javax.management.monitor
Class Monitor

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

public abstract class Monitor
extends NotificationBroadcasterSupport
implements MonitorMBean, MBeanRegistration

This is the super class for all types of monitor MBeans and defines the common part to all monitor MBeans. Using Monitor MBeans, the observed attribute of another MBean (the observed MBean) is monitored at intervals specified by the granularity period. A gauge value (derived gauge) is derived from the values of the observed attribute.


Field Summary
protected  int alreadyNotified
          Deprecated. equivalent to alreadyNotifieds[0].
protected  int[] alreadyNotifieds
          Selected monitor errors that have already been notified.
protected static int capacityIncrement
          The amount by which the capacity of the monitor arrays are automatically incremented when size exceeds their capacity.
protected  java.lang.String dbgTag
          This field is not required.
(package private)  java.util.ArrayList derivedGaugeTimeStamp
          Derived gauge timestamp as Long object.
protected  int elementCount
          Number of valid components in the list of observed objects.
(package private)  boolean isActive
          Indicates whether this Monitor is live or dead.
(package private)  Log logger
          Logger
protected static int OBSERVED_ATTRIBUTE_ERROR_NOTIFIED
          Flag denoting that a notification has occurred after changing the observed attribute.
protected static int OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED
          Flag denoting that a notification has occurred after changing the observed object or the observed attribute.
protected static int OBSERVED_OBJECT_ERROR_NOTIFIED
          Flag denoting that a notification has occurred after changing the observed object or the observed attribute.
protected static int RESET_FLAGS_ALREADY_NOTIFIED
          This flag is used to reset the alreadyNotifieds monitor attribute.
protected static int RUNTIME_ERROR_NOTIFIED
          Flag denoting that a notification has occurred after changing the observed object or the observed attribute.
(package private)  long sequenceNumber
          Monitor sequence number, used when constructing MonitorNotification.
protected  MBeanServer server
          Reference on the MBean server.
 
Fields inherited from class javax.management.NotificationBroadcasterSupport
li
 
Constructor Summary
Monitor()
          Default constructor
 
Method Summary
 void addObservedObject(ObjectName object)
          This method adds the specified object in the set of observed MBeans, if this object is not already present.
 boolean containsObservedObject(ObjectName objName)
          This method tests whether the specified object is in the set of observed MBeans.
 long getGranularityPeriod()
          This method gets the granularity period (in milliseconds).
 MBeanNotificationInfo[] getNotificationInfo()
          This method returns a NotificationInfo object containing the name of the Java class of the notification and the notification types sent by the counter monitor.
 java.lang.String getObservedAttribute()
          This method gets the name of the attribute being observed.
 ObjectName getObservedObject()
          Deprecated. Replaced by getObservedObjects()
(package private)  ObjectName getObservedObject(int index)
          Retrives the ObjectName of the object at the specified index in the list of observed MBeans.
 ObjectName[] getObservedObjects()
          This method returns an array containing the objects being observed.
(package private)  int indexOf(java.lang.Object objName)
          Retrives the index of the first occurance of the monitored object in the list of observed MBeans.
(package private)  void insertElementAt(int[] array, int value, int index)
          Inserts the specified value at the given index in the specified int array
(package private) abstract  void insertSpecificElementAt(int index)
          This method will be implemented by the specific monitor classes (Counter, Gauge and String).
 boolean isActive()
          This method tests whether the monitor MBean is active.
(package private)  boolean isFlagsReset(int index, int errorType)
          Checks whether the flag is been set for the specified error type
 void postDeregister()
          This method allows the monitor MBean to perform any operations needed after having been de-registered by the MBean server.
 void postRegister(java.lang.Boolean registrationDone)
          This method 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()
          This method allows the monitor MBean to perform any operations it needs before being de-registered by the MBean server.
 ObjectName preRegister(MBeanServer server, ObjectName name)
          This method allows the monitor MBean to perform any operations it needs before being registered in the MBean server.
(package private)  void removeElementAt(int[] array, int index)
          Removes the component at the specified index from the specified int array.
 void removeObservedObject(ObjectName objName)
          This method removes the specified object from the set of observed MBeans.
(package private) abstract  void removeSpecificElementAt(int index)
          This method will be implemented by the specific monitor classes (Counter, Gauge and String).
(package private)  void resetAllAlreadyNotifiedFlags(int index)
          Resets all the already notified flags
(package private)  void resetAlreadyNotifiedFlag(int index, int mask)
          Reset the given bits in the given element of alreadyNotifieds.
(package private)  void sendNotification(java.lang.String type, long timeStamp, java.lang.String msg, java.lang.Object derGauge, java.lang.Object trigger, int index)
          This method is used to create and send a monitor notification to all registered listeners for this kind of notification, by the monitor MBean.
