Class While
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.services.conditional.While
-
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,MessageEventGenerator
,Service
,StateManagedComponent
- Direct Known Subclasses:
DoWhile
@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.
<max-loops>57</max-loops>
The default value for the max-loops is 10. Setting this value to 0, will loop forever until your configured conditions evaluate to false.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.
-
-
Field Summary
-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description While()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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>
TwithCondition(Condition c)
<T extends While>
TwithMaxLoops(java.lang.Integer maxLoops)
<T extends While>
TwithOnMaxLoops(MaxLoopBehaviour c)
<T extends While>
TwithThen(ThenService t)
-
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
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:Service
Apply the service to the message.
- Parameters:
msg
- theAdaptrisMessage
to process- Throws:
ServiceException
- wrapping any underlyingException
s
-
prepare
public void prepare() throws CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Throws:
CoreException
-
initService
protected void initService() throws CoreException
- Specified by:
initService
in classServiceImp
- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeService
in classServiceImp
-
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
-
getCondition
public Condition getCondition()
-
setCondition
public void setCondition(Condition condition)
-
getThen
public ThenService getThen()
-
setThen
public void setThen(ThenService ifTrueService)
-
getMaxLoops
public java.lang.Integer getMaxLoops()
-
setMaxLoops
public void setMaxLoops(java.lang.Integer maxLoops)
Set the maximum number of loops.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.- Parameters:
maxLoops
- the max loops; if not specified 10.
-
getOnMaxLoops
public MaxLoopBehaviour getOnMaxLoops()
-
setOnMaxLoops
public void setOnMaxLoops(MaxLoopBehaviour onMaxLoops)
Set the behaviour desired when the max-loop condition is hit.- Parameters:
onMaxLoops
- the desired behaviour; the default which is to "continue" (effectivelyOnMaxNoOp
if not explicitly configured
-
withMaxLoops
public <T extends While> T withMaxLoops(java.lang.Integer maxLoops)
-
withThen
public <T extends While> T withThen(ThenService t)
-
withOnMaxLoops
public <T extends While> T withOnMaxLoops(MaxLoopBehaviour c)
-
onMaxLoops
protected MaxLoopBehaviour onMaxLoops()
-
continueLooping
protected boolean continueLooping(int loopCount, AdaptrisMessage msg) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-