Class ForEach
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.services.conditional.ForEach
-
- All Implemented Interfaces:
AdaptrisComponent,ComponentLifecycle,ComponentLifecycleExtension,MessageEventGenerator,Service,StateManagedComponent
@ComponentProfile(summary="Runs the configured service/list for each multi-payload message payload.", tag="for,each,for each,for-each,then,multi-payload", since="3.10.0") public class ForEach extends ServiceImpA for-each implementation that iterates over the payloads in a multi-payload messageMultiPayloadAdaptrisMessage. For each payload then execute the given service (list). The default is to use a single thread to iterate over the payloads, but a thread pool can be used to parallelize the loop.<for-each-payload> <unique-id>for-each-id</unique-id> <then> <service class="shared-service"> <lookup-name>for-each-service-list-id</lookup-name> <unique-id>for-each-service-list-id</unique-id> </service> </then> <thread-count>1</thread-count> </for-each-payload>Note: If your service list for each payload contains a
StopProcessingServiceit will not stop the processing of each payload.- Since:
- 3.10
- See Also:
MultiPayloadAdaptrisMessage
In the adapter configuration file this class is aliased as for-each-payload which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
Constructor Summary
Constructors Constructor Description ForEach()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseService()voiddoService(AdaptrisMessage msg)Apply the service to the message.ThenServicegetThen()Get the for-each-then service.java.lang.IntegergetThreadCount()Get the number of threads to use.protected voidinitService()voidprepare()Prepare for initialisation.voidsetThen(ThenService thenService)Set the for-each-then service.voidsetThreadCount(java.lang.Integer threadCount)Set the number of threads to use.voidstart()Starts the component.voidstop()Stop the component-
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
-
-
-
-
Method Detail
-
getThen
public ThenService getThen()
Get the for-each-then service.- Returns:
- The service.
-
setThen
public void setThen(ThenService thenService)
Set the for-each-then service.- Parameters:
thenService- The service.
-
getThreadCount
public java.lang.Integer getThreadCount()
Get the number of threads to use.- Returns:
- The number of threads.
-
setThreadCount
public void setThreadCount(java.lang.Integer threadCount)
Set the number of threads to use. If set to 0 then as many threads as there are payloads will be used.- Parameters:
threadCount- The number of threads.
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Apply the service to the message.
.- Parameters:
msg- theAdaptrisMessageto process- Throws:
ServiceException- wrapping any underlyingExceptions
-
initService
protected void initService() throws CoreException- Specified by:
initServicein classServiceImp- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeServicein classServiceImp
-
prepare
public void prepare() throws CoreExceptionPrepare for initialisation.- Throws:
CoreException
-
start
public void start() throws CoreExceptionStarts 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()
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 aRuntimeExceptionmay cause unintended consequences- Specified by:
stopin interfaceComponentLifecycle- Overrides:
stopin classServiceImp
-
-