Class 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.

    • Constructor Detail

      • While

        public While()
    • Method Detail

      • doService

        public void doService​(AdaptrisMessage msg)
                       throws ServiceException
        Description copied from interface: Service

        Apply the service to the message.

        Parameters:
        msg - the AdaptrisMessage to process
        Throws:
        ServiceException - wrapping any underlying Exceptions
      • stop

        public void stop()
        Description copied from interface: ComponentLifecycle
        Stop the component

        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

        Specified by:
        stop in interface ComponentLifecycle
        Overrides:
        stop in class ServiceImp
      • getCondition

        public Condition getCondition()
      • setCondition

        public void setCondition​(Condition condition)
      • 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.
      • 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" (effectively OnMaxNoOp if not explicitly configured
      • withMaxLoops

        public <T extends While> T withMaxLoops​(java.lang.Integer maxLoops)
      • withCondition

        public <T extends While> T withCondition​(Condition c)
      • continueLooping

        protected boolean continueLooping​(int loopCount,
                                          AdaptrisMessage msg)
                                   throws java.lang.Exception
        Throws:
        java.lang.Exception