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 ServiceImpThis
Serviceallows 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
Conditionwill 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 voidcloseService()protected booleancontinueLooping(int loopCount, AdaptrisMessage msg)voiddoService(AdaptrisMessage msg)Apply the service to the message.ConditiongetCondition()java.lang.IntegergetMaxLoops()MaxLoopBehaviourgetOnMaxLoops()ThenServicegetThen()protected voidinitService()protected MaxLoopBehaviouronMaxLoops()voidprepare()Prepare for initialisation.voidsetCondition(Condition condition)voidsetMaxLoops(java.lang.Integer maxLoops)Set the maximum number of loops.voidsetOnMaxLoops(MaxLoopBehaviour onMaxLoops)Set the behaviour desired when the max-loop condition is hit.voidsetThen(ThenService ifTrueService)voidstart()Starts the component.voidstop()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:ServiceApply the service to the message.
- Parameters:
msg- theAdaptrisMessageto process- Throws:
ServiceException- wrapping any underlyingExceptions
-
prepare
public void prepare() throws CoreExceptionDescription copied from interface:ComponentLifecycleExtensionPrepare for initialisation.- Throws:
CoreException
-
initService
protected void initService() throws CoreException- Specified by:
initServicein classServiceImp- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeServicein classServiceImp
-
start
public void start() throws CoreExceptionDescription copied from interface:ComponentLifecycleStarts 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()
Description copied from interface:ComponentLifecycleStop 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
-
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
<0to 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" (effectivelyOnMaxNoOpif 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
-
-