Class DurationRoutePolicy

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.CamelContextAware, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.RoutePolicy, org.apache.camel.StatefulService, org.apache.camel.SuspendableService

    public class DurationRoutePolicy
    extends org.apache.camel.support.RoutePolicySupport
    implements org.apache.camel.CamelContextAware
    RoutePolicy which executes for a duration and then triggers an action.

    This can be used to stop the route after it has processed a number of messages, or has been running for N seconds.

    • Field Summary

      • Fields inherited from class org.apache.camel.support.service.BaseService

        BUILDED, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTINGDOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void doStop()  
      org.apache.camel.impl.engine.DurationRoutePolicy.Action getAction()  
      org.apache.camel.CamelContext getCamelContext()  
      int getMaxMessages()  
      int getMaxSeconds()  
      void onExchangeDone​(org.apache.camel.Route route, org.apache.camel.Exchange exchange)  
      void onInit​(org.apache.camel.Route route)  
      protected ScheduledFuture performMaxDurationAction()  
      protected void performMaxMessagesAction()  
      void setAction​(org.apache.camel.impl.engine.DurationRoutePolicy.Action action)
      What action to perform when maximum is triggered.
      void setCamelContext​(org.apache.camel.CamelContext camelContext)  
      void setMaxMessages​(int maxMessages)
      Maximum number of messages to process before the action is triggered
      void setMaxSeconds​(int maxSeconds)
      Maximum seconds Camel is running before the action is triggered
      • Methods inherited from class org.apache.camel.support.RoutePolicySupport

        controller, doStart, getExceptionHandler, handleException, onExchangeBegin, onRemove, onResume, onStart, onStop, onSuspend, resumeOrStartConsumer, resumeRoute, setExceptionHandler, startConsumer, startRoute, stopConsumer, stopRoute, stopRoute, stopRouteAsync, suspendOrStopConsumer, suspendRoute, suspendRoute
      • Methods inherited from class org.apache.camel.support.service.BaseService

        build, doBuild, doFail, doInit, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
      • Methods inherited from interface org.apache.camel.Service

        build, close, init, start, stop
      • Methods inherited from interface org.apache.camel.ShutdownableService

        shutdown
      • Methods inherited from interface org.apache.camel.StatefulService

        getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
      • Methods inherited from interface org.apache.camel.SuspendableService

        isSuspended, resume, suspend
    • Constructor Detail

      • DurationRoutePolicy

        public DurationRoutePolicy()
      • DurationRoutePolicy

        public DurationRoutePolicy​(org.apache.camel.CamelContext camelContext,
                                   String routeId)
    • Method Detail

      • getCamelContext

        public org.apache.camel.CamelContext getCamelContext()
        Specified by:
        getCamelContext in interface org.apache.camel.CamelContextAware
      • setCamelContext

        public void setCamelContext​(org.apache.camel.CamelContext camelContext)
        Specified by:
        setCamelContext in interface org.apache.camel.CamelContextAware
      • getMaxMessages

        public int getMaxMessages()
      • setMaxMessages

        public void setMaxMessages​(int maxMessages)
        Maximum number of messages to process before the action is triggered
      • getMaxSeconds

        public int getMaxSeconds()
      • setMaxSeconds

        public void setMaxSeconds​(int maxSeconds)
        Maximum seconds Camel is running before the action is triggered
      • getAction

        public org.apache.camel.impl.engine.DurationRoutePolicy.Action getAction()
      • setAction

        public void setAction​(org.apache.camel.impl.engine.DurationRoutePolicy.Action action)
        What action to perform when maximum is triggered.
      • onInit

        public void onInit​(org.apache.camel.Route route)
        Specified by:
        onInit in interface org.apache.camel.spi.RoutePolicy
        Overrides:
        onInit in class org.apache.camel.support.RoutePolicySupport
      • onExchangeDone

        public void onExchangeDone​(org.apache.camel.Route route,
                                   org.apache.camel.Exchange exchange)
        Specified by:
        onExchangeDone in interface org.apache.camel.spi.RoutePolicy
        Overrides:
        onExchangeDone in class org.apache.camel.support.RoutePolicySupport
      • doStop

        protected void doStop()
                       throws Exception
        Overrides:
        doStop in class org.apache.camel.support.RoutePolicySupport
        Throws:
        Exception
      • performMaxMessagesAction

        protected void performMaxMessagesAction()
      • performMaxDurationAction

        protected ScheduledFuture performMaxDurationAction()