org.perf4j.helpers
Class StatisticsExposingMBean

java.lang.Object
  extended by javax.management.NotificationBroadcasterSupport
      extended by org.perf4j.helpers.StatisticsExposingMBean
All Implemented Interfaces:
DynamicMBean, NotificationBroadcaster, NotificationEmitter

public class StatisticsExposingMBean
extends NotificationBroadcasterSupport
implements DynamicMBean

This class provides a wrapper around GroupedTimingStatistics data so that this performance information can be exposed through JMX.

Author:
Alex Devine

Field Summary
protected  Map<AcceptableRangeConfiguration,Boolean> acceptableRanges
          These AcceptableRangeConfigurations force a notification to be sent if a statistic is updated to a value outside the allowable range.
protected  Pattern attributeNamePattern
          Pattern used to parse requested attribute names into the tag name and the statistic name
protected  GroupedTimingStatistics currentTimingStatistics
          The current underlying timing statistics whose values are exposed as MBean attributes.
static String DEFAULT_MBEAN_NAME
          Logging classes use this as the default ObjectName of this MBean when registering it with an MBeanServer.
protected  MBeanInfo managementInterface
          This MBeanInfo exposes this MBean's management interface to the MBeanServer.
protected  ObjectName mBeanName
          The name under which this MBean is registered in the MBean server.
static String OUT_OF_RANGE_NOTIFICATION_TYPE
          The type of the Notifications sent when a statistics value is outside of the acceptable range.
protected  long outOfRangeNotificationSeqNo
          This sequence number is required by the JMX Notification API.
protected  ExecutorService outOfRangeNotifierThread
          This single thread pool is used to send notifications if any values are outside of the acceptable ranges (this is necessary because the JMX spec states that the sendNotification method may be synchronous).
protected  Collection<String> tagsToExpose
          The tags whose statistics values are being exposed.
 
Constructor Summary
StatisticsExposingMBean(String mBeanName, Collection<String> tagsToExpose, Collection<AcceptableRangeConfiguration> acceptableRanges)
          Creates a new StatisticsExposingMBean whose management interface exposes performance attributes for the tags specified, and that sends notifications if attributes are outside of the acceptable ranges.
 
Method Summary
protected  MBeanInfo createMBeanInfoFromTagNames(Collection<String> tagNames)
          Helper method creates an MBeanInfo object that contains 6 read only attributes for each tag name, each attribute representing a different statistic.
 void exposeTag(String tagName)
          This MBean operation method allows the caller to add a tag whose statistics should be exposed as attributes at runtime.
 Object getAttribute(String attribute)
           
 AttributeList getAttributes(String[] attributeNames)
           
 MBeanInfo getMBeanInfo()
           
 MBeanNotificationInfo[] getNotificationInfo()
           
protected  Map<String,StatsValueRetriever> getStatsValueRetrievers()
          Overridable helper method gets the Map of statistic name to StatsValueRetriever.
 Object invoke(String actionName, Object[] params, String[] signature)
           
 boolean removeTag(String tagName)
          This MBean operation method allows the caller to remove, at runtime, a tag whose statistics are exposed.
protected  void sendNotificationsIfValuesNotAcceptable()
          This helper method sends notifications if any of the acceptable ranges detects an attribute value that is outside of the specified range.
protected  void sendOutOfRangeNotification(double attributeValue, AcceptableRangeConfiguration acceptableRange)
          Helper method is used to send the JMX notification because the attribute value doesn't fall within the acceptable range.
 void setAttribute(Attribute attribute)
           
 AttributeList setAttributes(AttributeList attributes)
           
 void updateCurrentTimingStatistics(GroupedTimingStatistics currentTimingStatistics)
          This method should be called to update the underlying timing statistics, which will correspondingly change the values of the exposed attributes.
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MBEAN_NAME

public static final String DEFAULT_MBEAN_NAME
Logging classes use this as the default ObjectName of this MBean when registering it with an MBeanServer.

See Also:
Constant Field Values

OUT_OF_RANGE_NOTIFICATION_TYPE

public static final String OUT_OF_RANGE_NOTIFICATION_TYPE
The type of the Notifications sent when a statistics value is outside of the acceptable range.

See Also:
Constant Field Values

mBeanName

protected ObjectName mBeanName
The name under which this MBean is registered in the MBean server.


managementInterface

protected MBeanInfo managementInterface
This MBeanInfo exposes this MBean's management interface to the MBeanServer.


tagsToExpose

protected Collection<String> tagsToExpose
The tags whose statistics values are being exposed.


acceptableRanges

protected Map<AcceptableRangeConfiguration,Boolean> acceptableRanges
These AcceptableRangeConfigurations force a notification to be sent if a statistic is updated to a value outside the allowable range. This Map maps acceptable ranges to whether or not the LAST check of the attribute value was good or bad. This is used to ensure only a single notification is sent when an attribute crosses the threshold to go out of range.


outOfRangeNotifierThread

