javax.management.monitor
Class Monitor

java.lang.Object
  |
  +--javax.management.NotificationBroadcasterSupport
        |
        +--javax.management.monitor.Monitor
All Implemented Interfaces:
MBeanRegistration, MonitorMBean, NotificationBroadcaster, NotificationEmitter
Direct Known Subclasses:
CounterMonitor, GaugeMonitor, StringMonitor

public abstract class Monitor
extends NotificationBroadcasterSupport
implements MonitorMBean, MBeanRegistration

Defines the common part to all monitor MBeans. A monitor MBean monitors values of an attribute in an observed MBean. The observed attribute is monitored at intervals specified by the granularity period. A gauge value (derived gauge) is derived from the values of the observed attribute.

Author:
Young Yang

Field Summary
protected  java.util.Map observedObjects
           
 
Constructor Summary
Monitor()
           
 
Method Summary
protected  void _start()
           
protected  void _stop()
           
abstract  void addObservedObject(ObjectName objectName)
          Adds the specified object in the set of observed MBeans.
 boolean containsObservedObject(ObjectName objectName)
          Tests whether the specified object is in the set of observed MBeans.
protected abstract  void doMonitor(ObjectName observedObject, java.lang.Object value)
           
 long getGranularityPeriod()
          Gets the granularity period (in milliseconds).
protected  javax.management.monitor.MonitorData getMonitorData(ObjectName observedObject)
           
 java.lang.String getObservedAttribute()
          Gets the attribute being observed.
 ObjectName[] getObservedObjects()
          Returns an array containing the objects being observed.
 boolean isActive()
          Tests if the monitor MBean is active.
 void postDeregister()
          Allows the MBean to perform any operations needed after having been de-registered in the MBean server.
 void postRegister(java.lang.Boolean value)
          Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.
 void preDeregister()
          Allows the MBean to perform any operations it needs before being de-registered by the MBean server.
 ObjectName preRegister(MBeanServer mbeanserver, ObjectName objectname)
          Allows the MBean to perform any operations it needs before being registered in the MBean server.
 void removeObservedObject(ObjectName objectName)
          Removes the specified object from the set of observed MBeans.
protected  void sendNotification(java.lang.String type, long timeStamp, java.lang.String message, java.lang.Object derivedValue, java.lang.Object trigger, ObjectName observedObject)
           
 void setGranularityPeriod(long period)
          Sets the granularity period (in milliseconds).
 void setObservedAttribute(java.lang.String attribute)
          Sets the attribute to observe.
abstract  void start()
           
abstract  void stop()
           
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

observedObjects

protected java.util.Map observedObjects
Constructor Detail

Monitor

public Monitor()
Method Detail

preRegister

public ObjectName preRegister(MBeanServer mbeanserver,
                              ObjectName objectname)
                       throws java.lang.Exception
Description copied from interface: MBeanRegistration
Allows the MBean to perform any operations it needs before being registered in the MBean server. If the name of the MBean is not specified, the MBean can provide a name for its registration. If any exception is raised, the MBean will not be registered in the MBean server.

Specified by:
preRegister in interface MBeanRegistration
Parameters:
mbeanserver - The MBean server in which the MBean will be registered.
objectname - The object name of the MBean.
Returns:
The name of the MBean registered.
Throws:
java.lang.Exception - This exception should be caught by the MBean server and re-thrown as an MBeanRegistrationException.

postRegister

public void postRegister(java.lang.Boolean value)
Description copied from interface: MBeanRegistration
Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.

Specified by:
postRegister in interface MBeanRegistration
Parameters:
value - Indicates whether or not the MBean has been successfully registered in the MBean server. The value false means that the registration phase has failed.

preDeregister

public void preDeregister()
                   throws java.lang.Exception
Description copied from interface: MBeanRegistration
Allows the MBean to perform any operations it needs before being de-registered by the MBean server.

