Package com.commercetools.sync.commons
Class BaseSync<T,U extends BaseSyncStatistics,V extends BaseSyncOptions>
- java.lang.Object
-
- com.commercetools.sync.commons.BaseSync<T,U,V>
-
- Direct Known Subclasses:
CartDiscountSync
,CategorySync
,CustomerSync
,CustomObjectSync
,InventorySync
,ProductSync
,ProductTypeSync
,ShoppingListSync
,StateSync
,TaxCategorySync
,TypeSync
public abstract class BaseSync<T,U extends BaseSyncStatistics,V extends BaseSyncOptions> extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected U
statistics
protected V
syncOptions
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static <S> S
executeSupplierIfConcurrentModificationException(java.lang.Throwable sphereException, java.util.function.Supplier<S> onConcurrentModificationSupplier, java.util.function.Supplier<S> onOtherExceptionSupplier)
This method checks if the suppliedsphereException
is an instance ofConcurrentModificationException
.U
getStatistics()
Returns an instance of type U which is a subclass ofBaseSyncStatistics
containing all the stats of the sync process; which includes a report message, the total number of update, created, failed, processed resources and the processing time of the sync in different time units and in a human readable format.V
getSyncOptions()
protected abstract java.util.concurrent.CompletionStage<U>
process(java.util.List<T> resourceDrafts)
Given a list of resource (e.g.protected abstract java.util.concurrent.CompletionStage<U>
processBatch(java.util.List<T> batch)
java.util.concurrent.CompletionStage<U>
sync(java.util.List<T> resourceDrafts)
Given a list of resource (e.g.protected java.util.concurrent.CompletionStage<U>
syncBatches(java.util.List<java.util.List<T>> batches, java.util.concurrent.CompletionStage<U> result)
Given a list of resource (e.g.
-
-
-
Field Detail
-
statistics
protected final U extends BaseSyncStatistics statistics
-
syncOptions
protected final V extends BaseSyncOptions syncOptions
-
-
Method Detail
-
process
protected abstract java.util.concurrent.CompletionStage<U> process(@Nonnull java.util.List<T> resourceDrafts)
Given a list of resource (e.g. categories, products, etc..) drafts. This method compares each new resource in this list with it's corresponding old resource in a given CTP project, and in turn it either issues update actions on the existing resource if it exists or create it if it doesn't.- Parameters:
resourceDrafts
- the list of new resources as drafts.- Returns:
- an instance of
CompletionStage
<U
> which contains as a result an instance ofU
which is a subclass ofBaseSyncStatistics
representing thestatistics
instance attribute ofthis
BaseSync
.
-
sync
public java.util.concurrent.CompletionStage<U> sync(@Nonnull java.util.List<T> resourceDrafts)
Given a list of resource (e.g. categories, products, etc..) drafts. This method compares each new resource in this list with it's corresponding old resource in a given CTP project, and in turn it either issues update actions on the existing resource if it exists or create it if it doesn't.The time before and after the actual sync process starts is recorded in the
BaseSyncStatistics
container so that the total processing time is computed in the statistics.- Parameters:
resourceDrafts
- the list of new resources as drafts.- Returns:
- an instance of
CompletionStage
<U
> which contains as a result an instance ofU
which is a subclass ofBaseSyncStatistics
representing thestatistics
instance attribute ofthis
BaseSync
.
-
getStatistics
@Nonnull public U getStatistics()
Returns an instance of type U which is a subclass ofBaseSyncStatistics
containing all the stats of the sync process; which includes a report message, the total number of update, created, failed, processed resources and the processing time of the sync in different time units and in a human readable format.- Returns:
- a statistics object for the sync process.
-
getSyncOptions
public V getSyncOptions()
-
syncBatches
protected java.util.concurrent.CompletionStage<U> syncBatches(@Nonnull java.util.List<java.util.List<T>> batches, @Nonnull java.util.concurrent.CompletionStage<U> result)
Given a list of resource (e.g. categories, products, etc.. batches represented by aList
<List
> of resources, this method recursively callsprocessBatch(List)
on each batch, then removes it, until there are no more batches, in other words, all batches have been synced.- Parameters:
batches
- the batches of resources to sync.result
- in the first call of this recursive method, this result is normally a completed future, it used from within the method to recursively sync each batch once the previous batch has finished syncing.- Returns:
- an instance of
CompletionStage
<U
> which contains as a result an instance ofBaseSyncStatistics
representing thestatistics
of the sync process executed on the given list of batches.
-
processBatch
protected abstract java.util.concurrent.CompletionStage<U> processBatch(@Nonnull java.util.List<T> batch)
-
executeSupplierIfConcurrentModificationException
protected static <S> S executeSupplierIfConcurrentModificationException(@Nonnull java.lang.Throwable sphereException, @Nonnull java.util.function.Supplier<S> onConcurrentModificationSupplier, @Nonnull java.util.function.Supplier<S> onOtherExceptionSupplier)
This method checks if the suppliedsphereException
is an instance ofConcurrentModificationException
. If it is, then it executes the suppliedonConcurrentModificationSupplier
Supplier
. Otherwise, if it is not an instance of aConcurrentModificationException
then it executes the otheronOtherExceptionSupplier
Supplier
. Regardless, which supplier is executed the results of either is the result of this method.- Type Parameters:
S
- the type of the result of the suppliers and this method.- Parameters:
sphereException
- the sphere exception to check if isConcurrentModificationException
.onConcurrentModificationSupplier
- the supplier to execute if thesphereException
is aConcurrentModificationException
.onOtherExceptionSupplier
- the supplier to execute if thesphereException
is not aConcurrentModificationException
.- Returns:
- the result of the executed supplier.
-
-