Defines a monitor MBean designed to observe the values of a gauge attribute.
A gauge monitor observes an attribute that is continuously
variable with time. A gauge monitor sends notifications as
follows:
This provides a hysteresis mechanism to avoid repeated triggering
of notifications when the attribute value makes small oscillations
around the high or low threshold value.
If the gauge difference mode is used, the value of the derived
gauge is calculated as the difference between the observed gauge
values for two successive observations.
The derived gauge value (V[t]) is calculated using the following method:
This implementation of the gauge monitor requires the observed
attribute to be of the type integer or floating-point
(
).
| Method from javax.management.monitor.GaugeMonitor Detail: |
synchronized MonitorNotification buildAlarmNotification(ObjectName object,
String attribute,
Comparable value) {
final GaugeMonitorObservedObject o =
(GaugeMonitorObservedObject) getObservedObject(object);
if (o == null)
return null;
// Notify the listeners if the updated derived
// gauge value is valid.
//
final MonitorNotification alarm;
if (o.getDerivedGaugeValid())
alarm = updateNotifications(o);
else
alarm = null;
return alarm;
}
|
ObservedObject createObservedObject(ObjectName object) {
final GaugeMonitorObservedObject gmo =
new GaugeMonitorObservedObject(object);
gmo.setStatus(RISING_OR_FALLING);
gmo.setPreviousScanGauge(null);
return gmo;
}
Factory method for ObservedObject creation. |
public synchronized Number getDerivedGauge() {
if (observedObjects.isEmpty()) {
return null;
} else {
return (Number) observedObjects.get(0).getDerivedGauge();
}
} Deprecated! As - of JMX 1.2, replaced by
#getDerivedGauge(ObjectName)
Returns the derived gauge of the first object in the set of
observed MBeans. |
public synchronized Number getDerivedGauge(ObjectName object) {
return (Number) super.getDerivedGauge(object);
}
Gets the derived gauge of the specified object, if this object is
contained in the set of observed MBeans, or null otherwise. |
synchronized Comparable getDerivedGaugeFromComparable(ObjectName object,
String attribute,
Comparable value) {
final GaugeMonitorObservedObject o =
(GaugeMonitorObservedObject) getObservedObject(object);
if (o == null)
return null;
// Update the derived gauge attributes and check the
// validity of the new value. The derived gauge value
// is invalid when the differenceMode flag is set to
// true and it is the first notification, i.e. we
// haven't got 2 consecutive values to update the
// derived gauge.
//
o.setDerivedGaugeValid(updateDerivedGauge(value, o));
return (Comparable< ? >) o.getDerivedGauge();
}
|
public synchronized long getDerivedGaugeTimeStamp() {
if (observedObjects.isEmpty()) {
return 0;
} else {
return observedObjects.get(0).getDerivedGaugeTimeStamp();
}
} Deprecated! As - of JMX 1.2, replaced by
#getDerivedGaugeTimeStamp(ObjectName)
Gets the derived gauge timestamp of the first object in the set
of observed MBeans. |
public synchronized long getDerivedGaugeTimeStamp(ObjectName object) {
return super.getDerivedGaugeTimeStamp(object);
}
Gets the derived gauge timestamp of the specified object, if
this object is contained in the set of observed MBeans, or
0 otherwise. |
public synchronized boolean getDifferenceMode() {
return differenceMode;
}
Gets the difference mode flag value common to all observed MBeans. |
public synchronized Number getHighThreshold() {
return highThreshold;
}
Gets the high threshold value common to all observed MBeans. |
public synchronized Number getLowThreshold() {
return lowThreshold;
}
Gets the low threshold value common to all observed MBeans. |
public MBeanNotificationInfo[] getNotificationInfo() {
return notifsInfo;
}
Returns a NotificationInfo object containing the
name of the Java class of the notification and the notification
types sent by the gauge monitor. |
public synchronized boolean getNotifyHigh() {
return notifyHigh;
}
Gets the high notification's on/off switch value common to all
observed MBeans. |
public synchronized boolean getNotifyLow() {
return notifyLow;
}
Gets the low notification's on/off switch value common to all
observed MBeans. |
synchronized boolean isComparableTypeValid(ObjectName object,
String attribute,
Comparable value) {
final GaugeMonitorObservedObject o =
(GaugeMonitorObservedObject) getObservedObject(object);
if (o == null)
return false;
// Check that the observed attribute is either of type
// "Integer" or "Float".
//
if (value instanceof Integer) {
o.setType(INTEGER);
} else if (value instanceof Byte) {
o.setType(BYTE);
} else if (value instanceof Short) {
o.setType(SHORT);
} else if (value instanceof Long) {
o.setType(LONG);
} else if (value instanceof Float) {
o.setType(FLOAT);
} else if (value instanceof Double) {
o.setType(DOUBLE);
} else {
return false;
}
return true;
}
This method globally sets the derived gauge type for the given
"object" and "attribute" after checking that the type of the
supplied observed attribute value is one of the value types
supported by this monitor. |
synchronized boolean isThresholdTypeValid(ObjectName object,
String attribute,
Comparable value) {
final GaugeMonitorObservedObject o =
(GaugeMonitorObservedObject) getObservedObject(object);
if (o == null)
return false;
Class< ? extends Number > c = classForType(o.getType());
return (isValidForType(highThreshold, c) &&
isValidForType(lowThreshold, c));
}
Tests if the threshold high and threshold low are both of the
same type as the gauge. Both integer and floating-point types
are allowed.
Note:
If the optional lowThreshold or highThreshold have not been
initialized, their default value is an Integer object with
a value equal to zero. |
synchronized void onErrorNotification(MonitorNotification notification) {
final GaugeMonitorObservedObject o = (GaugeMonitorObservedObject)
getObservedObject(notification.getObservedObject());
if (o == null)
return;
// Reset values.
//
o.setStatus(RISING_OR_FALLING);
o.setPreviousScanGauge(null);
}
|
public synchronized void setDifferenceMode(boolean value) {
if (differenceMode == value)
return;
differenceMode = value;
// Reset values.
//
for (ObservedObject o : observedObjects) {
final GaugeMonitorObservedObject gmo =
(GaugeMonitorObservedObject) o;
gmo.setStatus(RISING_OR_FALLING);
gmo.setPreviousScanGauge(null);
}
}
Sets the difference mode flag value common to all observed MBeans. |
public synchronized void setNotifyHigh(boolean value) {
if (notifyHigh == value)
return;
notifyHigh = value;
}
Sets the high notification's on/off switch value common to all
observed MBeans. |
public synchronized void setNotifyLow(boolean value) {
if (notifyLow == value)
return;
notifyLow = value;
}
Sets the low notification's on/off switch value common to all
observed MBeans. |
public synchronized void setThresholds(Number highValue,
Number lowValue) throws IllegalArgumentException {
if ((highValue == null) || (lowValue == null)) {
throw new IllegalArgumentException("Null threshold value");
}
if (highValue.getClass() != lowValue.getClass()) {
throw new IllegalArgumentException("Different type " +
"threshold values");
}
if (isFirstStrictlyGreaterThanLast(lowValue, highValue,
highValue.getClass().getName())) {
throw new IllegalArgumentException("High threshold less than " +
"low threshold");
}
if (highThreshold.equals(highValue) && lowThreshold.equals(lowValue))
return;
highThreshold = highValue;
lowThreshold = lowValue;
// Reset values.
//
int index = 0;
for (ObservedObject o : observedObjects) {
resetAlreadyNotified(o, index++, THRESHOLD_ERROR_NOTIFIED);
final GaugeMonitorObservedObject gmo =
(GaugeMonitorObservedObject) o;
gmo.setStatus(RISING_OR_FALLING);
}
}
Sets the high and the low threshold values common to all
observed MBeans. |
public synchronized void start() {
if (isActive()) {
MONITOR_LOGGER.logp(Level.FINER, GaugeMonitor.class.getName(),
"start", "the monitor is already active");
return;
}
// Reset values.
//
for (ObservedObject o : observedObjects) {
final GaugeMonitorObservedObject gmo =
(GaugeMonitorObservedObject) o;
gmo.setStatus(RISING_OR_FALLING);
gmo.setPreviousScanGauge(null);
}
doStart();
}
Starts the gauge monitor. |
public synchronized void stop() {
doStop();
}
|