Specified by:
preDeregister in interface MBeanRegistration
Throws:
java.lang.Exception - This exception should be caught by the MBean server and re-thrown as an MBeanRegistrationException.

postDeregister

public void postDeregister()
Description copied from interface: MBeanRegistration
Allows the MBean to perform any operations needed after having been de-registered in the MBean server.

Specified by:
postDeregister in interface MBeanRegistration

addObservedObject

public abstract void addObservedObject(ObjectName objectName)
                                throws java.lang.IllegalArgumentException
Description copied from interface: MonitorMBean
Adds the specified object in the set of observed MBeans.

Specified by:
addObservedObject in interface MonitorMBean
Parameters:
objectName - The object to observe.
Throws:
java.lang.IllegalArgumentException - the specified object is null.

getObservedObjects

public ObjectName[] getObservedObjects()
Description copied from interface: MonitorMBean
Returns an array containing the objects being observed.

Specified by:
getObservedObjects in interface MonitorMBean
Returns:
The objects being observed.

containsObservedObject

public boolean containsObservedObject(ObjectName objectName)
Description copied from interface: MonitorMBean
Tests whether the specified object is in the set of observed MBeans.

Specified by:
containsObservedObject in interface MonitorMBean
Parameters:
objectName - The object to check.
Returns:
true if the specified object is in the set, false otherwise.

removeObservedObject

public void removeObservedObject(ObjectName objectName)
Description copied from interface: MonitorMBean
Removes the specified object from the set of observed MBeans.

Specified by:
removeObservedObject in interface MonitorMBean
Parameters:
objectName - The object to remove.

getObservedAttribute

public java.lang.String getObservedAttribute()
Description copied from interface: MonitorMBean
Gets the attribute being observed.

Specified by:
getObservedAttribute in interface MonitorMBean
Returns:
The attribute being observed.
See Also:
MonitorMBean.setObservedAttribute(java.lang.String)

setObservedAttribute

public void setObservedAttribute(java.lang.String attribute)
                          throws java.lang.IllegalArgumentException
Description copied from interface: MonitorMBean
Sets the attribute to observe.

Specified by:
setObservedAttribute in interface MonitorMBean
Parameters:
attribute - The attribute to observe.
java.lang.IllegalArgumentException
See Also:
MonitorMBean.getObservedAttribute()

getGranularityPeriod

public long getGranularityPeriod()
Description copied from interface: MonitorMBean
Gets the granularity period (in milliseconds).

Specified by:
getGranularityPeriod in interface MonitorMBean
Returns:
The granularity period.
See Also:
MonitorMBean.setGranularityPeriod(long)

setGranularityPeriod

public void setGranularityPeriod(long period)
                          throws java.lang.IllegalArgumentException
Description copied from interface: MonitorMBean
Sets the granularity period (in milliseconds).

Specified by:
setGranularityPeriod in interface MonitorMBean
Parameters:
period - The granularity period.
Throws:
java.lang.IllegalArgumentException - The granularity period is less than or equal to zero.
See Also:
MonitorMBean.getGranularityPeriod()

isActive

public boolean isActive()
Description copied from interface: MonitorMBean
Tests if the monitor MBean is active. A monitor MBean is marked active when the start() method is called. It becomes inactive when the start() method is called.

Specified by:
isActive in interface MonitorMBean
Returns:
true if the monitor MBean is active, false otherwise.

start

public abstract void start()

stop

public abstract void stop()

sendNotification

protected void sendNotification(java.lang.String type,
                                long timeStamp,
                                java.lang.String message,
                                java.lang.Object derivedValue,
                                java.lang.Object trigger,
                                ObjectName observedObject)

_start

protected void _start()

_stop

protected void _stop()

getMonitorData

protected javax.management.monitor.MonitorData getMonitorData(ObjectName observedObject)

doMonitor

protected abstract void doMonitor(ObjectName observedObject,
                                  java.lang.Object value)