protected ExecutorService outOfRangeNotifierThread
This single thread pool is used to send notifications if any values are outside of the acceptable ranges (this is necessary because the JMX spec states that the sendNotification method may be synchronous). This member variable will be null if no acceptable ranges are specified.


outOfRangeNotificationSeqNo

protected long outOfRangeNotificationSeqNo
This sequence number is required by the JMX Notification API.


currentTimingStatistics

protected GroupedTimingStatistics currentTimingStatistics
The current underlying timing statistics whose values are exposed as MBean attributes.


attributeNamePattern

protected Pattern attributeNamePattern
Pattern used to parse requested attribute names into the tag name and the statistic name

Constructor Detail

StatisticsExposingMBean

public StatisticsExposingMBean(String mBeanName,
                               Collection<String> tagsToExpose,
                               Collection<AcceptableRangeConfiguration> acceptableRanges)
Creates a new StatisticsExposingMBean whose management interface exposes performance attributes for the tags specified, and that sends notifications if attributes are outside of the acceptable ranges.

Parameters:
mBeanName - The name under which this MBean is registered in the MBean server
tagsToExpose - The names of the tags whose statistics should exposed. For each tag specified there will be 6 attributes whose getters are exposed: tagNameMean, tagNameStdDev, tagNameMin, tagNameMax, and tagNameCount and tagNameTPS
acceptableRanges - These acceptable ranges are used to send notifications if any of the monitored attributes go outside of the range.
Method Detail

updateCurrentTimingStatistics

public void updateCurrentTimingStatistics(GroupedTimingStatistics currentTimingStatistics)
This method should be called to update the underlying timing statistics, which will correspondingly change the values of the exposed attributes.

Parameters:
currentTimingStatistics - The TimingStatistics to set, may not be null

exposeTag

public void exposeTag(String tagName)
This MBean operation method allows the caller to add a tag whose statistics should be exposed as attributes at runtime.

Parameters:
tagName - The name of the tag whose statistics should be exposed.

removeTag

public boolean removeTag(String tagName)
This MBean operation method allows the caller to remove, at runtime, a tag whose statistics are exposed.

Parameters:
tagName - The name of the tag whose statistics should be removed as attributes from this MBean.
Returns:
Whether or not the specified tag was previously exposed on this MBean.

getAttribute

public Object getAttribute(String attribute)
                    throws AttributeNotFoundException,
                           MBeanException,
                           ReflectionException
Specified by:
getAttribute in interface DynamicMBean
Throws:
AttributeNotFoundException
MBeanException
ReflectionException

setAttribute

public void setAttribute(Attribute attribute)
                  throws AttributeNotFoundException,
                         InvalidAttributeValueException,
                         MBeanException,
                         ReflectionException
Specified by:
setAttribute in interface DynamicMBean
Throws:
AttributeNotFoundException
InvalidAttributeValueException
MBeanException
ReflectionException

getAttributes

public AttributeList getAttributes(String[] attributeNames)
Specified by:
getAttributes in interface DynamicMBean

setAttributes

public AttributeList setAttributes(AttributeList attributes)
Specified by:
setAttributes in interface DynamicMBean

invoke

public Object invoke(String actionName,
                     Object[] params,
                     String[] signature)
              throws MBeanException,
                     ReflectionException
Specified by:
invoke in interface DynamicMBean
Throws:
MBeanException
ReflectionException

getMBeanInfo

public MBeanInfo getMBeanInfo()
Specified by:
getMBeanInfo in interface DynamicMBean

getNotificationInfo

public MBeanNotificationInfo[] getNotificationInfo()
Specified by:
getNotificationInfo in interface NotificationBroadcaster
Overrides:
getNotificationInfo in class NotificationBroadcasterSupport

getStatsValueRetrievers

protected Map<String,StatsValueRetriever> getStatsValueRetrievers()
Overridable helper method gets the Map of statistic name to StatsValueRetriever.

Returns:
The StatsValueRetriever Map.

createMBeanInfoFromTagNames

protected MBeanInfo createMBeanInfoFromTagNames(Collection<String> tagNames)
Helper method creates an MBeanInfo object that contains 6 read only attributes for each tag name, each attribute representing a different statistic.

Parameters:
tagNames - The name of the tags whose statistics should be exposed as MBeanAttributes.
Returns:
The MBeanInfo that represents the management interface for this MBean.

sendNotificationsIfValuesNotAcceptable

protected void sendNotificationsIfValuesNotAcceptable()
This helper method sends notifications if any of the acceptable ranges detects an attribute value that is outside of the specified range. This method should only be called when the lock on this object's monitor is held.


sendOutOfRangeNotification

protected void sendOutOfRangeNotification(double attributeValue,
                                          AcceptableRangeConfiguration acceptableRange)
Helper method is used to send the JMX notification because the attribute value doesn't fall within the acceptable range. This method should only be called when the lock on this object's monitor is held.

Parameters:
attributeValue - The attribute value that falls outside the threshold
acceptableRange - The AcceptableRangeConfiguration used to constrain the acceptable value


Copyright © 2008-2011 perf4j.org. All Rights Reserved.