@ComponentProfile(summary="Interceptor that issues a JMX notification based on a message count boundary", tag="interceptor,jmx") public class MessageCountNotification extends NotifyingInterceptorByCount
Notification
under based on message count being higher or lower
than the given message count.
A Notification will be emitted when the message count threshold is first exceeded in the last
complete timeslice. Notifications will continue being emitted for as long as the message count is
greater than the threshold and getMaxNotifications()
has not been exceeded. When the
message count dips below the threshold a notification is emitted with a different
Notification.getMessage()
.
The Notification.setUserData(Object)
part of the notification is a Properties
object containing information about the slice which was the source of the notification.
Notifications are only generated based on the last complete timeslice that was recorded when a
message enters the workflow. Note that a workflow which does not process any messages within a
given timeslice will never rollover the current timeslice so this means that notifications are
not generated until the current timeslice rolls over or a message is next processed by the
workflow. Any delay in notifications will be based on the spikiness of the traffic and the
granularity of your timeslice.
Additionally, this interceptor will notify a consecutive maximum of
getMaxNotifications()
(if not specified, then notifications continue forever) whenever a
boundary is breached. For instance, if you have getMaxNotifications()
set to 5, then a
maximum of 5 notifications will be emitted for an upper boundary breach provided no lower
boundary breaches happen in-between. If the configuration is
max-notifications=3, message-count=10
then our notifications happen like this:
|--Timeslice--|--MsgCount--|--Upper Boundary Notification--|--Lower Boundary Notification--|
| 01 | 11 | No (no previous timeslice) | No |
| 02 | 12 | Yes (count = 11) | No |
| 03 | 13 | Yes (count = 12) | No |
| 04 | 00 | No | No |
| 05 | 11 | Yes, (13) timeslice changed | No |
| 06 | 01 | No | No |
| 07 | 11 | No | Yes (count=1) |
| 08 | 12 | Yes (count = 11) | No |
| 09 | 13 | Yes (count = 12) | No |
| 10 | 14 | Yes (count = 13) | No |
| 11 | 01 | No, as max exceeded | No |
In the adapter configuration file this class is aliased as message-count-notification which is the preferred alternative to the fully qualified classname when building your configuration.
WorkflowInterceptorImpl.WorkflowInterceptorException
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
NOTIF_MESSAGE_ABOVE_THRESHOLD
The
Notification.getMessage() when the message count is above the configured threshold. |
static java.lang.String |
NOTIF_MESSAGE_BELOW_THRESHOLD
The
Notification.getMessage() when the message count is below the configured threshold. |
KEY_MESSAGE_COUNT, KEY_MESSAGE_ERROR, KEY_MESSAGE_SIZE, KEY_TIMESLICE_END, KEY_TIMESLICE_START
log
Constructor and Description |
---|
MessageCountNotification() |
MessageCountNotification(java.lang.String uid) |
MessageCountNotification(java.lang.String uid,
TimeInterval duration) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the component.
|
java.lang.Integer |
getMaxNotifications() |
java.lang.Integer |
getMessageCount() |
void |
init()
Initialises the component.
|
void |
setMaxNotifications(java.lang.Integer i)
Set the maximum number of consecutive notifications to emit.
|
void |
setMessageCount(java.lang.Integer l)
Set the upper boundary over which notifications will be emitted.
|
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.
|
asProperties, getAndIncrementStatistic, getCurrentTimeSlice, getTimesliceDuration, setTimesliceDuration
changeState, getUniqueId, parentChannel, parentWorkflow, prepare, registerParentChannel, registerParentWorkflow, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setUniqueId, wasSuccessful
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
processingStart
public static final java.lang.String NOTIF_MESSAGE_BELOW_THRESHOLD
Notification.getMessage()
when the message count is below the configured threshold.public static final java.lang.String NOTIF_MESSAGE_ABOVE_THRESHOLD
Notification.getMessage()
when the message count is above the configured threshold.public MessageCountNotification()
public MessageCountNotification(java.lang.String uid)
public MessageCountNotification(java.lang.String uid, TimeInterval duration)
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 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 java.lang.Integer getMessageCount()
public void setMessageCount(java.lang.Integer l)
l
- the threshold, defaults to null which means no notification on this boundarypublic java.lang.Integer getMaxNotifications()
public void setMaxNotifications(java.lang.Integer i)
i
- the max number of consecutive notifications.