(package private)  void setAlreadyNotifiedFlag(int index, int mask)
          Set the given bits in the given element of alreadyNotifieds.
 void setGranularityPeriod(long period)
          This method sets the granularity period (in milliseconds).
 void setObservedAttribute(java.lang.String attribute)
          This method sets the attribute being observed.
 void setObservedObject(ObjectName objName)
          Deprecated. Replaced by addObservedObject(javax.management.ObjectName)
abstract  void start()
          This method starts the monitor.
abstract  void stop()
          This method stops the monitor.
(package private)  void updateDeprecatedAlreadyNotifiedFlag()
          Update the deprecated alreadyNotified field.
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, handleNotification, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

capacityIncrement

protected static final int capacityIncrement
The amount by which the capacity of the monitor arrays are automatically incremented when size exceeds their capacity.

elementCount

protected int elementCount
Number of valid components in the list of observed objects.

alreadyNotified

protected int alreadyNotified
Deprecated. equivalent to alreadyNotifieds[0].

Monitor errors that have already been notified.

alreadyNotifieds

protected int[] alreadyNotifieds

Selected monitor errors that have already been notified.

Each element in this array corresponds to an observed object in the list. It contains a bit mask of the flags OBSERVED_OBJECT_ERROR_NOTIFIED etc, indicating whether the corresponding notification has already been sent for the MBean being monitored.


server

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

derivedGaugeTimeStamp

transient java.util.ArrayList derivedGaugeTimeStamp
Derived gauge timestamp as Long object.
Each element in this array corresponds to an observed object in the list.

RESET_FLAGS_ALREADY_NOTIFIED

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

OBSERVED_OBJECT_ERROR_NOTIFIED

protected static final int OBSERVED_OBJECT_ERROR_NOTIFIED
Flag denoting that a notification has occurred 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 time of the first notification.

OBSERVED_ATTRIBUTE_ERROR_NOTIFIED

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

OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED

protected static final int OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED
Flag denoting that a notification has occurred 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 time of the first notification.

RUNTIME_ERROR_NOTIFIED

protected static final int RUNTIME_ERROR_NOTIFIED
Flag denoting that a notification has occurred 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 time of the first notification.

isActive

transient boolean isActive
Indicates whether this Monitor is live or dead. The default value is set to false.

sequenceNumber

transient long sequenceNumber
Monitor sequence number, used when constructing MonitorNotification.

logger

Log logger
Logger

dbgTag

protected java.lang.String dbgTag
This field is not required.
Constructor Detail

Monitor

public Monitor()
Default constructor
Method Detail

getGranularityPeriod

public long getGranularityPeriod()
This method gets the granularity period (in milliseconds).
The default value of the granularity period is 10 seconds.
Specified by:
getGranularityPeriod in interface MonitorMBean
Returns:
long value representing the granularity period (in milliseconds).
See Also:
setGranularityPeriod(long)

setGranularityPeriod

public void setGranularityPeriod(long period)
                          throws java.lang.IllegalArgumentException
This method sets the granularity period (in milliseconds). The default value is ten seconds.
Specified by:
setGranularityPeriod in interface MonitorMBean
Parameters:
period - the granularity period value.
Throws:
java.lang.IllegalArgumentException - if the granularity period is less than or equal to zero.
See Also:
getGranularityPeriod()

getObservedAttribute

public java.lang.String getObservedAttribute()
This method gets the name of the attribute being observed.
Specified by:
getObservedAttribute in interface MonitorMBean
Returns:
String The name of the attribute that is being observed.
See Also:
setObservedAttribute(java.lang.String)

setObservedAttribute

public void setObservedAttribute(java.lang.String attribute)
                          throws java.lang.IllegalArgumentException
This method sets the attribute being observed.
The observed attribute is not initialized by default (set to null).
Specified by:
setObservedAttribute in interface MonitorMBean
Parameters:
attribute - The attribute to be observed.
Throws:
java.lang.IllegalArgumentException - The specified attribute is null.
See Also:
getObservedAttribute()

getObservedObject

public ObjectName getObservedObject()
Deprecated. Replaced by getObservedObjects()

Returns the object name of the first object in the set of observed MBeans, or null if there is no such object.
Specified by:
getObservedObject in interface MonitorMBean
Returns:
The object being observed.
See Also:
setObservedObject(ObjectName)

setObservedObject

public void setObservedObject(ObjectName objName)
                       throws java.lang.IllegalArgumentException
Deprecated. Replaced by addObservedObject(javax.management.ObjectName)

Removes all objects from the set of observed objects, and then adds the specified object.
Specified by:
setObservedObject in interface MonitorMBean
Parameters:
object - The object to observe.
Throws:
java.lang.IllegalArgumentException - The specified object is null.
See Also:
getObservedObject()

