@ComponentProfile(summary="Runs the configured service/list repeatedly \'WHILE\' the configured condition is met.", tag="service,conditional,loop") public class While extends ServiceImp
This Service
allows you to test boolean (true or false) Condition
's, which if
evaluate to "true" will run a configured set of services continuously until the configured
conditions do not evaluate to true.
You can also set a value for the maximum amount of times your services will run regardless of
whether your conditions continue to evaluate to true.
The default value for the max-loops is 10. Setting this value to 0, will loop forever until your configured conditions evaluate to false.5
Typically your Condition
will test for equality, in-line expressions or whether values
exist or not. The values to test will generally come from the payload or message metadata.
Also note that some conditions can be nested, such that you can test that a value is equal to
another AND / OR a value is equal/not to another value.
In the adapter configuration file this class is aliased as while which is the preferred alternative to the fully qualified classname when building your configuration.
log
Constructor and Description |
---|
While() |
Modifier and Type | Method and Description |
---|---|
protected void |
closeService() |
protected boolean |
continueLooping(int loopCount,
AdaptrisMessage msg) |
void |
doService(AdaptrisMessage msg)
Apply the service to the message.
|
Condition |
getCondition() |
java.lang.Integer |
getMaxLoops() |
MaxLoopBehaviour |
getOnMaxLoops() |
ThenService |
getThen() |
protected void |
initService() |
protected MaxLoopBehaviour |
onMaxLoops() |
void |
prepare()
Prepare for initialisation.
|
void |
setCondition(Condition condition) |
void |
setMaxLoops(java.lang.Integer maxLoops)
Set the maximum number of loops.
|
void |
setOnMaxLoops(MaxLoopBehaviour onMaxLoops)
Set the behaviour desired when the max-loop condition is hit.
|
void |
setThen(ThenService ifTrueService) |
void |
start()
Starts the component.
|
void |
stop()
Stop the component
|
<T extends While> |
withCondition(Condition c) |
<T extends While> |
withMaxLoops(java.lang.Integer maxLoops) |
<T extends While> |
withOnMaxLoops(MaxLoopBehaviour c) |
<T extends While> |
withThen(ThenService t) |
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId
public void doService(AdaptrisMessage msg) throws ServiceException
Service
Apply the service to the message.
msg
- the AdaptrisMessage
to processServiceException
- wrapping any underlying Exception
spublic void prepare() throws CoreException
ComponentLifecycleExtension
CoreException
protected void initService() throws CoreException
initService
in class ServiceImp
CoreException
protected void closeService()
closeService
in class ServiceImp
public void start() throws CoreException
ComponentLifecycle
Once a component is started it should be ready to process messages. In the case of AdaptrisMessageConsumer
, calling start
will begin message delivery.
start
in interface ComponentLifecycle
start
in class ServiceImp
CoreException
- wrapping any underlying Exception
spublic void stop()
ComponentLifecycle
A stopped component is not expected to be ready to process messages. In the case of AdaptrisMessageConsumer
, calling stop
will pause message delivery. Throwing a RuntimeException
may cause unintended consequences
stop
in interface ComponentLifecycle
stop
in class ServiceImp
public Condition getCondition()
public void setCondition(Condition condition)
public ThenService getThen()
public void setThen(ThenService ifTrueService)
public java.lang.Integer getMaxLoops()
public void setMaxLoops(java.lang.Integer maxLoops)
Note that you can set the max-loops to be <0
to get infinite loops; in that situation
if your condition is never met, the service will loop indefinitely.
maxLoops
- the max loops; if not specified 10.public MaxLoopBehaviour getOnMaxLoops()
public void setOnMaxLoops(MaxLoopBehaviour onMaxLoops)
onMaxLoops
- the desired behaviour; the default which is to "continue" (effectively OnMaxNoOp
if not explicitly
configuredpublic <T extends While> T withMaxLoops(java.lang.Integer maxLoops)
public <T extends While> T withThen(ThenService t)
public <T extends While> T withOnMaxLoops(MaxLoopBehaviour c)
protected MaxLoopBehaviour onMaxLoops()
protected boolean continueLooping(int loopCount, AdaptrisMessage msg) throws java.lang.Exception
java.lang.Exception