Class AbstractDataExchangeService<T extends ExchangeObject>
java.lang.Object
com.broadleafcommerce.dataexchange.service.AbstractDataExchangeService<T>
- Type Parameters:
 T-
- All Implemented Interfaces:
 DataExchangeService<T>
- Direct Known Subclasses:
 DefaultComprehensiveProductExchangeService
public abstract class AbstractDataExchangeService<T extends ExchangeObject>
extends Object
implements DataExchangeService<T>
Abstract base implementation for handling the orchestration of the requisite calls to multiple
 services and/or service API endpoints.
- Author:
 - Kelly Tisdell (ktisdell)
 
- 
Constructor Summary
ConstructorsConstructorDescriptionAbstractDataExchangeService(org.springframework.core.task.AsyncTaskExecutor executor, org.springframework.retry.support.RetryTemplate retryTemplate, com.broadleafcommerce.common.extension.TypeFactory typeFactory, DataExchangeProperties properties, List<BatchExtensionProcessor> batchExtensionProcessors, BatchItemErrorHandler errorResolver)  - 
Method Summary
Modifier and TypeMethodDescriptionprotected voidaggregate(BatchContext<T> batchContext) This process takes all the entities that have been saved, aggregates or augments them, and returns them.protected CompletableFuture<Void>createCompletableFuture(Runnable runnable) Returns aCompletableFuturethat will execute the providedRunnablein another thread provided bygetExecutor()when a terminating method is invoked.protected <R> CompletableFuture<R>createCompletableFuture(Supplier<R> supplier) Returns aCompletableFuturethat will execute the providedSupplierin another thread provided bygetExecutor()when a terminating method is invoked.protected StringexceedMaxBatchSizeError(@NotNull List<T> entities) protected org.springframework.retry.support.RetryTemplateprotected BatchItemErrorHandlerprotected org.springframework.core.task.AsyncTaskExecutorprotected DataExchangePropertiesprotected com.broadleafcommerce.common.extension.TypeFactoryprotected <C extends ExchangeObject>
RunnableretryableRunnable(C payload, BatchContext<T> batchContext, Callable<Void> supplier) protected <R,C extends ExchangeObject> 
Supplier<R>retryableSupplier(C payload, BatchContext<T> batchContext, Callable<R> supplier) protected <R,C extends ExchangeObject> 
Supplier<List<R>>retryableSupplier(List<C> payload, BatchContext<T> batchContext, Callable<List<R>> supplier) final BatchContext<T>saveAll(@NonNull List<T> entities, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) This method takes the list of entities to be saved, splits them into their individual pieces that have to be saved separately.protected abstract voidsaveAll(BatchContext<T> batchContext) This is the entry point for subclasses to inject logic to handle the structure that has been passed in.protected voidsplit(List<T> entities, BatchContext<T> batchContext) This method "flattens" the object graph into aMapofexchange objects. 
- 
Constructor Details
- 
AbstractDataExchangeService
public AbstractDataExchangeService(org.springframework.core.task.AsyncTaskExecutor executor, org.springframework.retry.support.RetryTemplate retryTemplate, com.broadleafcommerce.common.extension.TypeFactory typeFactory, DataExchangeProperties properties, List<BatchExtensionProcessor> batchExtensionProcessors, BatchItemErrorHandler errorResolver)  
 - 
 - 
Method Details
- 
saveAll
public final BatchContext<T> saveAll(@NonNull @NonNull List<T> entities, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) This method takes the list of entities to be saved, splits them into their individual pieces that have to be saved separately. It then processes the primary or containing entity synchronously first, and then processes child, or secondary, entities asynchronously for better performance. Each additional network call (to additional API endpoints or services) is added overhead, which is why this process attempts to parallelize parts of it.- Specified by:
 saveAllin interfaceDataExchangeService<T extends ExchangeObject>- Parameters:
 entities- the entities to be saved- Returns:
 - the 
BatchContextwhich should contain all state for the batch, including all results and errors 
 - 
exceedMaxBatchSizeError
 - 
split
This method "flattens" the object graph into aMapofexchange objects. Each key in the map is a correlationId for theExchangeObject. EachExchangeObjectwill be populated with the parent's correlationId:ExchangeObject.getParentCorrelationId(), or null if there is no parent. With this data, items can be collected, processed separately, and reconstructed - or aggregated - at the end of the process.- Parameters:
 entities- to be split into multiple constituents, presumably to be saved by different API callsbatchContext- the batch context
 - 
saveAll
This is the entry point for subclasses to inject logic to handle the structure that has been passed in. This may be called in a differentThreadthan the calling thread. Typically, the containing object needs to be processed first to ensure that the correct references (e.g. contextIds, pricing keys, etc. are available). It is expected that the values in the Map will be updated when they are created or saved, allowing the aggregate method to aggregate the details.- Parameters:
 batchContext- the batch context- See Also:
 
 - 
aggregate
This process takes all the entities that have been saved, aggregates or augments them, and returns them. They are all, presumably, saved and can be re-associated with their correlationIds, and their parentCorrelationsIds. The entities may already be composed, but this allows implementors to define errors as well.- Parameters:
 batchContext- the batch context- See Also:
 
 - 
createCompletableFuture
Returns aCompletableFuturethat will execute the providedSupplierin another thread provided bygetExecutor()when a terminating method is invoked. Implementors of theSupplierinterface or lambda should make every effort to avoid throwing exceptions from the supplier so that we can gather exceptions as needed. Consider passing aRetryableto this method, which implementsCallableand which will not, by default, throw an exception.- Parameters:
 supplier- aSupplierimplementation that will be executed in another thread- Returns:
 - a 
CompletableFuturethat will manage the execution of the providedSupplierinterface 
 - 
createCompletableFuture
Returns aCompletableFuturethat will execute the providedRunnablein another thread provided bygetExecutor()when a terminating method is invoked. Implementors of theRunnableinterface or lambda should make every effort to avoid throwing exceptions from the supplier so that we can gather exceptions as needed. Consider passing aRetryableto this method, which implementsRunnableand which will not, by default, throw an exception.- Parameters:
 runnable- aRunnableimplementation that will be executed in another thread- Returns:
 - a 
CompletableFuturethat will manage the execution of the providedSupplierinterface 
 - 
retryableSupplier
protected <R,C extends ExchangeObject> Supplier<R> retryableSupplier(C payload, BatchContext<T> batchContext, Callable<R> supplier)  - 
retryableSupplier
protected <R,C extends ExchangeObject> Supplier<List<R>> retryableSupplier(List<C> payload, BatchContext<T> batchContext, Callable<List<R>> supplier)  - 
retryableRunnable
protected <C extends ExchangeObject> Runnable retryableRunnable(C payload, BatchContext<T> batchContext, Callable<Void> supplier)  - 
getExecutor
protected org.springframework.core.task.AsyncTaskExecutor getExecutor() - 
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() - 
getDefaultRetryTemplate
protected org.springframework.retry.support.RetryTemplate getDefaultRetryTemplate() - 
getProperties
 - 
getErrorResolver
 
 -