isActive

public boolean isActive()
This method tests whether 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.

addObservedObject

public void addObservedObject(ObjectName object)
                       throws java.lang.IllegalArgumentException
This method adds the specified object in the set of observed MBeans, if this object is not already present.
Specified by:
addObservedObject in interface MonitorMBean
Parameters:
object - The object to observe.
Throws:
java.lang.IllegalArgumentException - The specified object is null.

removeObservedObject

public void removeObservedObject(ObjectName objName)
This method removes the specified object from the set of observed MBeans.
Specified by:
removeObservedObject in interface MonitorMBean
Parameters:
object - The object to remove.

containsObservedObject

public boolean containsObservedObject(ObjectName objName)
This method tests whether the specified object is in the set of observed MBeans.
Specified by:
containsObservedObject in interface MonitorMBean
Parameters:
object - The object to check.
Returns:
true if the specified object is present, false otherwise.

getObservedObjects

public ObjectName[] getObservedObjects()
This method returns an array containing the objects being observed.
Specified by:
getObservedObjects in interface MonitorMBean
Returns:
The objects being observed.

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws java.lang.Exception
This method 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)
This method allows the monitor MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.

Not used in this context.

Specified by:
postRegister in interface MBeanRegistration
Tags copied from interface: MBeanRegistration
Parameters:
registrationDone - 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
This method 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:
This - operation throws java.lang.Exception

postDeregister

public void postDeregister()
This method allows the monitor MBean to perform any operations needed after having been de-registered by the MBean server.

Not used in this context.

Specified by:
postDeregister in interface MBeanRegistration

start

public abstract void start()
This method starts the monitor.
Specified by:
start in interface MonitorMBean

stop

public abstract void stop()
This method stops the monitor.
Specified by:
stop in interface MonitorMBean

getNotificationInfo

public MBeanNotificationInfo[] getNotificationInfo()
This method returns a NotificationInfo object containing the name of the Java class of the notification and the notification types sent by the counter monitor.
Overrides:
getNotificationInfo in class NotificationBroadcasterSupport
Returns:
An Array of MBeanNotificationInfo objects.

insertSpecificElementAt

abstract void insertSpecificElementAt(int index)
This method will be implemented by the specific monitor classes (Counter, Gauge and String). It updates all the specific arrays after adding a new observed object in the list.

removeSpecificElementAt

abstract void removeSpecificElementAt(int index)
This method will be implemented by the specific monitor classes (Counter, Gauge and String). It updates all the specific arrays after removing an observed object from the vector.

sendNotification

void sendNotification(java.lang.String type,
                      long timeStamp,
                      java.lang.String msg,
                      java.lang.Object derGauge,
                      java.lang.Object trigger,
                      int index)
This method is used to create and send a monitor notification to all registered listeners for this kind of notification, by the monitor MBean.
Parameters:
type - The notification type.
timeStamp - The notification emission date.
msg - The notification message.
derGauge - The derived gauge.
trigger - The threshold/string (depending on the monitor type) that triggered off the notification.
index - The index of the observed object that triggered off the notification.

getObservedObject

ObjectName getObservedObject(int index)
                       throws java.lang.ArrayIndexOutOfBoundsException
Retrives the ObjectName of the object at the specified index in the list of observed MBeans.
Returns:
The observed object at the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If invalid index.

indexOf

int indexOf(java.lang.Object objName)
Retrives the index of the first occurance of the monitored object in the list of observed MBeans.
Returns:
The index of the observed object in the list.

isFlagsReset

boolean isFlagsReset(int index,
                     int errorType)
Checks whether the flag is been set for the specified error type

resetAllAlreadyNotifiedFlags

void resetAllAlreadyNotifiedFlags(int index)
Resets all the already notified flags

updateDeprecatedAlreadyNotifiedFlag

void updateDeprecatedAlreadyNotifiedFlag()
Update the deprecated alreadyNotified field.

setAlreadyNotifiedFlag

void setAlreadyNotifiedFlag(int index,
                            int mask)
Set the given bits in the given element of alreadyNotifieds. Ensure the deprecated alreadyNotified field is updated if appropriate.

resetAlreadyNotifiedFlag

void resetAlreadyNotifiedFlag(int index,
                              int mask)
Reset the given bits in the given element of alreadyNotifieds. Ensure the deprecated alreadyNotified field is updated if appropriate.

insertElementAt

void insertElementAt(int[] array,
                     int value,
                     int index)
Inserts the specified value at the given index in the specified int array

removeElementAt

void removeElementAt(int[] array,
                     int index)
Removes the component at the specified index from the specified int array.