Package com.morpheusdata.core.util
Class SyncTask<Projection,ApiItem,Model>
- java.lang.Object
-
- com.morpheusdata.core.util.SyncTask<Projection,ApiItem,Model>
-
- Type Parameters:
Projection
- The Projection Class Object used for matching the api object to the database object. Typically this Projection Object has fewer properties likeid
,externalId
, orname
ApiItem
- The Class Object representing the individual API result object coming back in the CollectionModel
- The Model Class that the Projection Class is a subset of. This is the Class that needs to be updated with changes
public class SyncTask<Projection,ApiItem,Model> extends java.lang.Object
This Utility Class provides an rxJava compatible means for syncing remote API objects with local/morpheus backed models in a persistent database. This handles an efficeint way to match data projection objects with api objects and batches updates to the backend database for efficient sync. This should be considered the standard method for caching objects within aCloudProvider
and many other provider types.Example:
Observable<NetworkDomainSyncProjection> domainRecords = morpheusContext.network.listNetworkDomainSyncMatch(poolServer.integration.id) SyncTask<NetworkDomainSyncProjection,Map,NetworkDomain> syncTask = new SyncTask(domainRecords, apiItems as Collection<Map>) syncTask.addMatchFunction { NetworkDomainSyncProjection domainObject, Map apiItem -> domainObject.externalId == apiItem.'_ref' }.addMatchFunction { NetworkDomainSyncProjection domainObject, Map apiItem -> domainObject.name == apiItem.name }.onDelete {removeItems -> morpheusContext.network.removeMissingZones(poolServer.integration.id, removeItems) }.onAdd { itemsToAdd -> addMissingZones(poolServer, itemsToAdd) }.withLoadObjectDetails { List<SyncTask.UpdateItemDto<NetworkDomainSyncProjection,Map>> updateItems -> return morpheusContext.network.listNetworkDomainsById(updateItems.collect{it.existingItem.id} as Collection<Long>) }.onUpdate { List<SyncTask.UpdateItem<NetworkDomain,Map>> updateItems -> updateMatchedZones(poolServer, updateItems) }.start()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SyncTask.MatchFunction<Projection,ApiItem>
static interface
SyncTask.OnAddFunction<ApiItem>
static interface
SyncTask.OnDeleteFunction<Projection>
static interface
SyncTask.OnErrorfunction
static interface
SyncTask.OnLoadObjectDetailsFunction<UpdateItemProjection,UpdateItem>
static interface
SyncTask.OnUpdateFunction<UpdateItems>
static class
SyncTask.UpdateItem<Model,ApiItem>
static class
SyncTask.UpdateItemDto<Projection,ApiItem>
-
Constructor Summary
Constructors Constructor Description SyncTask(io.reactivex.Observable<Projection> domainRecords, java.util.Collection<ApiItem> apiItems)
-
Method Summary
-
-
-
Constructor Detail
-
SyncTask
public SyncTask(io.reactivex.Observable<Projection> domainRecords, java.util.Collection<ApiItem> apiItems)
-
-
Method Detail
-
addMatchFunction
public SyncTask<Projection,ApiItem,Model> addMatchFunction(SyncTask.MatchFunction<Projection,ApiItem> matchFunction)
-
onDelete
public SyncTask<Projection,ApiItem,Model> onDelete(SyncTask.OnDeleteFunction<Projection> deleteFunction)
-
onAdd
public SyncTask<Projection,ApiItem,Model> onAdd(SyncTask.OnAddFunction<ApiItem> onAddFunction)
-
onUpdate
public SyncTask<Projection,ApiItem,Model> onUpdate(SyncTask.OnUpdateFunction<SyncTask.UpdateItem<Model,ApiItem>> onUpdateFunction)
-
withLoadObjectDetails
public SyncTask<Projection,ApiItem,Model> withLoadObjectDetails(SyncTask.OnLoadObjectDetailsFunction<SyncTask.UpdateItemDto<Projection,ApiItem>,SyncTask.UpdateItem<Model,ApiItem>> onLoadObjectDetailsFunction)
-
onError
public SyncTask<Projection,ApiItem,Model> onError(SyncTask.OnErrorfunction onErrorfunction)
-
setBufferSize
public void setBufferSize(java.lang.Integer bufferSize)
-
withBufferSize
public SyncTask<Projection,ApiItem,Model> withBufferSize(java.lang.Integer bufferSize)
-
startAsync
public void startAsync()
-
start
public void start()
-
observe
public io.reactivex.Observable<java.lang.Boolean> observe()
-
-