Methods Summary |
---|
synchronized javax.management.monitor.MonitorNotification | buildAlarmNotification(javax.management.ObjectName object, java.lang.String attribute, java.lang.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(javax.management.ObjectName object)Factory method for ObservedObject creation.
final CounterMonitorObservedObject cmo =
new CounterMonitorObservedObject(object);
cmo.setThreshold(initThreshold);
cmo.setModulusExceeded(false);
cmo.setEventAlreadyNotified(false);
cmo.setPreviousScanCounter(null);
return cmo;
|
public synchronized java.lang.Number | getDerivedGauge()Returns the derived gauge of the first object in the set of
observed MBeans.
if (observedObjects.isEmpty()) {
return null;
} else {
return (Number) observedObjects.get(0).getDerivedGauge();
}
|
public synchronized java.lang.Number | getDerivedGauge(javax.management.ObjectName object)Gets the derived gauge of the specified object, if this object is
contained in the set of observed MBeans, or null otherwise.
return (Number) super.getDerivedGauge(object);
|
synchronized java.lang.Comparable | getDerivedGaugeFromComparable(javax.management.ObjectName object, java.lang.String attribute, java.lang.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()Gets the derived gauge timestamp of the first object in the set
of observed MBeans.
if (observedObjects.isEmpty()) {
return 0;
} else {
return observedObjects.get(0).getDerivedGaugeTimeStamp();
}
|
public synchronized long | getDerivedGaugeTimeStamp(javax.management.ObjectName object)Gets the derived gauge timestamp of the specified object, if
this object is contained in the set of observed MBeans, or
0 otherwise.
return super.getDerivedGaugeTimeStamp(object);
|
public synchronized boolean | getDifferenceMode()Gets the difference mode flag value common to all observed MBeans.
return differenceMode;
|
public synchronized java.lang.Number | getInitThreshold()Gets the initial threshold value common to all observed objects.
return initThreshold;
|
public synchronized java.lang.Number | getModulus()Gets the modulus value common to all observed MBeans.
return modulus;
|
public javax.management.MBeanNotificationInfo[] | getNotificationInfo()Returns a NotificationInfo object containing the
name of the Java class of the notification and the notification
types sent by the counter monitor.
return notifsInfo;
|
public synchronized boolean | getNotify()Gets the notification's on/off switch value common to all
observed MBeans.
return notify;
|
public synchronized java.lang.Number | getOffset()Gets the offset value common to all observed MBeans.
return offset;
|
public synchronized java.lang.Number | getThreshold()Gets the threshold value of the first object in the set of
observed MBeans.
return getThreshold(getObservedObject());
|
public synchronized java.lang.Number | getThreshold(javax.management.ObjectName object)Gets the current threshold value of the specified object, if
this object is contained in the set of observed MBeans, or
null otherwise.
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();
}
|
synchronized boolean | isComparableTypeValid(javax.management.ObjectName object, java.lang.String attribute, java.lang.Comparable value)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.
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;
|
synchronized boolean | isThresholdTypeValid(javax.management.ObjectName object, java.lang.String attribute, java.lang.Comparable value)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.
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));
|
java.lang.String | makeDebugTag()
// TRACES & DEBUG
//---------------
return "CounterMonitor";
|
synchronized void | onErrorNotification(javax.management.monitor.MonitorNotification notification)
final CounterMonitorObservedObject o = (CounterMonitorObservedObject)
getObservedObject(notification.getObservedObject());
if (o == null)
return;
// Reset values.
//
o.setModulusExceeded(false);
o.setEventAlreadyNotified(false);
o.setPreviousScanCounter(null);
|
private synchronized void | setDerivedGaugeWithDifference(java.lang.Number scanCounter, java.lang.Number mod, javax.management.monitor.CounterMonitor$CounterMonitorObservedObject o)Sets the derived gauge of the specified observed object when the
differenceMode flag is set to true . Integer types
only are allowed.
/* We do the arithmetic using longs here even though the
result may end up in a smaller type. Since
l == (byte)l (mod 256) for any long l,
(byte) ((byte)l1 + (byte)l2) == (byte) (l1 + l2),
and likewise for subtraction. So it's the same as if
we had done the arithmetic in the smaller type.*/
long derived =
scanCounter.longValue() - o.getPreviousScanCounter().longValue();
if (mod != null)
derived += modulus.longValue();
switch (o.getType()) {
case INTEGER: o.setDerivedGauge(new Integer((int) derived)); break;
case BYTE: o.setDerivedGauge(new Byte((byte) derived)); break;
case SHORT: o.setDerivedGauge(new Short((short) derived)); break;
case LONG: o.setDerivedGauge(new Long(derived)); break;
default:
// Should never occur...
if (isDebugOn()) {
debug("setDerivedGaugeWithDifference",
"the threshold type is invalid");
}
break;
}
|
public synchronized void | setDifferenceMode(boolean value)Sets the difference mode flag value common to all observed MBeans.
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);
}
|
public synchronized void | setInitThreshold(java.lang.Number value)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.
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);
}
|
public synchronized void | setModulus(java.lang.Number value)Sets the modulus value common to all observed MBeans.
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);
}
|
public synchronized void | setNotify(boolean value)Sets the notification's on/off switch value common to all
observed MBeans.
if (notify == value)
return;
notify = value;
|
public synchronized void | setOffset(java.lang.Number value)Sets the offset value common to all observed MBeans.
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);
}
|
public synchronized void | setThreshold(java.lang.Number value)Sets the initial threshold value.
setInitThreshold(value);
|
public synchronized void | start()Starts the counter monitor.
if (isActive()) {
if (isTraceOn()) {
trace("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();
|
public synchronized void | stop()Stops the counter monitor.
doStop();
|
private synchronized boolean | updateDerivedGauge(java.lang.Object scanCounter, javax.management.monitor.CounterMonitor$CounterMonitorObservedObject o)Updates the derived gauge attribute of the observed object.
boolean is_derived_gauge_valid;
// The counter difference mode is used.
//
if (differenceMode) {
// The previous scan counter has been initialized.
//
if (o.getPreviousScanCounter() != null) {
setDerivedGaugeWithDifference((Number)scanCounter, null, o);
// If derived gauge is negative it means that the
// counter has wrapped around and the value of the
// threshold needs to be reset to its initial value.
//
if (((Number)o.getDerivedGauge()).longValue() < 0L) {
if (modulus.longValue() > 0L) {
setDerivedGaugeWithDifference((Number)scanCounter,
(Number)modulus, o);
}
o.setThreshold(initThreshold);
o.setEventAlreadyNotified(false);
}
is_derived_gauge_valid = true;
}
// The previous scan counter has not been initialized.
// We cannot update the derived gauge...
//
else {
is_derived_gauge_valid = false;
}
o.setPreviousScanCounter((Number)scanCounter);
}
// The counter difference mode is not used.
//
else {
o.setDerivedGauge((Number)scanCounter);
is_derived_gauge_valid = true;
}
return is_derived_gauge_valid;
|
private synchronized javax.management.monitor.MonitorNotification | updateNotifications(javax.management.monitor.CounterMonitor$CounterMonitorObservedObject o)Updates the notification attribute of the observed object
and notifies the listeners only once if the notify flag
is set to true .
MonitorNotification n = null;
// Send notification if notify is true.
//
if (!o.getEventAlreadyNotified()) {
if (((Number)o.getDerivedGauge()).longValue() >=
o.getThreshold().longValue()) {
if (notify) {
n = new MonitorNotification(THRESHOLD_VALUE_EXCEEDED,
this,
0,
0,
"",
null,
null,
null,
o.getThreshold());
}
if (!differenceMode) {
o.setEventAlreadyNotified(true);
}
}
} else {
if (isTraceOn()) {
trace("updateNotifications", "The notification:" +
"\n\tNotification observed object = " +
o.getObservedObject() +
"\n\tNotification observed attribute = " +
getObservedAttribute() +
"\n\tNotification threshold level = " +
o.getThreshold() +
"\n\tNotification derived gauge = " +
o.getDerivedGauge() +
"\nhas already been sent");
}
}
return n;
|
private synchronized void | updateThreshold(javax.management.monitor.CounterMonitor$CounterMonitorObservedObject o)Updates the threshold attribute of the observed object.
// Calculate the new threshold value if the threshold has been
// exceeded and if the offset value is greater than zero.
//
if (((Number)o.getDerivedGauge()).longValue() >=
o.getThreshold().longValue()) {
if (offset.longValue() > 0L) {
// Increment the threshold until its value is greater
// than the one for the current derived gauge.
//
long threshold_value = o.getThreshold().longValue();
while (((Number)o.getDerivedGauge()).longValue() >=
threshold_value) {
threshold_value += offset.longValue();
}
// Set threshold attribute.
//
switch (o.getType()) {
case INTEGER:
o.setThreshold(new Integer((int)threshold_value));
break;
case BYTE:
o.setThreshold(new Byte((byte)threshold_value));
break;
case SHORT:
o.setThreshold(new Short((short)threshold_value));
break;
case LONG:
o.setThreshold(new Long((long)threshold_value));
break;
default:
// Should never occur...
if (isDebugOn()) {
debug("updateThreshold",
"the threshold type is invalid");
}
break;
}
// If the counter can wrap around when it reaches
// its maximum and we are not dealing with counter
// differences then we need to reset the threshold
// to its initial value too.
//
if (!differenceMode) {
if (modulus.longValue() > 0L) {
if (o.getThreshold().longValue() >
modulus.longValue()) {
o.setModulusExceeded(true);
o.setDerivedGaugeExceeded(
(Number) o.getDerivedGauge());
}
}
}
// Threshold value has been modified so we can notify again.
//
o.setEventAlreadyNotified(false);
} else {
o.setModulusExceeded(true);
o.setDerivedGaugeExceeded((Number) o.getDerivedGauge());
}
}
|