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
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 a
CloudProvider
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
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
static interface
static interface
static interface
static interface
static class
static class
-
Field Summary
Modifier and TypeFieldDescriptionstatic io.reactivex.rxjava3.core.Scheduler
static ExecutorService
-
Constructor Summary
ConstructorDescriptionSyncTask
(io.reactivex.rxjava3.core.Observable<Projection> domainRecords, Collection<ApiItem> apiItems) -
Method Summary
Modifier and TypeMethodDescriptionaddMatchFunction
(SyncTask.MatchFunction<Projection, ApiItem> matchFunction) io.reactivex.rxjava3.core.Observable<Boolean>
observe()
onAdd
(SyncTask.OnAddFunction<ApiItem> onAddFunction) onDelete
(SyncTask.OnDeleteFunction<Projection> deleteFunction) onError
(SyncTask.OnErrorfunction onErrorfunction) onUpdate
(SyncTask.OnUpdateFunction<SyncTask.UpdateItem<Model, ApiItem>> onUpdateFunction) void
setBufferSize
(Integer bufferSize) void
start()
void
withBufferSize
(Integer bufferSize) withLoadObjectDetails
(SyncTask.OnLoadObjectDetailsFunction<SyncTask.UpdateItemDto<Projection, ApiItem>, SyncTask.UpdateItem<Model, ApiItem>> onLoadObjectDetailsFunction) withLoadObjectDetailsFromFinder
(SyncTask.OnLoadObjectDetailsFromFinderFunction<SyncTask.UpdateItemDto<Projection, ApiItem>, Model> onLoadObjectDetailsFromFinderFunction)
-
Field Details
-
syncSchedulerThreads
-
syncScheduler
public static io.reactivex.rxjava3.core.Scheduler syncScheduler
-
-
Constructor Details
-
SyncTask
public SyncTask(io.reactivex.rxjava3.core.Observable<Projection> domainRecords, Collection<ApiItem> apiItems)
-
-
Method Details
-
addMatchFunction
public SyncTask<Projection,ApiItem, addMatchFunctionModel> (SyncTask.MatchFunction<Projection, ApiItem> matchFunction) -
onDelete
public SyncTask<Projection,ApiItem, onDeleteModel> (SyncTask.OnDeleteFunction<Projection> deleteFunction) -
onAdd
-
onUpdate
public SyncTask<Projection,ApiItem, onUpdateModel> (SyncTask.OnUpdateFunction<SyncTask.UpdateItem<Model, ApiItem>> onUpdateFunction) -
withLoadObjectDetails
public SyncTask<Projection,ApiItem, withLoadObjectDetailsModel> (SyncTask.OnLoadObjectDetailsFunction<SyncTask.UpdateItemDto<Projection, ApiItem>, SyncTask.UpdateItem<Model, ApiItem>> onLoadObjectDetailsFunction) -
withLoadObjectDetailsFromFinder
public SyncTask<Projection,ApiItem, withLoadObjectDetailsFromFinderModel> (SyncTask.OnLoadObjectDetailsFromFinderFunction<SyncTask.UpdateItemDto<Projection, ApiItem>, Model> onLoadObjectDetailsFromFinderFunction) -
onError
-
setBufferSize
-
withBufferSize
-
startAsync
public void startAsync() -
start
public void start() -
observe
-