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 ServiceImp
A 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
StopProcessingService
it 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 void
closeService()
void
doService(AdaptrisMessage msg)
Apply the service to the message.ThenService
getThen()
Get the for-each-then service.java.lang.Integer
getThreadCount()
Get the number of threads to use.protected void
initService()
void
prepare()
Prepare for initialisation.void
setThen(ThenService thenService)
Set the for-each-then service.void
setThreadCount(java.lang.Integer threadCount)
Set the number of threads to use.void
start()
Starts the component.void
stop()
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
- theAdaptrisMessage
to process- Throws:
ServiceException
- wrapping any underlyingException
s
-
initService
protected void initService() throws CoreException
- Specified by:
initService
in classServiceImp
- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeService
in classServiceImp
-
prepare
public void prepare() throws CoreException
Prepare for initialisation.- Throws:
CoreException
-
start
public void start() throws CoreException
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()
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
-
-