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, ServiceWrapper
Implementation 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
MessageSplitter
implementation, executes the configuredService
and subsequently aggregates all the messages back using the configuredMessageAggregator
implementationA pool of
Service
instances 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 void
closeService()
void
doService(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 MessageAggregator
getAggregator()
TheMessageAggregator
implementation to use to join messages together.java.lang.Integer
getPoolsize()
The size of the underlying object/thread pool used to execute services.java.lang.Boolean
getSendEvents()
Whether or not to send events for the split message once service execution has completed.@NonNull Service
getService()
TheService
to execute over all the split messages.ServiceErrorHandler
getServiceErrorHandler()
The strategy to use when encountering any errors during execution.@NonNull MessageSplitter
getSplitter()
TheMessageSplitter
implementation to use to split the incoming message.TimeInterval
getTimeout()
The max amount of time to wait for all the operations to complete.protected void
initService()
void
prepare()
Prepare for initialisation.void
registerEventHandler(EventHandler eh)
Register the current event handler against this component.protected AdaptrisMessage
sendEvents(AdaptrisMessage msg)
void
setAggregator(@NonNull MessageAggregator aggregator)
TheMessageAggregator
implementation to use to join messages together.void
setPoolsize(java.lang.Integer poolsize)
The size of the underlying object/thread pool used to execute services.void
setSendEvents(java.lang.Boolean sendEvents)
Whether or not to send events for the split message once service execution has completed.void
setService(@NonNull Service service)
TheService
to execute over all the split messages.void
setServiceErrorHandler(ServiceErrorHandler serviceErrorHandler)
The strategy to use when encountering any errors during execution.void
setSplitter(@NonNull MessageSplitter splitter)
TheMessageSplitter
implementation to use to split the incoming message.void
setTimeout(TimeInterval timeout)
The max amount of time to wait for all the operations to complete.void
start()
Starts the component.void
stop()
Stop the componentprotected void
waitQuietly(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 CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Specified by:
prepare
in interfaceComponentLifecycleExtension
- Throws:
CoreException
-
initService
protected void initService() throws CoreException
- Specified by:
initService
in classServiceImp
- Throws:
CoreException
-
start
public void start() throws CoreException
Description copied from interface:ComponentLifecycle
Starts 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:
start
in interfaceComponentLifecycle
- Overrides:
start
in classServiceImp
- Throws:
CoreException
- wrapping any underlyingException
s
-
stop
public void stop()
Description copied from interface:ComponentLifecycle
Stop 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 aRuntimeException
may cause unintended consequences- Specified by:
stop
in interfaceComponentLifecycle
- Overrides:
stop
in classServiceImp
-
closeService
protected void closeService()
- Specified by:
closeService
in classServiceImp
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:Service
Apply the service to the message.
- Specified by:
doService
in interfaceService
- Parameters:
msg
- theAdaptrisMessage
to process- Throws:
ServiceException
- wrapping any underlyingException
s
-
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:EventHandlerAware
Register the current event handler against this component.- Specified by:
registerEventHandler
in interfaceEventHandlerAware
- Parameters:
eh
- the event handler currently in use.
-
wrappedServices
public Service[] wrappedServices()
Description copied from interface:ServiceWrapper
Return all the services that are wrapped by this service.- Specified by:
wrappedServices
in interfaceServiceWrapper
- Returns:
- an array of wrapped services.
-
sendEvents
protected AdaptrisMessage sendEvents(AdaptrisMessage msg) throws CoreException
- Throws:
CoreException
-
getService
@NonNull public @NonNull Service getService()
TheService
to execute over all the split messages.
-
setService
public void setService(@NonNull @NonNull Service service)
TheService
to execute over all the split messages.
-
getSplitter
@NonNull public @NonNull MessageSplitter getSplitter()
TheMessageSplitter
implementation to use to split the incoming message.
-
setSplitter
public void setSplitter(@NonNull @NonNull MessageSplitter splitter)
TheMessageSplitter
implementation to use to split the incoming message.
-
getAggregator
@NonNull public @NonNull MessageAggregator getAggregator()
TheMessageAggregator
implementation to use to join messages together.
-
setAggregator
public void setAggregator(@NonNull @NonNull MessageAggregator aggregator)
TheMessageAggregator
implementation 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_KEY
set 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_KEY
set 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
ServiceExceptionHandler
if not explicitly specified
-
setServiceErrorHandler
public void setServiceErrorHandler(ServiceErrorHandler serviceErrorHandler)
The strategy to use when encountering any errors during execution.Defaults to
ServiceExceptionHandler
if not explicitly specified
-
-