Class ThrottlingInterceptor

  • All Implemented Interfaces:
    AdaptrisComponent, ComponentLifecycle, ComponentLifecycleExtension, StateManagedComponent, WorkflowInterceptor

    @ComponentProfile(summary="Throttles message flow based on some message count criteria",
                      tag="interceptor,jmx")
    public class ThrottlingInterceptor
    extends WorkflowInterceptorImpl
    The throttling interceptor will attempt to limit the number of messages that are processed by an adapter over a given time slot.

    A time slice is measured through the setTimeSliceInterval(TimeInterval). Once the first message is processed by this interceptor, a time slice is created. The start of the time slice is the current time, the end of the time slice is set as the current time + the number of time units in the configuration. Every message processed by the interceptor will start a check to see if the current time slice is out of date. If it is out of date, then a new time slice is created. If the current time slice is not out of date, then we check to make sure the maximum messages have not already passed through. If we have not yet reached the maximum messages for the current time slice, we simply increment the message count on the time slice. If we have reached the maximum messages, then we will delay this processing thread until the current time slice is finished, and finally a new time slice is created.

    Any given instance of the ThrottlingInterceptor can be set to work with a particular cache name. This allows you to configure a throttling interceptor on one or more workflows to all use the same time slice or use a completely different time slice.

    For example, you can set workflow A and workflow B to both have a throttling interceptor, where both interceptors use the same cache name. This will have the effect of restricting the sum of messages passing through both workflows against the same time slice statistics.

    Likewise, you may have a third workflow with an interceptor configured to use a different cache name. This means messages passing through the third workflow will not have the same throttling restrictions as those on workflow A and B.

    The following properties may be set in configuration;
    • time-slice-interval - This is the number of time units each time slice will use. The default value is 5.
    • maximum-messages - The maximum amount of messages allowed to pass through the current time slice The default value is Integer.MAX_VALUE
    • cache-provider - The implementation that handles the time slice memory management. The default is TimeSliceDefaultCacheProvider
    • cache-name - This allows you to set the cache name that the time slice statistics will be created/used from;this must be specified

    In the adapter configuration file this class is aliased as throttling-interceptor which is the preferred alternative to the fully qualified classname when building your configuration.

    • Constructor Detail

      • ThrottlingInterceptor

        public ThrottlingInterceptor()
    • Method Detail

      • init

        public void init()
                  throws CoreException
        Description copied from interface: ComponentLifecycle
        Initialises the component.

        Component initialisation includes config verification, creation of connections etc.

        Throws:
        CoreException - wrapping any underlying Exceptions
      • 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.

        Throws:
        CoreException - 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

      • close

        public void close()
        Description copied from interface: ComponentLifecycle
        Closes the component.

        A closed component should release any connections it uses, etc. and clean up completely. Throwing a RuntimeException may cause unintended consequences

      • workflowStart

        public void workflowStart​(AdaptrisMessage inputMsg)
        Description copied from interface: WorkflowInterceptor
        Mark the start of a workflow. This doesn't mean the message has started processing but only that the message will - at some point - be processed by the workflow.
        Parameters:
        inputMsg - the message that will be processed by this workflow.
      • workflowEnd

        public void workflowEnd​(AdaptrisMessage inputMsg,
                                AdaptrisMessage outputMsg)
        Description copied from interface: WorkflowInterceptor
        Mark the end of a workflow.
        Parameters:
        inputMsg - the original message that was originally submitted to the workflow; in the event of an exception during processing, the exception will be stored in object metadata in the inputMsg
        outputMsg - the message contaning any changes that may have been applied by the services within the workflow.
        See Also:
        CoreConstants.OBJ_METADATA_EXCEPTION
      • getMaximumMessages

        public int getMaximumMessages()
      • setMaximumMessages

        public void setMaximumMessages​(int maximumMessages)
        Set the maximum number of messages that can be processed in each timeslice.
        Parameters:
        maximumMessages - the max number of messages, default is 2147483647
      • setCacheProvider

        public void setCacheProvider​(TimeSliceCacheProvider cacheProvider)
        Set the caching provider for timeslices.
        Parameters:
        cacheProvider - the caching provider.
      • getCacheName

        public java.lang.String getCacheName()
      • setCacheName

        public void setCacheName​(java.lang.String cacheName)
        Set the cache name for shared throttles.
        Parameters:
        cacheName - the cache name.
      • setTimeSliceInterval

        public void setTimeSliceInterval​(TimeInterval interval)
        Set the interval for each timeslice.
        Parameters:
        interval -
      • getTimeSliceInterval

        public TimeInterval getTimeSliceInterval()