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 part common to all monitor MBeans.
A monitor MBean monitors values of an attribute common to a set of observed
MBeans. 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.
- Since:
- 1.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intDeprecated.protected int[]Selected monitor errors that have already been notified.protected static final intThe amount by which the capacity of the monitor arrays are automatically incremented when their size becomes greater than their capacity.protected StringDeprecated.No replacement.protected intThe number of valid components in the vector of observed objects.protected static final intFlag denoting that a notification has occurred after changing the observed attribute.protected static final intFlag denoting that a notification has occurred after changing the observed object or the observed attribute.protected static final intFlag denoting that a notification has occurred after changing the observed object.protected static final intThis flag is used to reset thealreadyNotifiedsmonitor attribute.protected static final intFlag denoting that a notification has occurred after changing the observed object or the observed attribute.protected MBeanServerReference to the MBean server. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddObservedObject(ObjectName object) Adds the specified object in the set of observed MBeans, if this object is not already present.booleancontainsObservedObject(ObjectName object) Tests whether the specified object is in the set of observed MBeans.longGets the granularity period (in milliseconds).Gets the attribute being observed.Deprecated.As of JMX 1.2, replaced bygetObservedObjects()Returns an array containing the objects being observed.booleanisActive()Tests whether the monitor MBean is active.voidAllows the monitor MBean to perform any operations needed after having been unregistered by the MBean server.voidpostRegister(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.voidAllows the monitor MBean to perform any operations it needs before being unregistered by the MBean server.preRegister(MBeanServer server, ObjectName name) Allows the monitor MBean to perform any operations it needs before being registered in the MBean server.voidremoveObservedObject(ObjectName object) Removes the specified object from the set of observed MBeans.voidsetGranularityPeriod(long period) Sets the granularity period (in milliseconds).voidsetObservedAttribute(String attribute) Sets the attribute to observe.voidsetObservedObject(ObjectName object) Deprecated.As of JMX 1.2, replaced byaddObservedObject(ObjectName)abstract voidstart()Starts the monitor.abstract voidstop()Stops the monitor.Methods declared in class NotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotificationModifier and TypeMethodDescriptionvoidaddNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) Adds a listener.Returns an array indicating, for each notification this MBean may send, the name of the Java class of the notification and the notification type.protected voidhandleNotification(NotificationListener listener, Notification notif, Object handback) This method is called bysendNotificationfor each listener in order to send the notification to that listener.voidRemoves a listener from this MBean.voidremoveNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) Removes a listener from this MBean.voidsendNotification(Notification notification) Sends a notification.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Field Details
-
capacityIncrement
protected static final int capacityIncrementThe amount by which the capacity of the monitor arrays are automatically incremented when their size becomes greater than their capacity.- See Also:
-
elementCount
protected int elementCountThe number of valid components in the vector of observed objects. -
alreadyNotified
Deprecated.equivalent toalreadyNotifieds[0].Monitor errors that have already been notified. -
alreadyNotifieds
protected int[] alreadyNotifiedsSelected monitor errors that have already been notified.
Each element in this array corresponds to an observed object in the vector. It contains a bit mask of the flags
OBSERVED_OBJECT_ERROR_NOTIFIEDetc, indicating whether the corresponding notification has already been sent for the MBean being monitored. -
server
Reference to 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:
-
RESET_FLAGS_ALREADY_NOTIFIED
protected static final int RESET_FLAGS_ALREADY_NOTIFIEDThis flag is used to reset thealreadyNotifiedsmonitor attribute.- See Also:
-
OBSERVED_OBJECT_ERROR_NOTIFIED
protected static final int OBSERVED_OBJECT_ERROR_NOTIFIEDFlag denoting that a notification has occurred after changing the observed object. This flag is used to check that the new observed object is registered in the MBean server at the time of the first notification.- See Also:
-
OBSERVED_ATTRIBUTE_ERROR_NOTIFIED
protected static final int OBSERVED_ATTRIBUTE_ERROR_NOTIFIEDFlag 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.- See Also:
-
OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED
protected static final int OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIEDFlag 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.- See Also:
-
RUNTIME_ERROR_NOTIFIED
protected static final int RUNTIME_ERROR_NOTIFIEDFlag 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.- See Also:
-
dbgTag
Deprecated.No replacement.This field is retained for compatibility but should not be referenced.
-
-
Constructor Details
-
Monitor
public Monitor()Constructor for subclasses to call.
-
-
Method Details
-
preRegister
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:
preRegisterin interfaceMBeanRegistration- 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:
Exception- if something goes wrong
-
postRegister
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:
postRegisterin interfaceMBeanRegistration- 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
Allows the monitor MBean to perform any operations it needs before being unregistered by the MBean server.Stops the monitor.
- Specified by:
preDeregisterin interfaceMBeanRegistration- Throws:
Exception- if something goes wrong
-
postDeregister
public void postDeregister()Allows the monitor MBean to perform any operations needed after having been unregistered by the MBean server.Not used in this context.
- Specified by:
postDeregisterin interfaceMBeanRegistration
-
start
-
stop
-
getObservedObject
Deprecated.As of JMX 1.2, replaced bygetObservedObjects()Returns the object name of the first object in the set of observed MBeans, ornullif there is no such object.- Specified by:
getObservedObjectin interfaceMonitorMBean- Returns:
- The object being observed.
- See Also:
-
setObservedObject
Deprecated.As of JMX 1.2, replaced byaddObservedObject(ObjectName)Removes all objects from the set of observed objects, and then adds the specified object.- Specified by:
setObservedObjectin interfaceMonitorMBean- Parameters:
object- The object to observe.- Throws:
IllegalArgumentException- The specified object is null.- See Also:
-
addObservedObject
Adds the specified object in the set of observed MBeans, if this object is not already present.- Specified by:
addObservedObjectin interfaceMonitorMBean- Parameters:
object- The object to observe.- Throws:
IllegalArgumentException- The specified object is null.
-
removeObservedObject
Removes the specified object from the set of observed MBeans.- Specified by:
removeObservedObjectin interfaceMonitorMBean- Parameters:
object- The object to remove.
-
containsObservedObject
Tests whether the specified object is in the set of observed MBeans.- Specified by:
containsObservedObjectin interfaceMonitorMBean- Parameters:
object- The object to check.- Returns:
trueif the specified object is present,falseotherwise.
-
getObservedObjects
Returns an array containing the objects being observed.- Specified by:
getObservedObjectsin interfaceMonitorMBean- Returns:
- The objects being observed.
-
getObservedAttribute
Gets the attribute being observed.
The observed attribute is not initialized by default (set to null).- Specified by:
getObservedAttributein interfaceMonitorMBean- Returns:
- The attribute being observed.
- See Also:
-
setObservedAttribute
Sets the attribute to observe.
The observed attribute is not initialized by default (set to null).- Specified by:
setObservedAttributein interfaceMonitorMBean- Parameters:
attribute- The attribute to observe.- Throws:
IllegalArgumentException- The specified attribute is null.- See Also:
-
getGranularityPeriod
public long getGranularityPeriod()Gets the granularity period (in milliseconds).
The default value of the granularity period is 10 seconds.- Specified by:
getGranularityPeriodin interfaceMonitorMBean- Returns:
- The granularity period value.
- See Also:
-
setGranularityPeriod
Sets the granularity period (in milliseconds).
The default value of the granularity period is 10 seconds.- Specified by:
setGranularityPeriodin interfaceMonitorMBean- Parameters:
period- The granularity period value.- Throws:
IllegalArgumentException- The granularity period is less than or equal to zero.- See Also:
-
isActive
public boolean isActive()Tests whether the monitor MBean is active. A monitor MBean is marked active when thestartmethod is called. It becomes inactive when thestopmethod is called.- Specified by:
isActivein interfaceMonitorMBean- Returns:
trueif the monitor MBean is active,falseotherwise.
-
alreadyNotifieds[0].