Class PooledSplitJoinService
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.services.splitter.PooledSplitJoinService
-
- All Implemented Interfaces:
AdaptrisComponent,ComponentLifecycle,ComponentLifecycleExtension,EventHandlerAware,MessageEventGenerator,Service,ServiceWrapper,StateManagedComponent
@ComponentProfile(summary="Split a message and then execute the associated services on the split items, aggregating the split messages afterwards", since="3.11.1", tag="service,splitjoin") public class PooledSplitJoinService extends ServiceImp implements EventHandlerAware, ServiceWrapperImplementation of the Splitter and Aggregator enterprise integration pattern.This has more predictable peformance characteristics in constrained environments where the numbers of messages that are generated and aggregated can be large/unknown.
This service splits a message according to the configured
MessageSplitterimplementation, executes the configuredServiceand subsequently aggregates all the messages back using the configuredMessageAggregatorimplementationA pool of
Serviceinstances is maintained and re-used for each message; the cost of initialisation for the wrapped service, is incurred during this service's initialisation phase.Aggregation may start happening as soon as messages are available to be aggregated (i.e. a split message has been operated on) using the
MessageAggregator.aggregate(AdaptrisMessage, Iterable)method. Performance characteristics will largely depend on how the splitter and aggregator implementations iterate over the messages.In the adapter configuration file this class is aliased as pooled-split-join-service which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
Field Summary
-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description PooledSplitJoinService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseService()voiddoService(AdaptrisMessage msg)Apply the service to the message.protected java.lang.Iterable<AdaptrisMessage>doSplitService(java.lang.Iterable<AdaptrisMessage> msgs, com.adaptris.core.services.splitter.PooledSplitJoinService.CountingExceptionHandlerWrapper exceptionHandler)@NonNull MessageAggregatorgetAggregator()TheMessageAggregatorimplementation to use to join messages together.java.lang.IntegergetPoolsize()The size of the underlying object/thread pool used to execute services.java.lang.BooleangetSendEvents()Whether or not to send events for the split message once service execution has completed.@NonNull ServicegetService()TheServiceto execute over all the split messages.ServiceErrorHandlergetServiceErrorHandler()The strategy to use when encountering any errors during execution.@NonNull MessageSplittergetSplitter()TheMessageSplitterimplementation to use to split the incoming message.TimeIntervalgetTimeout()The max amount of time to wait for all the operations to complete.protected voidinitService()voidprepare()Prepare for initialisation.voidregisterEventHandler(EventHandler eh)Register the current event handler against this component.protected AdaptrisMessagesendEvents(AdaptrisMessage msg)voidsetAggregator(@NonNull MessageAggregator aggregator)TheMessageAggregatorimplementation to use to join messages together.voidsetPoolsize(java.lang.Integer poolsize)The size of the underlying object/thread pool used to execute services.voidsetSendEvents(java.lang.Boolean sendEvents)Whether or not to send events for the split message once service execution has completed.voidsetService(@NonNull Service service)TheServiceto execute over all the split messages.voidsetServiceErrorHandler(ServiceErrorHandler serviceErrorHandler)The strategy to use when encountering any errors during execution.voidsetSplitter(@NonNull MessageSplitter splitter)TheMessageSplitterimplementation to use to split the incoming message.voidsetTimeout(TimeInterval timeout)The max amount of time to wait for all the operations to complete.voidstart()Starts the component.voidstop()Stop the componentprotected voidwaitQuietly(java.lang.Object monitor, long timeoutMs)Service[]wrappedServices()Return all the services that are wrapped by this service.-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.adaptris.core.AdaptrisComponent
getUniqueId
-
Methods inherited from interface com.adaptris.core.ComponentLifecycle
close, init
-
Methods inherited from interface com.adaptris.core.MessageEventGenerator
createName, createQualifier, isTrackingEndpoint
-
Methods inherited from interface com.adaptris.core.Service
continueOnFailure, isBranching, setUniqueId
-
Methods inherited from interface com.adaptris.core.StateManagedComponent
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
-
-
-
-
Method Detail
-
prepare
public void prepare() throws CoreExceptionDescription copied from interface:ComponentLifecycleExtensionPrepare for initialisation.- Specified by:
preparein interfaceComponentLifecycleExtension- Throws:
CoreException
-
initService
protected void initService() throws CoreException- Specified by:
initServicein classServiceImp- Throws:
CoreException
-
start
public void start() throws CoreExceptionDescription copied from interface:ComponentLifecycleStarts the component.Once a component is started it should be ready to process messages. In the case of
AdaptrisMessageConsumer, calling start will begin message delivery.- Specified by:
startin interfaceComponentLifecycle- Overrides:
startin classServiceImp- Throws:
CoreException- wrapping any underlyingExceptions
-
stop
public void stop()
Description copied from interface:ComponentLifecycleStop the componentA stopped component is not expected to be ready to process messages. In the case of
AdaptrisMessageConsumer, calling stop will pause message delivery. Throwing aRuntimeExceptionmay cause unintended consequences- Specified by:
stopin interfaceComponentLifecycle- Overrides:
stopin classServiceImp
-
closeService
protected void closeService()
- Specified by:
closeServicein classServiceImp
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:ServiceApply the service to the message.
- Specified by:
doServicein interfaceService- Parameters:
msg- theAdaptrisMessageto process- Throws:
ServiceException- wrapping any underlyingExceptions
-
doSplitService
protected java.lang.Iterable<AdaptrisMessage> doSplitService(java.lang.Iterable<AdaptrisMessage> msgs, com.adaptris.core.services.splitter.PooledSplitJoinService.CountingExceptionHandlerWrapper exceptionHandler)
-
waitQuietly
protected void waitQuietly(java.lang.Object monitor, long timeoutMs)
-
registerEventHandler
public void registerEventHandler(EventHandler eh)
Description copied from interface:EventHandlerAwareRegister the current event handler against this component.- Specified by:
registerEventHandlerin interfaceEventHandlerAware- Parameters:
eh- the event handler currently in use.
-
wrappedServices
public Service[] wrappedServices()
Description copied from interface:ServiceWrapperReturn all the services that are wrapped by this service.- Specified by:
wrappedServicesin interfaceServiceWrapper- Returns:
- an array of wrapped services.
-
sendEvents
protected AdaptrisMessage sendEvents(AdaptrisMessage msg) throws CoreException
- Throws:
CoreException
-
getService
@NonNull public @NonNull Service getService()
TheServiceto execute over all the split messages.
-
setService
public void setService(@NonNull @NonNull Service service)TheServiceto execute over all the split messages.
-
getSplitter
@NonNull public @NonNull MessageSplitter getSplitter()
TheMessageSplitterimplementation to use to split the incoming message.
-
setSplitter
public void setSplitter(@NonNull @NonNull MessageSplitter splitter)TheMessageSplitterimplementation to use to split the incoming message.
-
getAggregator
@NonNull public @NonNull MessageAggregator getAggregator()
TheMessageAggregatorimplementation to use to join messages together.
-
setAggregator
public void setAggregator(@NonNull @NonNull MessageAggregator aggregator)TheMessageAggregatorimplementation to use to join messages together.
-
getTimeout
public TimeInterval getTimeout()
The max amount of time to wait for all the operations to complete.If not explicitly specified then is set to be 10 minutes; in the event that the timeout is exceeded, then an exception will be thrown eventually.
-
setTimeout
public void setTimeout(TimeInterval timeout)
The max amount of time to wait for all the operations to complete.If not explicitly specified then is set to be 10 minutes; in the event that the timeout is exceeded, then an exception will be thrown eventually.
-
getSendEvents
public java.lang.Boolean getSendEvents()
Whether or not to send events for the split message once service execution has completed.Note that even if this is set to true, because each child message has its own unique id, you will have to externally correlate the message lifecycle events together. Child messages will always have the metadata
CoreConstants.PARENT_UNIQUE_ID_KEYset with the originating message id.If not explicitly specified then is set to false which means no events are sent for 'split' messages.
-
setSendEvents
public void setSendEvents(java.lang.Boolean sendEvents)
Whether or not to send events for the split message once service execution has completed.Note that even if this is set to true, because each child message has its own unique id, you will have to externally correlate the message lifecycle events together. Child messages will always have the metadata
CoreConstants.PARENT_UNIQUE_ID_KEYset with the originating message id.If not explicitly specified then is set to false which means no events are sent for 'split' messages.
-
getPoolsize
public java.lang.Integer getPoolsize()
The size of the underlying object/thread pool used to execute services.The default value is '10' unless explicitly configured
-
setPoolsize
public void setPoolsize(java.lang.Integer poolsize)
The size of the underlying object/thread pool used to execute services.The default value is '10' unless explicitly configured
-
getServiceErrorHandler
public ServiceErrorHandler getServiceErrorHandler()
The strategy to use when encountering any errors during execution.Defaults to
ServiceExceptionHandlerif not explicitly specified
-
setServiceErrorHandler
public void setServiceErrorHandler(ServiceErrorHandler serviceErrorHandler)
The strategy to use when encountering any errors during execution.Defaults to
ServiceExceptionHandlerif not explicitly specified
-
-