@ComponentProfile(summary="Throttles message flow based on some message count criteria", tag="interceptor,jmx") public class ThrottlingInterceptor extends WorkflowInterceptorImpl
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;Integer.MAX_VALUE
TimeSliceDefaultCacheProvider
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.
WorkflowInterceptorImpl.WorkflowInterceptorException
Constructor and Description |
---|
ThrottlingInterceptor() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the component.
|
java.lang.String |
getCacheName() |
TimeSliceCacheProvider |
getCacheProvider() |
int |
getMaximumMessages() |
TimeInterval |
getTimeSliceInterval() |
void |
init()
Initialises the component.
|
void |
setCacheName(java.lang.String cacheName)
Set the cache name for shared throttles.
|
void |
setCacheProvider(TimeSliceCacheProvider cacheProvider)
Set the caching provider for timeslices.
|
void |
setMaximumMessages(int maximumMessages)
Set the maximum number of messages that can be processed in each timeslice.
|
void |
setTimeSliceInterval(TimeInterval interval)
Set the interval for each timeslice.
|
void |
start()
Starts the component.
|
void |
stop()
Stop the component
|
void |
workflowEnd(AdaptrisMessage inputMsg,
AdaptrisMessage outputMsg)
Mark the end of a workflow.
|
void |
workflowStart(AdaptrisMessage inputMsg)
Mark the start of a workflow.
|
changeState, getUniqueId, parentChannel, parentWorkflow, prepare, registerParentChannel, registerParentWorkflow, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setUniqueId, wasSuccessful
public void init() throws CoreException
ComponentLifecycle
Component initialisation includes config verification, creation of connections etc.
CoreException
- wrapping any underlying Exception
spublic void start() throws CoreException
ComponentLifecycle
Once a component is started it should be ready to process messages. In the case of
AdaptrisMessageConsumer
, calling start will begin message delivery.
CoreException
- wrapping any underlying Exception
spublic void stop()
ComponentLifecycle
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
public void close()
ComponentLifecycle
A closed component should release any connections it uses, etc. and clean up completely.
Throwing a RuntimeException
may cause unintended consequences
public void workflowStart(AdaptrisMessage inputMsg)
WorkflowInterceptor
inputMsg
- the message that will be processed by this workflow.public void workflowEnd(AdaptrisMessage inputMsg, AdaptrisMessage outputMsg)
WorkflowInterceptor
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 inputMsgoutputMsg
- the message contaning any changes that may have been applied by the services within the workflow.CoreConstants.OBJ_METADATA_EXCEPTION
public int getMaximumMessages()
public void setMaximumMessages(int maximumMessages)
maximumMessages
- the max number of messages, default is 2147483647public TimeSliceCacheProvider getCacheProvider()
public void setCacheProvider(TimeSliceCacheProvider cacheProvider)
cacheProvider
- the caching provider.public java.lang.String getCacheName()
public void setCacheName(java.lang.String cacheName)
cacheName
- the cache name.public void setTimeSliceInterval(TimeInterval interval)
interval
- public TimeInterval getTimeSliceInterval()