javax.management.monitor
Class Monitor

java.lang.Object
  |
  +--javax.management.NotificationBroadcasterSupport
        |
        +--javax.management.monitor.Monitor
Direct Known Subclasses:
CounterMonitor, GaugeMonitor, StringMonitor

public abstract class Monitor
extends NotificationBroadcasterSupport
implements MonitorMBean, MBeanRegistration, java.io.Serializable

This abstract class 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.

See Also:
Serialized Form

Field Summary
protected  int alreadyNotified
          Selected monitor errors that have already been notified.
protected  java.lang.String dbgTag
           
protected static int OBSERVED_ATTRIBUTE_ERROR_NOTIFIED
          Flag denoting that a notification has occured after changing the observed attribute.
protected static int OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED
          Flag denoting that a notification has occured after changing the observed object or the observed attribute.
protected static int OBSERVED_OBJECT_ERROR_NOTIFIED
          Flag denoting that a notification has occured after changing the observed object.
protected static int RESET_FLAGS_ALREADY_NOTIFIED
          This flag is used to reset the alreadyNotified monitor attribute.
protected static int RUNTIME_ERROR_NOTIFIED
          Flag denoting that a notification has occured after changing the observed object or the observed attribute.
protected  MBeanServer server
          Reference on the MBean server.
 
Constructor Summary
Monitor()
           
 
Method Summary
 long getGranularityPeriod()
          Gets the granularity period (in milliseconds).
 java.lang.String getObservedAttribute()
          Gets the attribute being observed.
 ObjectName getObservedObject()
          Gets the object name of the object being observed.
 boolean isActive()
          Tests if the Monitor MBean is active.
 void postDeregister()
          Allows the Monitor MBean to perform any operations needed after having been de-registered by the MBean server.
 void postRegister(java.lang.Boolean registrationDone)
          Allows the Monitor MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.
 void preDeregister()
          Allows the Monitor MBean to perform any operations it needs before being de-registered by the MBean server.
 ObjectName preRegister(MBeanServer server, ObjectName name)
          Allows the Monitor MBean to perform any operations it needs before being registered in the MBean server.
 void setGranularityPeriod(long period)
          Sets the granularity period (in milliseconds).
 void setObservedAttribute(java.lang.String attribute)
          Sets the attribute to observe.
 void setObservedObject(ObjectName object)
          Sets the object to observe identified by its object name.
abstract  void start()
          Starts the Monitor.
abstract  void stop()
          Stops the Monitor.
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server

protected MBeanServer server
Reference on the MBean server. This reference is null when the Monitor MBean is not registered in a MBean server. This reference is initialized before the Monitor MBean is registered in the MBean server.
See Also:
preRegister(MBeanServer server, ObjectName name)

alreadyNotified

protected int alreadyNotified
Selected monitor errors that have already been notified.

RESET_FLAGS_ALREADY_NOTIFIED

protected static final int RESET_FLAGS_ALREADY_NOTIFIED
This flag is used to reset the alreadyNotified monitor attribute.

OBSERVED_OBJECT_ERROR_NOTIFIED

protected static final int OBSERVED_OBJECT_ERROR_NOTIFIED
Flag denoting that a notification has occured after changing the observed object. This flag is used to check that the new observed object is registered in the MBean server at the first notification time.

OBSERVED_ATTRIBUTE_ERROR_NOTIFIED

protected static final int OBSERVED_ATTRIBUTE_ERROR_NOTIFIED
Flag denoting that a notification has occured after changing the observed attribute. This flag is used to check that the new observed attribute belongs to the observed object at the first notification time.

OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED

protected static final int OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED
Flag denoting that a notification has occured after changing the observed object or the observed attribute. This flag is used to check that the observed attribute type is correct (depending on the monitor in use) at the first notification time.

RUNTIME_ERROR_NOTIFIED

protected static final int RUNTIME_ERROR_NOTIFIED
Flag denoting that a notification has occured after changing the observed object or the observed attribute. This flag is used to notify any exception (except the cases described above) when trying to get the value of the observed attribute at the first notification time.

dbgTag

protected java.lang.String dbgTag
Constructor Detail

Monitor

public Monitor()
Method Detail

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws java.lang.Exception
Allows the Monitor MBean to perform any operations it needs before being registered in the MBean server.

Initializes the reference to the MBean server.

Specified by:
preRegister in interface MBeanRegistration
Parameters:
server - The MBean server in which the Monitor MBean will be registered.
name - The object name of the Monitor MBean.
Returns:
The name of the Monitor MBean registered.
Throws:
java.lang.Exception -  

postRegister

public void postRegister(java.lang.Boolean registrationDone)
Allows the Monitor 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:
registrationDone - Indicates whether or not the Monitor MBean has been successfully registered in the MBean server. The value false means that either the registration phase has failed.

preDeregister

public void preDeregister()
                   throws java.lang.Exception
Allows the Monitor MBean to perform any operations it needs before being de-registered by the MBean server.

Stops the monitor.

Specified by:
preDeregister in interface MBeanRegistration
Throws:
java.lang.Exception -  

postDeregister

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

start

public abstract void start()
Starts the Monitor.
Specified by:
start in interface MonitorMBean

stop

public abstract void stop()
Stops the Monitor.
Specified by:
stop in interface MonitorMBean

getObservedObject

public ObjectName getObservedObject()
Gets the object name of the object being observed.
Specified by:
getObservedObject in interface MonitorMBean
Returns:
The object being observed.

setObservedObject

public void setObservedObject(ObjectName object)
Sets the object to observe identified by its object name.
Specified by:
setObservedObject in interface MonitorMBean
Parameters:
object - The object to observe.

getObservedAttribute

public java.lang.String getObservedAttribute()
Gets the attribute being observed.
Specified by:
getObservedAttribute in interface MonitorMBean
Returns:
The attribute being observed.

setObservedAttribute

public void setObservedAttribute(java.lang.String attribute)
Sets the attribute to observe.
Specified by:
setObservedAttribute in interface MonitorMBean
Parameters:
attribute - The attribute to observe.

getGranularityPeriod

public long getGranularityPeriod()
Gets the granularity period (in milliseconds).
Specified by:
getGranularityPeriod in interface MonitorMBean
Returns:
The granularity period value.

setGranularityPeriod

public void setGranularityPeriod(long period)
                          throws java.lang.IllegalArgumentException
Sets the granularity period (in milliseconds).
Specified by:
setGranularityPeriod in interface MonitorMBean
Parameters:
period - The granularity period value.
Throws:
java.lang.IllegalArgumentException - The granularity period is less than or equal to zero.

isActive

public boolean isActive()
Tests if the Monitor MBean is active. A Monitor MBean is marked active when the start method is called. It becomes inactive when the stop method is called.
Specified by:
isActive in interface MonitorMBean
Returns:
True if the Monitor MBean is active, false otherwise.