Defines a monitor MBean designed to observe the values of a counter
attribute.
In addition, an offset mechanism enables particular counting
intervals to be detected. If the offset value is not zero,
whenever the threshold is triggered by the counter value reaching a
comparison level, that comparison level is incremented by the
offset value. This is regarded as taking place instantaneously,
that is, before the count is incremented. Thus, for each level,
the threshold triggers an event notification every time the count
increases by an interval equal to the offset value.
If the counter can wrap around its maximum value, the modulus
needs to be specified. The modulus is the value at which the
counter is reset to zero.
If the counter difference mode is used, the value of the
derived gauge is calculated as the difference between the observed
counter values for two successive observations. If this difference
is negative, the value of the derived gauge is incremented by the
value of the modulus. The derived gauge value (V[t]) is calculated
using the following method:
This implementation of the counter monitor requires the observed
attribute to be of the type integer (
).
Method from javax.management.monitor.CounterMonitor Detail: |
synchronized MonitorNotification buildAlarmNotification(ObjectName object,
String attribute,
Comparable<?> value) {
final CounterMonitorObservedObject o =
(CounterMonitorObservedObject) getObservedObject(object);
if (o == null)
return null;
// Notify the listeners and update the threshold if
// the updated derived gauge value is valid.
//
final MonitorNotification alarm;
if (o.getDerivedGaugeValid()) {
alarm = updateNotifications(o);
updateThreshold(o);
} else {
alarm = null;
}
return alarm;
}
|
ObservedObject createObservedObject(ObjectName object) {
final CounterMonitorObservedObject cmo =
new CounterMonitorObservedObject(object);
cmo.setThreshold(initThreshold);
cmo.setModulusExceeded(false);
cmo.setEventAlreadyNotified(false);
cmo.setPreviousScanCounter(null);
return cmo;
}
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 CounterMonitorObservedObject o =
(CounterMonitorObservedObject) getObservedObject(object);
if (o == null)
return null;
// Check if counter has wrapped around.
//
if (o.getModulusExceeded()) {
if (((Number)o.getDerivedGauge()).longValue() <
o.getDerivedGaugeExceeded().longValue()) {
o.setThreshold(initThreshold);
o.setModulusExceeded(false);
o.setEventAlreadyNotified(false);
}
}
// 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 getInitThreshold() {
return initThreshold;
}
Gets the initial threshold value common to all observed objects. |
public synchronized Number getModulus() {
return modulus;
}
Gets the modulus value common to all observed MBeans. |
public MBeanNotificationInfo[] getNotificationInfo() {
return notifsInfo.clone();
}
Returns a NotificationInfo object containing the
name of the Java class of the notification and the notification
types sent by the counter monitor. |
public synchronized boolean getNotify() {
return notify;
}
Gets the notification's on/off switch value common to all
observed MBeans. |
public synchronized Number getOffset() {
return offset;
}
Gets the offset value common to all observed MBeans. |
public synchronized Number getThreshold() {
return getThreshold(getObservedObject());
} Deprecated! As - of JMX 1.2, replaced by #getThreshold(ObjectName)
Gets the threshold value of the first object in the set of
observed MBeans. |
public synchronized Number getThreshold(ObjectName object) {
final CounterMonitorObservedObject o =
(CounterMonitorObservedObject) getObservedObject(object);
if (o == null)
return null;
// If the counter that is monitored rolls over when it reaches a
// maximum value, then the modulus value needs to be set to that
// maximum value. The threshold will then also roll over whenever
// it strictly exceeds the modulus value. When the threshold rolls
// over, it is reset to the value that was specified through the
// latest call to the monitor's setInitThreshold method, before
// any offsets were applied.
//
if (offset.longValue() > 0L &&
modulus.longValue() > 0L &&
o.getThreshold().longValue() > modulus.longValue()) {
return initThreshold;
} else {
return o.getThreshold();
}
}
Gets the current threshold value of the specified object, if
this object is contained in the set of observed MBeans, or
null otherwise. |
synchronized boolean isComparableTypeValid(ObjectName object,
String attribute,
Comparable<?> value) {
final CounterMonitorObservedObject o =
(CounterMonitorObservedObject) getObservedObject(object);
if (o == null)
return false;
// Check that the observed attribute is of type "Integer".
//
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 {
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 CounterMonitorObservedObject o =
(CounterMonitorObservedObject) getObservedObject(object);
if (o == null)
return false;
Class< ? extends Number > c = classForType(o.getType());
return (c.isInstance(o.getThreshold()) &&
isValidForType(offset, c) &&
isValidForType(modulus, c));
}
Tests if the threshold, offset and modulus of the specified observed
object are of the same type as the counter. Only integer types are
allowed.
Note:
If the optional offset or modulus have not been initialized, their
default value is an Integer object with a value equal to zero. |
synchronized void onErrorNotification(MonitorNotification notification) {
final CounterMonitorObservedObject o = (CounterMonitorObservedObject)
getObservedObject(notification.getObservedObject());
if (o == null)
return;
// Reset values.
//
o.setModulusExceeded(false);
o.setEventAlreadyNotified(false);
o.setPreviousScanCounter(null);
}
|
public synchronized void setDifferenceMode(boolean value) {
if (differenceMode == value)
return;
differenceMode = value;
// Reset values.
//
for (ObservedObject o : observedObjects) {
final CounterMonitorObservedObject cmo =
(CounterMonitorObservedObject) o;
cmo.setThreshold(initThreshold);
cmo.setModulusExceeded(false);
cmo.setEventAlreadyNotified(false);
cmo.setPreviousScanCounter(null);
}
}
Sets the difference mode flag value common to all observed MBeans. |
public synchronized void setInitThreshold(Number value) throws IllegalArgumentException {
if (value == null) {
throw new IllegalArgumentException("Null threshold");
}
if (value.longValue() < 0L) {
throw new IllegalArgumentException("Negative threshold");
}
if (initThreshold.equals(value))
return;
initThreshold = value;
// Reset values.
//
int index = 0;
for (ObservedObject o : observedObjects) {
resetAlreadyNotified(o, index++, THRESHOLD_ERROR_NOTIFIED);
final CounterMonitorObservedObject cmo =
(CounterMonitorObservedObject) o;
cmo.setThreshold(value);
cmo.setModulusExceeded(false);
cmo.setEventAlreadyNotified(false);
}
}
Sets the initial threshold value common to all observed objects.
The current threshold of every object in the set of
observed MBeans is updated consequently. |
public synchronized void setModulus(Number value) throws IllegalArgumentException {
if (value == null) {
throw new IllegalArgumentException("Null modulus");
}
if (value.longValue() < 0L) {
throw new IllegalArgumentException("Negative modulus");
}
if (modulus.equals(value))
return;
modulus = value;
// Reset values.
//
int index = 0;
for (ObservedObject o : observedObjects) {
resetAlreadyNotified(o, index++, THRESHOLD_ERROR_NOTIFIED);
final CounterMonitorObservedObject cmo =
(CounterMonitorObservedObject) o;
cmo.setModulusExceeded(false);
}
}
Sets the modulus value common to all observed MBeans. |
public synchronized void setNotify(boolean value) {
if (notify == value)
return;
notify = value;
}
Sets the notification's on/off switch value common to all
observed MBeans. |
public synchronized void setOffset(Number value) throws IllegalArgumentException {
if (value == null) {
throw new IllegalArgumentException("Null offset");
}
if (value.longValue() < 0L) {
throw new IllegalArgumentException("Negative offset");
}
if (offset.equals(value))
return;
offset = value;
int index = 0;
for (ObservedObject o : observedObjects) {
resetAlreadyNotified(o, index++, THRESHOLD_ERROR_NOTIFIED);
}
}
Sets the offset value common to all observed MBeans. |
public synchronized void setThreshold(Number value) throws IllegalArgumentException {
setInitThreshold(value);
} Deprecated! As - of JMX 1.2, replaced by #setInitThreshold
Sets the initial threshold value. |
public synchronized void start() {
if (isActive()) {
MONITOR_LOGGER.logp(Level.FINER, CounterMonitor.class.getName(),
"start", "the monitor is already active");
return;
}
// Reset values.
//
for (ObservedObject o : observedObjects) {
final CounterMonitorObservedObject cmo =
(CounterMonitorObservedObject) o;
cmo.setThreshold(initThreshold);
cmo.setModulusExceeded(false);
cmo.setEventAlreadyNotified(false);
cmo.setPreviousScanCounter(null);
}
doStart();
}
Starts the counter monitor. |
public synchronized void stop() {
doStop();
}
Stops the counter monitor. |