feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
981
jdkSrc/jdk8/javax/management/monitor/CounterMonitor.java
Normal file
981
jdkSrc/jdk8/javax/management/monitor/CounterMonitor.java
Normal file
@@ -0,0 +1,981 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.monitor;
|
||||
|
||||
import static com.sun.jmx.defaults.JmxProperties.MONITOR_LOGGER;
|
||||
import java.util.logging.Level;
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.MBeanNotificationInfo;
|
||||
import static javax.management.monitor.Monitor.NumericalType.*;
|
||||
import static javax.management.monitor.MonitorNotification.*;
|
||||
|
||||
/**
|
||||
* Defines a monitor MBean designed to observe the values of a counter
|
||||
* attribute.
|
||||
*
|
||||
* <P> A counter monitor sends a {@link
|
||||
* MonitorNotification#THRESHOLD_VALUE_EXCEEDED threshold
|
||||
* notification} when the value of the counter reaches or exceeds a
|
||||
* threshold known as the comparison level. The notify flag must be
|
||||
* set to <CODE>true</CODE>.
|
||||
*
|
||||
* <P> 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.
|
||||
*
|
||||
* <P> 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.
|
||||
*
|
||||
* <P> 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:
|
||||
*
|
||||
* <UL>
|
||||
* <LI>if (counter[t] - counter[t-GP]) is positive then
|
||||
* V[t] = counter[t] - counter[t-GP]
|
||||
* <LI>if (counter[t] - counter[t-GP]) is negative then
|
||||
* V[t] = counter[t] - counter[t-GP] + MODULUS
|
||||
* </UL>
|
||||
*
|
||||
* This implementation of the counter monitor requires the observed
|
||||
* attribute to be of the type integer (<CODE>Byte</CODE>,
|
||||
* <CODE>Integer</CODE>, <CODE>Short</CODE>, <CODE>Long</CODE>).
|
||||
*
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class CounterMonitor extends Monitor implements CounterMonitorMBean {
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PACKAGE CLASSES
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
static class CounterMonitorObservedObject extends ObservedObject {
|
||||
|
||||
public CounterMonitorObservedObject(ObjectName observedObject) {
|
||||
super(observedObject);
|
||||
}
|
||||
|
||||
public final synchronized Number getThreshold() {
|
||||
return threshold;
|
||||
}
|
||||
public final synchronized void setThreshold(Number threshold) {
|
||||
this.threshold = threshold;
|
||||
}
|
||||
public final synchronized Number getPreviousScanCounter() {
|
||||
return previousScanCounter;
|
||||
}
|
||||
public final synchronized void setPreviousScanCounter(
|
||||
Number previousScanCounter) {
|
||||
this.previousScanCounter = previousScanCounter;
|
||||
}
|
||||
public final synchronized boolean getModulusExceeded() {
|
||||
return modulusExceeded;
|
||||
}
|
||||
public final synchronized void setModulusExceeded(
|
||||
boolean modulusExceeded) {
|
||||
this.modulusExceeded = modulusExceeded;
|
||||
}
|
||||
public final synchronized Number getDerivedGaugeExceeded() {
|
||||
return derivedGaugeExceeded;
|
||||
}
|
||||
public final synchronized void setDerivedGaugeExceeded(
|
||||
Number derivedGaugeExceeded) {
|
||||
this.derivedGaugeExceeded = derivedGaugeExceeded;
|
||||
}
|
||||
public final synchronized boolean getDerivedGaugeValid() {
|
||||
return derivedGaugeValid;
|
||||
}
|
||||
public final synchronized void setDerivedGaugeValid(
|
||||
boolean derivedGaugeValid) {
|
||||
this.derivedGaugeValid = derivedGaugeValid;
|
||||
}
|
||||
public final synchronized boolean getEventAlreadyNotified() {
|
||||
return eventAlreadyNotified;
|
||||
}
|
||||
public final synchronized void setEventAlreadyNotified(
|
||||
boolean eventAlreadyNotified) {
|
||||
this.eventAlreadyNotified = eventAlreadyNotified;
|
||||
}
|
||||
public final synchronized NumericalType getType() {
|
||||
return type;
|
||||
}
|
||||
public final synchronized void setType(NumericalType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private Number threshold;
|
||||
private Number previousScanCounter;
|
||||
private boolean modulusExceeded;
|
||||
private Number derivedGaugeExceeded;
|
||||
private boolean derivedGaugeValid;
|
||||
private boolean eventAlreadyNotified;
|
||||
private NumericalType type;
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PRIVATE VARIABLES
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Counter modulus.
|
||||
* <BR>The default value is a null Integer object.
|
||||
*/
|
||||
private Number modulus = INTEGER_ZERO;
|
||||
|
||||
/**
|
||||
* Counter offset.
|
||||
* <BR>The default value is a null Integer object.
|
||||
*/
|
||||
private Number offset = INTEGER_ZERO;
|
||||
|
||||
/**
|
||||
* Flag indicating if the counter monitor notifies when exceeding
|
||||
* the threshold. The default value is set to
|
||||
* <CODE>false</CODE>.
|
||||
*/
|
||||
private boolean notify = false;
|
||||
|
||||
/**
|
||||
* Flag indicating if the counter difference mode is used. If the
|
||||
* counter difference mode is used, the derived gauge is the
|
||||
* difference between two consecutive observed values. Otherwise,
|
||||
* the derived gauge is directly the value of the observed
|
||||
* attribute. The default value is set to <CODE>false</CODE>.
|
||||
*/
|
||||
private boolean differenceMode = false;
|
||||
|
||||
/**
|
||||
* Initial counter threshold. This value is used to initialize
|
||||
* the threshold when a new object is added to the list and reset
|
||||
* the threshold to its initial value each time the counter
|
||||
* resets.
|
||||
*/
|
||||
private Number initThreshold = INTEGER_ZERO;
|
||||
|
||||
private static final String[] types = {
|
||||
RUNTIME_ERROR,
|
||||
OBSERVED_OBJECT_ERROR,
|
||||
OBSERVED_ATTRIBUTE_ERROR,
|
||||
OBSERVED_ATTRIBUTE_TYPE_ERROR,
|
||||
THRESHOLD_ERROR,
|
||||
THRESHOLD_VALUE_EXCEEDED
|
||||
};
|
||||
|
||||
private static final MBeanNotificationInfo[] notifsInfo = {
|
||||
new MBeanNotificationInfo(
|
||||
types,
|
||||
"javax.management.monitor.MonitorNotification",
|
||||
"Notifications sent by the CounterMonitor MBean")
|
||||
};
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* CONSTRUCTORS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public CounterMonitor() {
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PUBLIC METHODS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Starts the counter monitor.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the counter monitor.
|
||||
*/
|
||||
public synchronized void stop() {
|
||||
doStop();
|
||||
}
|
||||
|
||||
// GETTERS AND SETTERS
|
||||
//--------------------
|
||||
|
||||
/**
|
||||
* Gets the derived gauge of the specified object, if this object is
|
||||
* contained in the set of observed MBeans, or <code>null</code> otherwise.
|
||||
*
|
||||
* @param object the name of the object whose derived gauge is to
|
||||
* be returned.
|
||||
*
|
||||
* @return The derived gauge of the specified object.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public synchronized Number getDerivedGauge(ObjectName object) {
|
||||
return (Number) super.getDerivedGauge(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the derived gauge timestamp of the specified object, if
|
||||
* this object is contained in the set of observed MBeans, or
|
||||
* <code>0</code> otherwise.
|
||||
*
|
||||
* @param object the name of the object whose derived gauge
|
||||
* timestamp is to be returned.
|
||||
*
|
||||
* @return The derived gauge timestamp of the specified object.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public synchronized long getDerivedGaugeTimeStamp(ObjectName object) {
|
||||
return super.getDerivedGaugeTimeStamp(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current threshold value of the specified object, if
|
||||
* this object is contained in the set of observed MBeans, or
|
||||
* <code>null</code> otherwise.
|
||||
*
|
||||
* @param object the name of the object whose threshold is to be
|
||||
* returned.
|
||||
*
|
||||
* @return The threshold value of the specified object.
|
||||
*
|
||||
*/
|
||||
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 initial threshold value common to all observed objects.
|
||||
*
|
||||
* @return The initial threshold.
|
||||
*
|
||||
* @see #setInitThreshold
|
||||
*
|
||||
*/
|
||||
public synchronized Number getInitThreshold() {
|
||||
return initThreshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the initial threshold value common to all observed objects.
|
||||
*
|
||||
* <BR>The current threshold of every object in the set of
|
||||
* observed MBeans is updated consequently.
|
||||
*
|
||||
* @param value The initial threshold value.
|
||||
*
|
||||
* @exception IllegalArgumentException The specified
|
||||
* threshold is null or the threshold value is less than zero.
|
||||
*
|
||||
* @see #getInitThreshold
|
||||
*
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the derived gauge of the first object in the set of
|
||||
* observed MBeans.
|
||||
*
|
||||
* @return The derived gauge.
|
||||
*
|
||||
* @deprecated As of JMX 1.2, replaced by
|
||||
* {@link #getDerivedGauge(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public synchronized Number getDerivedGauge() {
|
||||
if (observedObjects.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
return (Number) observedObjects.get(0).getDerivedGauge();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the derived gauge timestamp of the first object in the set
|
||||
* of observed MBeans.
|
||||
*
|
||||
* @return The derived gauge timestamp.
|
||||
*
|
||||
* @deprecated As of JMX 1.2, replaced by
|
||||
* {@link #getDerivedGaugeTimeStamp(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public synchronized long getDerivedGaugeTimeStamp() {
|
||||
if (observedObjects.isEmpty()) {
|
||||
return 0;
|
||||
} else {
|
||||
return observedObjects.get(0).getDerivedGaugeTimeStamp();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the threshold value of the first object in the set of
|
||||
* observed MBeans.
|
||||
*
|
||||
* @return The threshold value.
|
||||
*
|
||||
* @see #setThreshold
|
||||
*
|
||||
* @deprecated As of JMX 1.2, replaced by {@link #getThreshold(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public synchronized Number getThreshold() {
|
||||
return getThreshold(getObservedObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the initial threshold value.
|
||||
*
|
||||
* @param value The initial threshold value.
|
||||
*
|
||||
* @exception IllegalArgumentException The specified threshold is
|
||||
* null or the threshold value is less than zero.
|
||||
*
|
||||
* @see #getThreshold()
|
||||
*
|
||||
* @deprecated As of JMX 1.2, replaced by {@link #setInitThreshold}
|
||||
*/
|
||||
@Deprecated
|
||||
public synchronized void setThreshold(Number value)
|
||||
throws IllegalArgumentException {
|
||||
setInitThreshold(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the offset value common to all observed MBeans.
|
||||
*
|
||||
* @return The offset value.
|
||||
*
|
||||
* @see #setOffset
|
||||
*/
|
||||
public synchronized Number getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the offset value common to all observed MBeans.
|
||||
*
|
||||
* @param value The offset value.
|
||||
*
|
||||
* @exception IllegalArgumentException The specified
|
||||
* offset is null or the offset value is less than zero.
|
||||
*
|
||||
* @see #getOffset
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the modulus value common to all observed MBeans.
|
||||
*
|
||||
* @see #setModulus
|
||||
*
|
||||
* @return The modulus value.
|
||||
*/
|
||||
public synchronized Number getModulus() {
|
||||
return modulus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the modulus value common to all observed MBeans.
|
||||
*
|
||||
* @param value The modulus value.
|
||||
*
|
||||
* @exception IllegalArgumentException The specified
|
||||
* modulus is null or the modulus value is less than zero.
|
||||
*
|
||||
* @see #getModulus
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the notification's on/off switch value common to all
|
||||
* observed MBeans.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the counter monitor notifies when
|
||||
* exceeding the threshold, <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setNotify
|
||||
*/
|
||||
public synchronized boolean getNotify() {
|
||||
return notify;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the notification's on/off switch value common to all
|
||||
* observed MBeans.
|
||||
*
|
||||
* @param value The notification's on/off switch value.
|
||||
*
|
||||
* @see #getNotify
|
||||
*/
|
||||
public synchronized void setNotify(boolean value) {
|
||||
if (notify == value)
|
||||
return;
|
||||
notify = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the difference mode flag value common to all observed MBeans.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the difference mode is used,
|
||||
* <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setDifferenceMode
|
||||
*/
|
||||
public synchronized boolean getDifferenceMode() {
|
||||
return differenceMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the difference mode flag value common to all observed MBeans.
|
||||
*
|
||||
* @param value The difference mode flag value.
|
||||
*
|
||||
* @see #getDifferenceMode
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <CODE>NotificationInfo</CODE> object containing the
|
||||
* name of the Java class of the notification and the notification
|
||||
* types sent by the counter monitor.
|
||||
*/
|
||||
@Override
|
||||
public MBeanNotificationInfo[] getNotificationInfo() {
|
||||
return notifsInfo.clone();
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PRIVATE METHODS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Updates the derived gauge attribute of the observed object.
|
||||
*
|
||||
* @param scanCounter The value of the observed attribute.
|
||||
* @param o The observed object.
|
||||
* @return <CODE>true</CODE> if the derived gauge value is valid,
|
||||
* <CODE>false</CODE> otherwise. The derived gauge value is
|
||||
* invalid when the differenceMode flag is set to
|
||||
* <CODE>true</CODE> and it is the first notification (so we
|
||||
* haven't 2 consecutive values to update the derived gauge).
|
||||
*/
|
||||
private synchronized boolean updateDerivedGauge(
|
||||
Object scanCounter, CounterMonitorObservedObject o) {
|
||||
|
||||
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,
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the notification attribute of the observed object
|
||||
* and notifies the listeners only once if the notify flag
|
||||
* is set to <CODE>true</CODE>.
|
||||
* @param o The observed object.
|
||||
*/
|
||||
private synchronized MonitorNotification updateNotifications(
|
||||
CounterMonitorObservedObject o) {
|
||||
|
||||
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 (MONITOR_LOGGER.isLoggable(Level.FINER)) {
|
||||
final StringBuilder strb = new StringBuilder()
|
||||
.append("The notification:")
|
||||
.append("\n\tNotification observed object = ")
|
||||
.append(o.getObservedObject())
|
||||
.append("\n\tNotification observed attribute = ")
|
||||
.append(getObservedAttribute())
|
||||
.append("\n\tNotification threshold level = ")
|
||||
.append(o.getThreshold())
|
||||
.append("\n\tNotification derived gauge = ")
|
||||
.append(o.getDerivedGauge())
|
||||
.append("\nhas already been sent");
|
||||
MONITOR_LOGGER.logp(Level.FINER, CounterMonitor.class.getName(),
|
||||
"updateNotifications", strb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the threshold attribute of the observed object.
|
||||
* @param o The observed object.
|
||||
*/
|
||||
private synchronized void updateThreshold(CounterMonitorObservedObject o) {
|
||||
|
||||
// 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(Integer.valueOf((int)threshold_value));
|
||||
break;
|
||||
case BYTE:
|
||||
o.setThreshold(Byte.valueOf((byte)threshold_value));
|
||||
break;
|
||||
case SHORT:
|
||||
o.setThreshold(Short.valueOf((short)threshold_value));
|
||||
break;
|
||||
case LONG:
|
||||
o.setThreshold(Long.valueOf(threshold_value));
|
||||
break;
|
||||
default:
|
||||
// Should never occur...
|
||||
MONITOR_LOGGER.logp(Level.FINEST,
|
||||
CounterMonitor.class.getName(),
|
||||
"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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the derived gauge of the specified observed object when the
|
||||
* differenceMode flag is set to <CODE>true</CODE>. Integer types
|
||||
* only are allowed.
|
||||
*
|
||||
* @param scanCounter The value of the observed attribute.
|
||||
* @param mod The counter modulus value.
|
||||
* @param o The observed object.
|
||||
*/
|
||||
private synchronized void setDerivedGaugeWithDifference(
|
||||
Number scanCounter, Number mod, CounterMonitorObservedObject o) {
|
||||
/* 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(Integer.valueOf((int) derived)); break;
|
||||
case BYTE: o.setDerivedGauge(Byte.valueOf((byte) derived)); break;
|
||||
case SHORT: o.setDerivedGauge(Short.valueOf((short) derived)); break;
|
||||
case LONG: o.setDerivedGauge(Long.valueOf(derived)); break;
|
||||
default:
|
||||
// Should never occur...
|
||||
MONITOR_LOGGER.logp(Level.FINEST, CounterMonitor.class.getName(),
|
||||
"setDerivedGaugeWithDifference",
|
||||
"the threshold type is invalid");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PACKAGE METHODS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Factory method for ObservedObject creation.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
@Override
|
||||
ObservedObject createObservedObject(ObjectName object) {
|
||||
final CounterMonitorObservedObject cmo =
|
||||
new CounterMonitorObservedObject(object);
|
||||
cmo.setThreshold(initThreshold);
|
||||
cmo.setModulusExceeded(false);
|
||||
cmo.setEventAlreadyNotified(false);
|
||||
cmo.setPreviousScanCounter(null);
|
||||
return cmo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param object The observed object.
|
||||
* @param attribute The observed attribute.
|
||||
* @param value The sample value.
|
||||
* @return <CODE>true</CODE> if type is the same,
|
||||
* <CODE>false</CODE> otherwise.
|
||||
*/
|
||||
@Override
|
||||
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));
|
||||
}
|
||||
}
|
||||
216
jdkSrc/jdk8/javax/management/monitor/CounterMonitorMBean.java
Normal file
216
jdkSrc/jdk8/javax/management/monitor/CounterMonitorMBean.java
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.monitor;
|
||||
|
||||
// jmx imports
|
||||
//
|
||||
import javax.management.ObjectName;
|
||||
|
||||
/**
|
||||
* Exposes the remote management interface of the counter monitor MBean.
|
||||
*
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface CounterMonitorMBean extends MonitorMBean {
|
||||
|
||||
// GETTERS AND SETTERS
|
||||
//--------------------
|
||||
|
||||
/**
|
||||
* Gets the derived gauge.
|
||||
*
|
||||
* @return The derived gauge.
|
||||
* @deprecated As of JMX 1.2, replaced by {@link #getDerivedGauge(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Number getDerivedGauge();
|
||||
|
||||
/**
|
||||
* Gets the derived gauge timestamp.
|
||||
*
|
||||
* @return The derived gauge timestamp.
|
||||
* @deprecated As of JMX 1.2, replaced by {@link #getDerivedGaugeTimeStamp(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public long getDerivedGaugeTimeStamp();
|
||||
|
||||
/**
|
||||
* Gets the threshold value.
|
||||
*
|
||||
* @return The threshold value.
|
||||
*
|
||||
* @see #setThreshold(Number)
|
||||
*
|
||||
* @deprecated As of JMX 1.2, replaced by {@link #getThreshold(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Number getThreshold();
|
||||
|
||||
/**
|
||||
* Sets the threshold value.
|
||||
*
|
||||
* @see #getThreshold()
|
||||
*
|
||||
* @param value The threshold value.
|
||||
* @exception java.lang.IllegalArgumentException The specified threshold is null or the threshold value is less than zero.
|
||||
* @deprecated As of JMX 1.2, replaced by {@link #setInitThreshold}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setThreshold(Number value) throws java.lang.IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Gets the derived gauge for the specified MBean.
|
||||
*
|
||||
* @param object the MBean for which the derived gauge is to be returned
|
||||
* @return The derived gauge for the specified MBean if this MBean is in the
|
||||
* set of observed MBeans, or <code>null</code> otherwise.
|
||||
*
|
||||
*/
|
||||
public Number getDerivedGauge(ObjectName object);
|
||||
|
||||
/**
|
||||
* Gets the derived gauge timestamp for the specified MBean.
|
||||
*
|
||||
* @param object the MBean for which the derived gauge timestamp is to be returned
|
||||
* @return The derived gauge timestamp for the specified MBean if this MBean
|
||||
* is in the set of observed MBeans, or <code>null</code> otherwise.
|
||||
*
|
||||
*/
|
||||
public long getDerivedGaugeTimeStamp(ObjectName object);
|
||||
|
||||
/**
|
||||
* Gets the threshold value for the specified MBean.
|
||||
*
|
||||
* @param object the MBean for which the threshold value is to be returned
|
||||
* @return The threshold value for the specified MBean if this MBean
|
||||
* is in the set of observed MBeans, or <code>null</code> otherwise.
|
||||
*
|
||||
* @see #setThreshold
|
||||
*
|
||||
*/
|
||||
public Number getThreshold(ObjectName object);
|
||||
|
||||
/**
|
||||
* Gets the initial threshold value common to all observed objects.
|
||||
*
|
||||
* @return The initial threshold value.
|
||||
*
|
||||
* @see #setInitThreshold
|
||||
*
|
||||
*/
|
||||
public Number getInitThreshold();
|
||||
|
||||
/**
|
||||
* Sets the initial threshold value common to all observed MBeans.
|
||||
*
|
||||
* @param value The initial threshold value.
|
||||
* @exception java.lang.IllegalArgumentException The specified
|
||||
* threshold is null or the threshold value is less than zero.
|
||||
*
|
||||
* @see #getInitThreshold
|
||||
*
|
||||
*/
|
||||
public void setInitThreshold(Number value) throws java.lang.IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Gets the offset value.
|
||||
*
|
||||
* @see #setOffset(Number)
|
||||
*
|
||||
* @return The offset value.
|
||||
*/
|
||||
public Number getOffset();
|
||||
|
||||
/**
|
||||
* Sets the offset value.
|
||||
*
|
||||
* @param value The offset value.
|
||||
* @exception java.lang.IllegalArgumentException The specified
|
||||
* offset is null or the offset value is less than zero.
|
||||
*
|
||||
* @see #getOffset()
|
||||
*/
|
||||
public void setOffset(Number value) throws java.lang.IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Gets the modulus value.
|
||||
*
|
||||
* @return The modulus value.
|
||||
*
|
||||
* @see #setModulus
|
||||
*/
|
||||
public Number getModulus();
|
||||
|
||||
/**
|
||||
* Sets the modulus value.
|
||||
*
|
||||
* @param value The modulus value.
|
||||
* @exception java.lang.IllegalArgumentException The specified
|
||||
* modulus is null or the modulus value is less than zero.
|
||||
*
|
||||
* @see #getModulus
|
||||
*/
|
||||
public void setModulus(Number value) throws java.lang.IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Gets the notification's on/off switch value.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the counter monitor notifies when
|
||||
* exceeding the threshold, <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setNotify
|
||||
*/
|
||||
public boolean getNotify();
|
||||
|
||||
/**
|
||||
* Sets the notification's on/off switch value.
|
||||
*
|
||||
* @param value The notification's on/off switch value.
|
||||
*
|
||||
* @see #getNotify
|
||||
*/
|
||||
public void setNotify(boolean value);
|
||||
|
||||
/**
|
||||
* Gets the difference mode flag value.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the difference mode is used,
|
||||
* <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setDifferenceMode
|
||||
*/
|
||||
public boolean getDifferenceMode();
|
||||
|
||||
/**
|
||||
* Sets the difference mode flag value.
|
||||
*
|
||||
* @param value The difference mode flag value.
|
||||
*
|
||||
* @see #getDifferenceMode
|
||||
*/
|
||||
public void setDifferenceMode(boolean value);
|
||||
}
|
||||
884
jdkSrc/jdk8/javax/management/monitor/GaugeMonitor.java
Normal file
884
jdkSrc/jdk8/javax/management/monitor/GaugeMonitor.java
Normal file
@@ -0,0 +1,884 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.monitor;
|
||||
|
||||
import static com.sun.jmx.defaults.JmxProperties.MONITOR_LOGGER;
|
||||
import java.util.logging.Level;
|
||||
import javax.management.MBeanNotificationInfo;
|
||||
import javax.management.ObjectName;
|
||||
import static javax.management.monitor.Monitor.NumericalType.*;
|
||||
import static javax.management.monitor.MonitorNotification.*;
|
||||
|
||||
/**
|
||||
* Defines a monitor MBean designed to observe the values of a gauge attribute.
|
||||
*
|
||||
* <P> A gauge monitor observes an attribute that is continuously
|
||||
* variable with time. A gauge monitor sends notifications as
|
||||
* follows:
|
||||
*
|
||||
* <UL>
|
||||
*
|
||||
* <LI> if the attribute value is increasing and becomes equal to or
|
||||
* greater than the high threshold value, a {@link
|
||||
* MonitorNotification#THRESHOLD_HIGH_VALUE_EXCEEDED threshold high
|
||||
* notification} is sent. The notify high flag must be set to
|
||||
* <CODE>true</CODE>.
|
||||
*
|
||||
* <BR>Subsequent crossings of the high threshold value do not cause
|
||||
* further notifications unless the attribute value becomes equal to
|
||||
* or less than the low threshold value.</LI>
|
||||
*
|
||||
* <LI> if the attribute value is decreasing and becomes equal to or
|
||||
* less than the low threshold value, a {@link
|
||||
* MonitorNotification#THRESHOLD_LOW_VALUE_EXCEEDED threshold low
|
||||
* notification} is sent. The notify low flag must be set to
|
||||
* <CODE>true</CODE>.
|
||||
*
|
||||
* <BR>Subsequent crossings of the low threshold value do not cause
|
||||
* further notifications unless the attribute value becomes equal to
|
||||
* or greater than the high threshold value.</LI>
|
||||
*
|
||||
* </UL>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* <P> 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.
|
||||
*
|
||||
* <BR>The derived gauge value (V[t]) is calculated using the following method:
|
||||
* <UL>
|
||||
* <LI>V[t] = gauge[t] - gauge[t-GP]</LI>
|
||||
* </UL>
|
||||
*
|
||||
* This implementation of the gauge monitor requires the observed
|
||||
* attribute to be of the type integer or floating-point
|
||||
* (<CODE>Byte</CODE>, <CODE>Integer</CODE>, <CODE>Short</CODE>,
|
||||
* <CODE>Long</CODE>, <CODE>Float</CODE>, <CODE>Double</CODE>).
|
||||
*
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class GaugeMonitor extends Monitor implements GaugeMonitorMBean {
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PACKAGE CLASSES
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
static class GaugeMonitorObservedObject extends ObservedObject {
|
||||
|
||||
public GaugeMonitorObservedObject(ObjectName observedObject) {
|
||||
super(observedObject);
|
||||
}
|
||||
|
||||
public final synchronized boolean getDerivedGaugeValid() {
|
||||
return derivedGaugeValid;
|
||||
}
|
||||
public final synchronized void setDerivedGaugeValid(
|
||||
boolean derivedGaugeValid) {
|
||||
this.derivedGaugeValid = derivedGaugeValid;
|
||||
}
|
||||
public final synchronized NumericalType getType() {
|
||||
return type;
|
||||
}
|
||||
public final synchronized void setType(NumericalType type) {
|
||||
this.type = type;
|
||||
}
|
||||
public final synchronized Number getPreviousScanGauge() {
|
||||
return previousScanGauge;
|
||||
}
|
||||
public final synchronized void setPreviousScanGauge(
|
||||
Number previousScanGauge) {
|
||||
this.previousScanGauge = previousScanGauge;
|
||||
}
|
||||
public final synchronized int getStatus() {
|
||||
return status;
|
||||
}
|
||||
public final synchronized void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
private boolean derivedGaugeValid;
|
||||
private NumericalType type;
|
||||
private Number previousScanGauge;
|
||||
private int status;
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PRIVATE VARIABLES
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gauge high threshold.
|
||||
*
|
||||
* <BR>The default value is a null Integer object.
|
||||
*/
|
||||
private Number highThreshold = INTEGER_ZERO;
|
||||
|
||||
/**
|
||||
* Gauge low threshold.
|
||||
*
|
||||
* <BR>The default value is a null Integer object.
|
||||
*/
|
||||
private Number lowThreshold = INTEGER_ZERO;
|
||||
|
||||
/**
|
||||
* Flag indicating if the gauge monitor notifies when exceeding
|
||||
* the high threshold.
|
||||
*
|
||||
* <BR>The default value is <CODE>false</CODE>.
|
||||
*/
|
||||
private boolean notifyHigh = false;
|
||||
|
||||
/**
|
||||
* Flag indicating if the gauge monitor notifies when exceeding
|
||||
* the low threshold.
|
||||
*
|
||||
* <BR>The default value is <CODE>false</CODE>.
|
||||
*/
|
||||
private boolean notifyLow = false;
|
||||
|
||||
/**
|
||||
* Flag indicating if the gauge difference mode is used. If the
|
||||
* gauge difference mode is used, the derived gauge is the
|
||||
* difference between two consecutive observed values. Otherwise,
|
||||
* the derived gauge is directly the value of the observed
|
||||
* attribute.
|
||||
*
|
||||
* <BR>The default value is set to <CODE>false</CODE>.
|
||||
*/
|
||||
private boolean differenceMode = false;
|
||||
|
||||
private static final String[] types = {
|
||||
RUNTIME_ERROR,
|
||||
OBSERVED_OBJECT_ERROR,
|
||||
OBSERVED_ATTRIBUTE_ERROR,
|
||||
OBSERVED_ATTRIBUTE_TYPE_ERROR,
|
||||
THRESHOLD_ERROR,
|
||||
THRESHOLD_HIGH_VALUE_EXCEEDED,
|
||||
THRESHOLD_LOW_VALUE_EXCEEDED
|
||||
};
|
||||
|
||||
private static final MBeanNotificationInfo[] notifsInfo = {
|
||||
new MBeanNotificationInfo(
|
||||
types,
|
||||
"javax.management.monitor.MonitorNotification",
|
||||
"Notifications sent by the GaugeMonitor MBean")
|
||||
};
|
||||
|
||||
// Flags needed to implement the hysteresis mechanism.
|
||||
//
|
||||
private static final int RISING = 0;
|
||||
private static final int FALLING = 1;
|
||||
private static final int RISING_OR_FALLING = 2;
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* CONSTRUCTORS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public GaugeMonitor() {
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PUBLIC METHODS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Starts the gauge monitor.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the gauge monitor.
|
||||
*/
|
||||
public synchronized void stop() {
|
||||
doStop();
|
||||
}
|
||||
|
||||
// GETTERS AND SETTERS
|
||||
//--------------------
|
||||
|
||||
/**
|
||||
* Gets the derived gauge of the specified object, if this object is
|
||||
* contained in the set of observed MBeans, or <code>null</code> otherwise.
|
||||
*
|
||||
* @param object the name of the MBean.
|
||||
*
|
||||
* @return The derived gauge of the specified object.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public synchronized Number getDerivedGauge(ObjectName object) {
|
||||
return (Number) super.getDerivedGauge(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the derived gauge timestamp of the specified object, if
|
||||
* this object is contained in the set of observed MBeans, or
|
||||
* <code>0</code> otherwise.
|
||||
*
|
||||
* @param object the name of the object whose derived gauge
|
||||
* timestamp is to be returned.
|
||||
*
|
||||
* @return The derived gauge timestamp of the specified object.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public synchronized long getDerivedGaugeTimeStamp(ObjectName object) {
|
||||
return super.getDerivedGaugeTimeStamp(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the derived gauge of the first object in the set of
|
||||
* observed MBeans.
|
||||
*
|
||||
* @return The derived gauge.
|
||||
*
|
||||
* @deprecated As of JMX 1.2, replaced by
|
||||
* {@link #getDerivedGauge(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public synchronized Number getDerivedGauge() {
|
||||
if (observedObjects.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
return (Number) observedObjects.get(0).getDerivedGauge();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the derived gauge timestamp of the first object in the set
|
||||
* of observed MBeans.
|
||||
*
|
||||
* @return The derived gauge timestamp.
|
||||
*
|
||||
* @deprecated As of JMX 1.2, replaced by
|
||||
* {@link #getDerivedGaugeTimeStamp(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public synchronized long getDerivedGaugeTimeStamp() {
|
||||
if (observedObjects.isEmpty()) {
|
||||
return 0;
|
||||
} else {
|
||||
return observedObjects.get(0).getDerivedGaugeTimeStamp();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the high threshold value common to all observed MBeans.
|
||||
*
|
||||
* @return The high threshold value.
|
||||
*
|
||||
* @see #setThresholds
|
||||
*/
|
||||
public synchronized Number getHighThreshold() {
|
||||
return highThreshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the low threshold value common to all observed MBeans.
|
||||
*
|
||||
* @return The low threshold value.
|
||||
*
|
||||
* @see #setThresholds
|
||||
*/
|
||||
public synchronized Number getLowThreshold() {
|
||||
return lowThreshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the high and the low threshold values common to all
|
||||
* observed MBeans.
|
||||
*
|
||||
* @param highValue The high threshold value.
|
||||
* @param lowValue The low threshold value.
|
||||
*
|
||||
* @exception IllegalArgumentException The specified high/low
|
||||
* threshold is null or the low threshold is greater than the high
|
||||
* threshold or the high threshold and the low threshold are not
|
||||
* of the same type.
|
||||
*
|
||||
* @see #getHighThreshold
|
||||
* @see #getLowThreshold
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the high notification's on/off switch value common to all
|
||||
* observed MBeans.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the gauge monitor notifies when
|
||||
* exceeding the high threshold, <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setNotifyHigh
|
||||
*/
|
||||
public synchronized boolean getNotifyHigh() {
|
||||
return notifyHigh;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the high notification's on/off switch value common to all
|
||||
* observed MBeans.
|
||||
*
|
||||
* @param value The high notification's on/off switch value.
|
||||
*
|
||||
* @see #getNotifyHigh
|
||||
*/
|
||||
public synchronized void setNotifyHigh(boolean value) {
|
||||
if (notifyHigh == value)
|
||||
return;
|
||||
notifyHigh = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the low notification's on/off switch value common to all
|
||||
* observed MBeans.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the gauge monitor notifies when
|
||||
* exceeding the low threshold, <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setNotifyLow
|
||||
*/
|
||||
public synchronized boolean getNotifyLow() {
|
||||
return notifyLow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the low notification's on/off switch value common to all
|
||||
* observed MBeans.
|
||||
*
|
||||
* @param value The low notification's on/off switch value.
|
||||
*
|
||||
* @see #getNotifyLow
|
||||
*/
|
||||
public synchronized void setNotifyLow(boolean value) {
|
||||
if (notifyLow == value)
|
||||
return;
|
||||
notifyLow = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the difference mode flag value common to all observed MBeans.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the difference mode is used,
|
||||
* <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setDifferenceMode
|
||||
*/
|
||||
public synchronized boolean getDifferenceMode() {
|
||||
return differenceMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the difference mode flag value common to all observed MBeans.
|
||||
*
|
||||
* @param value The difference mode flag value.
|
||||
*
|
||||
* @see #getDifferenceMode
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <CODE>NotificationInfo</CODE> object containing the
|
||||
* name of the Java class of the notification and the notification
|
||||
* types sent by the gauge monitor.
|
||||
*/
|
||||
@Override
|
||||
public MBeanNotificationInfo[] getNotificationInfo() {
|
||||
return notifsInfo.clone();
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PRIVATE METHODS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Updates the derived gauge attribute of the observed object.
|
||||
*
|
||||
* @param scanGauge The value of the observed attribute.
|
||||
* @param o The observed object.
|
||||
* @return <CODE>true</CODE> if the derived gauge value is valid,
|
||||
* <CODE>false</CODE> otherwise. The derived gauge value is
|
||||
* invalid when the differenceMode flag is set to
|
||||
* <CODE>true</CODE> and it is the first notification (so we
|
||||
* haven't 2 consecutive values to update the derived gauge).
|
||||
*/
|
||||
private synchronized boolean updateDerivedGauge(
|
||||
Object scanGauge, GaugeMonitorObservedObject o) {
|
||||
|
||||
boolean is_derived_gauge_valid;
|
||||
|
||||
// The gauge difference mode is used.
|
||||
//
|
||||
if (differenceMode) {
|
||||
|
||||
// The previous scan gauge has been initialized.
|
||||
//
|
||||
if (o.getPreviousScanGauge() != null) {
|
||||
setDerivedGaugeWithDifference((Number)scanGauge, o);
|
||||
is_derived_gauge_valid = true;
|
||||
}
|
||||
// The previous scan gauge has not been initialized.
|
||||
// We cannot update the derived gauge...
|
||||
//
|
||||
else {
|
||||
is_derived_gauge_valid = false;
|
||||
}
|
||||
o.setPreviousScanGauge((Number)scanGauge);
|
||||
}
|
||||
// The gauge difference mode is not used.
|
||||
//
|
||||
else {
|
||||
o.setDerivedGauge((Number)scanGauge);
|
||||
is_derived_gauge_valid = true;
|
||||
}
|
||||
|
||||
return is_derived_gauge_valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the notification attribute of the observed object
|
||||
* and notifies the listeners only once if the notify flag
|
||||
* is set to <CODE>true</CODE>.
|
||||
* @param o The observed object.
|
||||
*/
|
||||
private synchronized MonitorNotification updateNotifications(
|
||||
GaugeMonitorObservedObject o) {
|
||||
|
||||
MonitorNotification n = null;
|
||||
|
||||
// Send high notification if notifyHigh is true.
|
||||
// Send low notification if notifyLow is true.
|
||||
//
|
||||
if (o.getStatus() == RISING_OR_FALLING) {
|
||||
if (isFirstGreaterThanLast((Number)o.getDerivedGauge(),
|
||||
highThreshold,
|
||||
o.getType())) {
|
||||
if (notifyHigh) {
|
||||
n = new MonitorNotification(
|
||||
THRESHOLD_HIGH_VALUE_EXCEEDED,
|
||||
this,
|
||||
0,
|
||||
0,
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
highThreshold);
|
||||
}
|
||||
o.setStatus(FALLING);
|
||||
} else if (isFirstGreaterThanLast(lowThreshold,
|
||||
(Number)o.getDerivedGauge(),
|
||||
o.getType())) {
|
||||
if (notifyLow) {
|
||||
n = new MonitorNotification(
|
||||
THRESHOLD_LOW_VALUE_EXCEEDED,
|
||||
this,
|
||||
0,
|
||||
0,
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
lowThreshold);
|
||||
}
|
||||
o.setStatus(RISING);
|
||||
}
|
||||
} else {
|
||||
if (o.getStatus() == RISING) {
|
||||
if (isFirstGreaterThanLast((Number)o.getDerivedGauge(),
|
||||
highThreshold,
|
||||
o.getType())) {
|
||||
if (notifyHigh) {
|
||||
n = new MonitorNotification(
|
||||
THRESHOLD_HIGH_VALUE_EXCEEDED,
|
||||
this,
|
||||
0,
|
||||
0,
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
highThreshold);
|
||||
}
|
||||
o.setStatus(FALLING);
|
||||
}
|
||||
} else if (o.getStatus() == FALLING) {
|
||||
if (isFirstGreaterThanLast(lowThreshold,
|
||||
(Number)o.getDerivedGauge(),
|
||||
o.getType())) {
|
||||
if (notifyLow) {
|
||||
n = new MonitorNotification(
|
||||
THRESHOLD_LOW_VALUE_EXCEEDED,
|
||||
this,
|
||||
0,
|
||||
0,
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
lowThreshold);
|
||||
}
|
||||
o.setStatus(RISING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the derived gauge when the differenceMode flag is set to
|
||||
* <CODE>true</CODE>. Both integer and floating-point types are
|
||||
* allowed.
|
||||
*
|
||||
* @param scanGauge The value of the observed attribute.
|
||||
* @param o The observed object.
|
||||
*/
|
||||
private synchronized void setDerivedGaugeWithDifference(
|
||||
Number scanGauge, GaugeMonitorObservedObject o) {
|
||||
Number prev = o.getPreviousScanGauge();
|
||||
Number der;
|
||||
switch (o.getType()) {
|
||||
case INTEGER:
|
||||
der = Integer.valueOf(((Integer)scanGauge).intValue() -
|
||||
((Integer)prev).intValue());
|
||||
break;
|
||||
case BYTE:
|
||||
der = Byte.valueOf((byte)(((Byte)scanGauge).byteValue() -
|
||||
((Byte)prev).byteValue()));
|
||||
break;
|
||||
case SHORT:
|
||||
der = Short.valueOf((short)(((Short)scanGauge).shortValue() -
|
||||
((Short)prev).shortValue()));
|
||||
break;
|
||||
case LONG:
|
||||
der = Long.valueOf(((Long)scanGauge).longValue() -
|
||||
((Long)prev).longValue());
|
||||
break;
|
||||
case FLOAT:
|
||||
der = Float.valueOf(((Float)scanGauge).floatValue() -
|
||||
((Float)prev).floatValue());
|
||||
break;
|
||||
case DOUBLE:
|
||||
der = Double.valueOf(((Double)scanGauge).doubleValue() -
|
||||
((Double)prev).doubleValue());
|
||||
break;
|
||||
default:
|
||||
// Should never occur...
|
||||
MONITOR_LOGGER.logp(Level.FINEST, GaugeMonitor.class.getName(),
|
||||
"setDerivedGaugeWithDifference",
|
||||
"the threshold type is invalid");
|
||||
return;
|
||||
}
|
||||
o.setDerivedGauge(der);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the first specified Number is greater than or equal to
|
||||
* the last. Both integer and floating-point types are allowed.
|
||||
*
|
||||
* @param greater The first Number to compare with the second.
|
||||
* @param less The second Number to compare with the first.
|
||||
* @param type The number type.
|
||||
* @return <CODE>true</CODE> if the first specified Number is
|
||||
* greater than or equal to the last, <CODE>false</CODE>
|
||||
* otherwise.
|
||||
*/
|
||||
private boolean isFirstGreaterThanLast(Number greater,
|
||||
Number less,
|
||||
NumericalType type) {
|
||||
|
||||
switch (type) {
|
||||
case INTEGER:
|
||||
case BYTE:
|
||||
case SHORT:
|
||||
case LONG:
|
||||
return (greater.longValue() >= less.longValue());
|
||||
case FLOAT:
|
||||
case DOUBLE:
|
||||
return (greater.doubleValue() >= less.doubleValue());
|
||||
default:
|
||||
// Should never occur...
|
||||
MONITOR_LOGGER.logp(Level.FINEST, GaugeMonitor.class.getName(),
|
||||
"isFirstGreaterThanLast",
|
||||
"the threshold type is invalid");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the first specified Number is strictly greater than the last.
|
||||
* Both integer and floating-point types are allowed.
|
||||
*
|
||||
* @param greater The first Number to compare with the second.
|
||||
* @param less The second Number to compare with the first.
|
||||
* @param className The number class name.
|
||||
* @return <CODE>true</CODE> if the first specified Number is
|
||||
* strictly greater than the last, <CODE>false</CODE> otherwise.
|
||||
*/
|
||||
private boolean isFirstStrictlyGreaterThanLast(Number greater,
|
||||
Number less,
|
||||
String className) {
|
||||
|
||||
if (className.equals("java.lang.Integer") ||
|
||||
className.equals("java.lang.Byte") ||
|
||||
className.equals("java.lang.Short") ||
|
||||
className.equals("java.lang.Long")) {
|
||||
|
||||
return (greater.longValue() > less.longValue());
|
||||
}
|
||||
else if (className.equals("java.lang.Float") ||
|
||||
className.equals("java.lang.Double")) {
|
||||
|
||||
return (greater.doubleValue() > less.doubleValue());
|
||||
}
|
||||
else {
|
||||
// Should never occur...
|
||||
MONITOR_LOGGER.logp(Level.FINEST, GaugeMonitor.class.getName(),
|
||||
"isFirstStrictlyGreaterThanLast",
|
||||
"the threshold type is invalid");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PACKAGE METHODS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Factory method for ObservedObject creation.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
@Override
|
||||
ObservedObject createObservedObject(ObjectName object) {
|
||||
final GaugeMonitorObservedObject gmo =
|
||||
new GaugeMonitorObservedObject(object);
|
||||
gmo.setStatus(RISING_OR_FALLING);
|
||||
gmo.setPreviousScanGauge(null);
|
||||
return gmo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param object The observed object.
|
||||
* @param attribute The observed attribute.
|
||||
* @param value The sample value.
|
||||
* @return <CODE>true</CODE> if type is the same,
|
||||
* <CODE>false</CODE> otherwise.
|
||||
*/
|
||||
@Override
|
||||
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));
|
||||
}
|
||||
}
|
||||
162
jdkSrc/jdk8/javax/management/monitor/GaugeMonitorMBean.java
Normal file
162
jdkSrc/jdk8/javax/management/monitor/GaugeMonitorMBean.java
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.monitor;
|
||||
|
||||
// jmx imports
|
||||
//
|
||||
import javax.management.ObjectName;
|
||||
|
||||
/**
|
||||
* Exposes the remote management interface of the gauge monitor MBean.
|
||||
*
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface GaugeMonitorMBean extends MonitorMBean {
|
||||
|
||||
// GETTERS AND SETTERS
|
||||
//--------------------
|
||||
|
||||
/**
|
||||
* Gets the derived gauge.
|
||||
*
|
||||
* @return The derived gauge.
|
||||
* @deprecated As of JMX 1.2, replaced by {@link #getDerivedGauge(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Number getDerivedGauge();
|
||||
|
||||
/**
|
||||
* Gets the derived gauge timestamp.
|
||||
*
|
||||
* @return The derived gauge timestamp.
|
||||
* @deprecated As of JMX 1.2, replaced by {@link #getDerivedGaugeTimeStamp(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public long getDerivedGaugeTimeStamp();
|
||||
|
||||
/**
|
||||
* Gets the derived gauge for the specified MBean.
|
||||
*
|
||||
* @param object the MBean for which the derived gauge is to be returned
|
||||
* @return The derived gauge for the specified MBean if this MBean is in the
|
||||
* set of observed MBeans, or <code>null</code> otherwise.
|
||||
*
|
||||
*/
|
||||
public Number getDerivedGauge(ObjectName object);
|
||||
|
||||
/**
|
||||
* Gets the derived gauge timestamp for the specified MBean.
|
||||
*
|
||||
* @param object the MBean for which the derived gauge timestamp is to be returned
|
||||
* @return The derived gauge timestamp for the specified MBean if this MBean
|
||||
* is in the set of observed MBeans, or <code>null</code> otherwise.
|
||||
*
|
||||
*/
|
||||
public long getDerivedGaugeTimeStamp(ObjectName object);
|
||||
|
||||
/**
|
||||
* Gets the high threshold value.
|
||||
*
|
||||
* @return The high threshold value.
|
||||
*/
|
||||
public Number getHighThreshold();
|
||||
|
||||
/**
|
||||
* Gets the low threshold value.
|
||||
*
|
||||
* @return The low threshold value.
|
||||
*/
|
||||
public Number getLowThreshold();
|
||||
|
||||
/**
|
||||
* Sets the high and the low threshold values.
|
||||
*
|
||||
* @param highValue The high threshold value.
|
||||
* @param lowValue The low threshold value.
|
||||
* @exception java.lang.IllegalArgumentException The specified high/low threshold is null
|
||||
* or the low threshold is greater than the high threshold
|
||||
* or the high threshold and the low threshold are not of the same type.
|
||||
*/
|
||||
public void setThresholds(Number highValue, Number lowValue) throws java.lang.IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Gets the high notification's on/off switch value.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the gauge monitor notifies when
|
||||
* exceeding the high threshold, <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setNotifyHigh
|
||||
*/
|
||||
public boolean getNotifyHigh();
|
||||
|
||||
/**
|
||||
* Sets the high notification's on/off switch value.
|
||||
*
|
||||
* @param value The high notification's on/off switch value.
|
||||
*
|
||||
* @see #getNotifyHigh
|
||||
*/
|
||||
public void setNotifyHigh(boolean value);
|
||||
|
||||
/**
|
||||
* Gets the low notification's on/off switch value.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the gauge monitor notifies when
|
||||
* exceeding the low threshold, <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setNotifyLow
|
||||
*/
|
||||
public boolean getNotifyLow();
|
||||
|
||||
/**
|
||||
* Sets the low notification's on/off switch value.
|
||||
*
|
||||
* @param value The low notification's on/off switch value.
|
||||
*
|
||||
* @see #getNotifyLow
|
||||
*/
|
||||
public void setNotifyLow(boolean value);
|
||||
|
||||
/**
|
||||
* Gets the difference mode flag value.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the difference mode is used,
|
||||
* <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setDifferenceMode
|
||||
*/
|
||||
public boolean getDifferenceMode();
|
||||
|
||||
/**
|
||||
* Sets the difference mode flag value.
|
||||
*
|
||||
* @param value The difference mode flag value.
|
||||
*
|
||||
* @see #getDifferenceMode
|
||||
*/
|
||||
public void setDifferenceMode(boolean value);
|
||||
}
|
||||
1651
jdkSrc/jdk8/javax/management/monitor/Monitor.java
Normal file
1651
jdkSrc/jdk8/javax/management/monitor/Monitor.java
Normal file
File diff suppressed because it is too large
Load Diff
157
jdkSrc/jdk8/javax/management/monitor/MonitorMBean.java
Normal file
157
jdkSrc/jdk8/javax/management/monitor/MonitorMBean.java
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.monitor;
|
||||
|
||||
// jmx imports
|
||||
//
|
||||
import javax.management.ObjectName;
|
||||
|
||||
/**
|
||||
* Exposes the remote management interface of monitor MBeans.
|
||||
*
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface MonitorMBean {
|
||||
|
||||
/**
|
||||
* Starts the monitor.
|
||||
*/
|
||||
public void start();
|
||||
|
||||
/**
|
||||
* Stops the monitor.
|
||||
*/
|
||||
public void stop();
|
||||
|
||||
// GETTERS AND SETTERS
|
||||
//--------------------
|
||||
|
||||
/**
|
||||
* Adds the specified object in the set of observed MBeans.
|
||||
*
|
||||
* @param object The object to observe.
|
||||
* @exception java.lang.IllegalArgumentException the specified object is null.
|
||||
*
|
||||
*/
|
||||
public void addObservedObject(ObjectName object) throws java.lang.IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Removes the specified object from the set of observed MBeans.
|
||||
*
|
||||
* @param object The object to remove.
|
||||
*
|
||||
*/
|
||||
public void removeObservedObject(ObjectName object);
|
||||
|
||||
/**
|
||||
* Tests whether the specified object is in the set of observed MBeans.
|
||||
*
|
||||
* @param object The object to check.
|
||||
* @return <CODE>true</CODE> if the specified object is in the set, <CODE>false</CODE> otherwise.
|
||||
*
|
||||
*/
|
||||
public boolean containsObservedObject(ObjectName object);
|
||||
|
||||
/**
|
||||
* Returns an array containing the objects being observed.
|
||||
*
|
||||
* @return The objects being observed.
|
||||
*
|
||||
*/
|
||||
public ObjectName[] getObservedObjects();
|
||||
|
||||
/**
|
||||
* Gets the object name of the object being observed.
|
||||
*
|
||||
* @return The object being observed.
|
||||
*
|
||||
* @see #setObservedObject
|
||||
*
|
||||
* @deprecated As of JMX 1.2, replaced by {@link #getObservedObjects}
|
||||
*/
|
||||
@Deprecated
|
||||
public ObjectName getObservedObject();
|
||||
|
||||
/**
|
||||
* Sets the object to observe identified by its object name.
|
||||
*
|
||||
* @param object The object to observe.
|
||||
*
|
||||
* @see #getObservedObject
|
||||
*
|
||||
* @deprecated As of JMX 1.2, replaced by {@link #addObservedObject}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setObservedObject(ObjectName object);
|
||||
|
||||
/**
|
||||
* Gets the attribute being observed.
|
||||
*
|
||||
* @return The attribute being observed.
|
||||
*
|
||||
* @see #setObservedAttribute
|
||||
*/
|
||||
public String getObservedAttribute();
|
||||
|
||||
/**
|
||||
* Sets the attribute to observe.
|
||||
*
|
||||
* @param attribute The attribute to observe.
|
||||
*
|
||||
* @see #getObservedAttribute
|
||||
*/
|
||||
public void setObservedAttribute(String attribute);
|
||||
|
||||
/**
|
||||
* Gets the granularity period (in milliseconds).
|
||||
*
|
||||
* @return The granularity period.
|
||||
*
|
||||
* @see #setGranularityPeriod
|
||||
*/
|
||||
public long getGranularityPeriod();
|
||||
|
||||
/**
|
||||
* Sets the granularity period (in milliseconds).
|
||||
*
|
||||
* @param period The granularity period.
|
||||
* @exception java.lang.IllegalArgumentException The granularity
|
||||
* period is less than or equal to zero.
|
||||
*
|
||||
* @see #getGranularityPeriod
|
||||
*/
|
||||
public void setGranularityPeriod(long period) throws java.lang.IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests if the monitor MBean is active.
|
||||
* A monitor MBean is marked active when the {@link #start start} method is called.
|
||||
* It becomes inactive when the {@link #stop stop} method is called.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the monitor MBean is active, <CODE>false</CODE> otherwise.
|
||||
*/
|
||||
public boolean isActive();
|
||||
}
|
||||
259
jdkSrc/jdk8/javax/management/monitor/MonitorNotification.java
Normal file
259
jdkSrc/jdk8/javax/management/monitor/MonitorNotification.java
Normal file
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.monitor;
|
||||
|
||||
|
||||
// jmx imports
|
||||
//
|
||||
import javax.management.ObjectName;
|
||||
|
||||
/**
|
||||
* Provides definitions of the notifications sent by monitor MBeans.
|
||||
* <P>
|
||||
* The notification source and a set of parameters concerning the monitor MBean's state
|
||||
* need to be specified when creating a new object of this class.
|
||||
*
|
||||
* The list of notifications fired by the monitor MBeans is the following:
|
||||
*
|
||||
* <UL>
|
||||
* <LI>Common to all kind of monitors:
|
||||
* <UL>
|
||||
* <LI>The observed object is not registered in the MBean server.
|
||||
* <LI>The observed attribute is not contained in the observed object.
|
||||
* <LI>The type of the observed attribute is not correct.
|
||||
* <LI>Any exception (except the cases described above) occurs when trying to get the value of the observed attribute.
|
||||
* </UL>
|
||||
* <LI>Common to the counter and the gauge monitors:
|
||||
* <UL>
|
||||
* <LI>The threshold high or threshold low are not of the same type as the gauge (gauge monitors).
|
||||
* <LI>The threshold or the offset or the modulus are not of the same type as the counter (counter monitors).
|
||||
* </UL>
|
||||
* <LI>Counter monitors only:
|
||||
* <UL>
|
||||
* <LI>The observed attribute has reached the threshold value.
|
||||
* </UL>
|
||||
* <LI>Gauge monitors only:
|
||||
* <UL>
|
||||
* <LI>The observed attribute has exceeded the threshold high value.
|
||||
* <LI>The observed attribute has exceeded the threshold low value.
|
||||
* </UL>
|
||||
* <LI>String monitors only:
|
||||
* <UL>
|
||||
* <LI>The observed attribute has matched the "string to compare" value.
|
||||
* <LI>The observed attribute has differed from the "string to compare" value.
|
||||
* </UL>
|
||||
* </UL>
|
||||
*
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class MonitorNotification extends javax.management.Notification {
|
||||
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PUBLIC VARIABLES
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Notification type denoting that the observed object is not registered in the MBean server.
|
||||
* This notification is fired by all kinds of monitors.
|
||||
* <BR>The value of this notification type is <CODE>jmx.monitor.error.mbean</CODE>.
|
||||
*/
|
||||
public static final String OBSERVED_OBJECT_ERROR = "jmx.monitor.error.mbean";
|
||||
|
||||
/**
|
||||
* Notification type denoting that the observed attribute is not contained in the observed object.
|
||||
* This notification is fired by all kinds of monitors.
|
||||
* <BR>The value of this notification type is <CODE>jmx.monitor.error.attribute</CODE>.
|
||||
*/
|
||||
public static final String OBSERVED_ATTRIBUTE_ERROR = "jmx.monitor.error.attribute";
|
||||
|
||||
/**
|
||||
* Notification type denoting that the type of the observed attribute is not correct.
|
||||
* This notification is fired by all kinds of monitors.
|
||||
* <BR>The value of this notification type is <CODE>jmx.monitor.error.type</CODE>.
|
||||
*/
|
||||
public static final String OBSERVED_ATTRIBUTE_TYPE_ERROR = "jmx.monitor.error.type";
|
||||
|
||||
/**
|
||||
* Notification type denoting that the type of the thresholds, offset or modulus is not correct.
|
||||
* This notification is fired by counter and gauge monitors.
|
||||
* <BR>The value of this notification type is <CODE>jmx.monitor.error.threshold</CODE>.
|
||||
*/
|
||||
public static final String THRESHOLD_ERROR = "jmx.monitor.error.threshold";
|
||||
|
||||
/**
|
||||
* Notification type denoting that a non-predefined error type has occurred when trying to get the value of the observed attribute.
|
||||
* This notification is fired by all kinds of monitors.
|
||||
* <BR>The value of this notification type is <CODE>jmx.monitor.error.runtime</CODE>.
|
||||
*/
|
||||
public static final String RUNTIME_ERROR = "jmx.monitor.error.runtime";
|
||||
|
||||
/**
|
||||
* Notification type denoting that the observed attribute has reached the threshold value.
|
||||
* This notification is only fired by counter monitors.
|
||||
* <BR>The value of this notification type is <CODE>jmx.monitor.counter.threshold</CODE>.
|
||||
*/
|
||||
public static final String THRESHOLD_VALUE_EXCEEDED = "jmx.monitor.counter.threshold";
|
||||
|
||||
/**
|
||||
* Notification type denoting that the observed attribute has exceeded the threshold high value.
|
||||
* This notification is only fired by gauge monitors.
|
||||
* <BR>The value of this notification type is <CODE>jmx.monitor.gauge.high</CODE>.
|
||||
*/
|
||||
public static final String THRESHOLD_HIGH_VALUE_EXCEEDED = "jmx.monitor.gauge.high";
|
||||
|
||||
/**
|
||||
* Notification type denoting that the observed attribute has exceeded the threshold low value.
|
||||
* This notification is only fired by gauge monitors.
|
||||
* <BR>The value of this notification type is <CODE>jmx.monitor.gauge.low</CODE>.
|
||||
*/
|
||||
public static final String THRESHOLD_LOW_VALUE_EXCEEDED = "jmx.monitor.gauge.low";
|
||||
|
||||
/**
|
||||
* Notification type denoting that the observed attribute has matched the "string to compare" value.
|
||||
* This notification is only fired by string monitors.
|
||||
* <BR>The value of this notification type is <CODE>jmx.monitor.string.matches</CODE>.
|
||||
*/
|
||||
public static final String STRING_TO_COMPARE_VALUE_MATCHED = "jmx.monitor.string.matches";
|
||||
|
||||
/**
|
||||
* Notification type denoting that the observed attribute has differed from the "string to compare" value.
|
||||
* This notification is only fired by string monitors.
|
||||
* <BR>The value of this notification type is <CODE>jmx.monitor.string.differs</CODE>.
|
||||
*/
|
||||
public static final String STRING_TO_COMPARE_VALUE_DIFFERED = "jmx.monitor.string.differs";
|
||||
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PRIVATE VARIABLES
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = -4608189663661929204L;
|
||||
|
||||
/**
|
||||
* @serial Monitor notification observed object.
|
||||
*/
|
||||
private ObjectName observedObject = null;
|
||||
|
||||
/**
|
||||
* @serial Monitor notification observed attribute.
|
||||
*/
|
||||
private String observedAttribute = null;
|
||||
|
||||
/**
|
||||
* @serial Monitor notification derived gauge.
|
||||
*/
|
||||
private Object derivedGauge = null;
|
||||
|
||||
/**
|
||||
* @serial Monitor notification release mechanism.
|
||||
* This value is used to keep the threshold/string (depending on the
|
||||
* monitor type) that triggered off this notification.
|
||||
*/
|
||||
private Object trigger = null;
|
||||
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* CONSTRUCTORS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a monitor notification object.
|
||||
*
|
||||
* @param type The notification type.
|
||||
* @param source The notification producer.
|
||||
* @param sequenceNumber The notification sequence number within the source object.
|
||||
* @param timeStamp The notification emission date.
|
||||
* @param msg The notification message.
|
||||
* @param obsObj The object observed by the producer of this notification.
|
||||
* @param obsAtt The attribute observed by the producer of this notification.
|
||||
* @param derGauge The derived gauge.
|
||||
* @param trigger The threshold/string (depending on the monitor type) that triggered the notification.
|
||||
*/
|
||||
MonitorNotification(String type, Object source, long sequenceNumber, long timeStamp, String msg,
|
||||
ObjectName obsObj, String obsAtt, Object derGauge, Object trigger) {
|
||||
|
||||
super(type, source, sequenceNumber, timeStamp, msg);
|
||||
this.observedObject = obsObj;
|
||||
this.observedAttribute = obsAtt;
|
||||
this.derivedGauge = derGauge;
|
||||
this.trigger = trigger;
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PUBLIC METHODS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
// GETTERS AND SETTERS
|
||||
//--------------------
|
||||
|
||||
/**
|
||||
* Gets the observed object of this monitor notification.
|
||||
*
|
||||
* @return The observed object.
|
||||
*/
|
||||
public ObjectName getObservedObject() {
|
||||
return observedObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the observed attribute of this monitor notification.
|
||||
*
|
||||
* @return The observed attribute.
|
||||
*/
|
||||
public String getObservedAttribute() {
|
||||
return observedAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the derived gauge of this monitor notification.
|
||||
*
|
||||
* @return The derived gauge.
|
||||
*/
|
||||
public Object getDerivedGauge() {
|
||||
return derivedGauge;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the threshold/string (depending on the monitor type) that triggered off this monitor notification.
|
||||
*
|
||||
* @return The trigger.
|
||||
*/
|
||||
public Object getTrigger() {
|
||||
return trigger;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.monitor;
|
||||
|
||||
|
||||
/**
|
||||
* Exception thrown by the monitor when a monitor setting becomes invalid while the monitor is running.
|
||||
* <P>
|
||||
* As the monitor attributes may change at runtime, a check is performed before each observation.
|
||||
* If a monitor attribute has become invalid, a monitor setting exception is thrown.
|
||||
*
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class MonitorSettingException extends javax.management.JMRuntimeException {
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = -8807913418190202007L;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public MonitorSettingException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that allows an error message to be specified.
|
||||
*
|
||||
* @param message The specific error message.
|
||||
*/
|
||||
public MonitorSettingException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
463
jdkSrc/jdk8/javax/management/monitor/StringMonitor.java
Normal file
463
jdkSrc/jdk8/javax/management/monitor/StringMonitor.java
Normal file
@@ -0,0 +1,463 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.monitor;
|
||||
|
||||
import static com.sun.jmx.defaults.JmxProperties.MONITOR_LOGGER;
|
||||
import java.util.logging.Level;
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.MBeanNotificationInfo;
|
||||
import static javax.management.monitor.MonitorNotification.*;
|
||||
|
||||
/**
|
||||
* Defines a monitor MBean designed to observe the values of a string
|
||||
* attribute.
|
||||
* <P>
|
||||
* A string monitor sends notifications as follows:
|
||||
* <UL>
|
||||
* <LI> if the attribute value matches the string to compare value,
|
||||
* a {@link MonitorNotification#STRING_TO_COMPARE_VALUE_MATCHED
|
||||
* match notification} is sent.
|
||||
* The notify match flag must be set to <CODE>true</CODE>.
|
||||
* <BR>Subsequent matchings of the string to compare values do not
|
||||
* cause further notifications unless
|
||||
* the attribute value differs from the string to compare value.
|
||||
* <LI> if the attribute value differs from the string to compare value,
|
||||
* a {@link MonitorNotification#STRING_TO_COMPARE_VALUE_DIFFERED
|
||||
* differ notification} is sent.
|
||||
* The notify differ flag must be set to <CODE>true</CODE>.
|
||||
* <BR>Subsequent differences from the string to compare value do
|
||||
* not cause further notifications unless
|
||||
* the attribute value matches the string to compare value.
|
||||
* </UL>
|
||||
*
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class StringMonitor extends Monitor implements StringMonitorMBean {
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PACKAGE CLASSES
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
static class StringMonitorObservedObject extends ObservedObject {
|
||||
|
||||
public StringMonitorObservedObject(ObjectName observedObject) {
|
||||
super(observedObject);
|
||||
}
|
||||
|
||||
public final synchronized int getStatus() {
|
||||
return status;
|
||||
}
|
||||
public final synchronized void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
private int status;
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PRIVATE VARIABLES
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* String to compare with the observed attribute.
|
||||
* <BR>The default value is an empty character sequence.
|
||||
*/
|
||||
private String stringToCompare = "";
|
||||
|
||||
/**
|
||||
* Flag indicating if the string monitor notifies when matching
|
||||
* the string to compare.
|
||||
* <BR>The default value is set to <CODE>false</CODE>.
|
||||
*/
|
||||
private boolean notifyMatch = false;
|
||||
|
||||
/**
|
||||
* Flag indicating if the string monitor notifies when differing
|
||||
* from the string to compare.
|
||||
* <BR>The default value is set to <CODE>false</CODE>.
|
||||
*/
|
||||
private boolean notifyDiffer = false;
|
||||
|
||||
private static final String[] types = {
|
||||
RUNTIME_ERROR,
|
||||
OBSERVED_OBJECT_ERROR,
|
||||
OBSERVED_ATTRIBUTE_ERROR,
|
||||
OBSERVED_ATTRIBUTE_TYPE_ERROR,
|
||||
STRING_TO_COMPARE_VALUE_MATCHED,
|
||||
STRING_TO_COMPARE_VALUE_DIFFERED
|
||||
};
|
||||
|
||||
private static final MBeanNotificationInfo[] notifsInfo = {
|
||||
new MBeanNotificationInfo(
|
||||
types,
|
||||
"javax.management.monitor.MonitorNotification",
|
||||
"Notifications sent by the StringMonitor MBean")
|
||||
};
|
||||
|
||||
// Flags needed to implement the matching/differing mechanism.
|
||||
//
|
||||
private static final int MATCHING = 0;
|
||||
private static final int DIFFERING = 1;
|
||||
private static final int MATCHING_OR_DIFFERING = 2;
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* CONSTRUCTORS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public StringMonitor() {
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PUBLIC METHODS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Starts the string monitor.
|
||||
*/
|
||||
public synchronized void start() {
|
||||
if (isActive()) {
|
||||
MONITOR_LOGGER.logp(Level.FINER, StringMonitor.class.getName(),
|
||||
"start", "the monitor is already active");
|
||||
return;
|
||||
}
|
||||
// Reset values.
|
||||
//
|
||||
for (ObservedObject o : observedObjects) {
|
||||
final StringMonitorObservedObject smo =
|
||||
(StringMonitorObservedObject) o;
|
||||
smo.setStatus(MATCHING_OR_DIFFERING);
|
||||
}
|
||||
doStart();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the string monitor.
|
||||
*/
|
||||
public synchronized void stop() {
|
||||
doStop();
|
||||
}
|
||||
|
||||
// GETTERS AND SETTERS
|
||||
//--------------------
|
||||
|
||||
/**
|
||||
* Gets the derived gauge of the specified object, if this object is
|
||||
* contained in the set of observed MBeans, or <code>null</code> otherwise.
|
||||
*
|
||||
* @param object the name of the MBean whose derived gauge is required.
|
||||
*
|
||||
* @return The derived gauge of the specified object.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public synchronized String getDerivedGauge(ObjectName object) {
|
||||
return (String) super.getDerivedGauge(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the derived gauge timestamp of the specified object, if
|
||||
* this object is contained in the set of observed MBeans, or
|
||||
* <code>0</code> otherwise.
|
||||
*
|
||||
* @param object the name of the object whose derived gauge
|
||||
* timestamp is to be returned.
|
||||
*
|
||||
* @return The derived gauge timestamp of the specified object.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public synchronized long getDerivedGaugeTimeStamp(ObjectName object) {
|
||||
return super.getDerivedGaugeTimeStamp(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the derived gauge of the first object in the set of
|
||||
* observed MBeans.
|
||||
*
|
||||
* @return The derived gauge.
|
||||
*
|
||||
* @deprecated As of JMX 1.2, replaced by
|
||||
* {@link #getDerivedGauge(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public synchronized String getDerivedGauge() {
|
||||
if (observedObjects.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
return (String) observedObjects.get(0).getDerivedGauge();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the derived gauge timestamp of the first object in the set
|
||||
* of observed MBeans.
|
||||
*
|
||||
* @return The derived gauge timestamp.
|
||||
*
|
||||
* @deprecated As of JMX 1.2, replaced by
|
||||
* {@link #getDerivedGaugeTimeStamp(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public synchronized long getDerivedGaugeTimeStamp() {
|
||||
if (observedObjects.isEmpty()) {
|
||||
return 0;
|
||||
} else {
|
||||
return observedObjects.get(0).getDerivedGaugeTimeStamp();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string to compare with the observed attribute common
|
||||
* to all observed MBeans.
|
||||
*
|
||||
* @return The string value.
|
||||
*
|
||||
* @see #setStringToCompare
|
||||
*/
|
||||
public synchronized String getStringToCompare() {
|
||||
return stringToCompare;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the string to compare with the observed attribute common
|
||||
* to all observed MBeans.
|
||||
*
|
||||
* @param value The string value.
|
||||
*
|
||||
* @exception IllegalArgumentException The specified
|
||||
* string to compare is null.
|
||||
*
|
||||
* @see #getStringToCompare
|
||||
*/
|
||||
public synchronized void setStringToCompare(String value)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException("Null string to compare");
|
||||
}
|
||||
|
||||
if (stringToCompare.equals(value))
|
||||
return;
|
||||
stringToCompare = value;
|
||||
|
||||
// Reset values.
|
||||
//
|
||||
for (ObservedObject o : observedObjects) {
|
||||
final StringMonitorObservedObject smo =
|
||||
(StringMonitorObservedObject) o;
|
||||
smo.setStatus(MATCHING_OR_DIFFERING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the matching notification's on/off switch value common to
|
||||
* all observed MBeans.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the string monitor notifies when
|
||||
* matching the string to compare, <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setNotifyMatch
|
||||
*/
|
||||
public synchronized boolean getNotifyMatch() {
|
||||
return notifyMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the matching notification's on/off switch value common to
|
||||
* all observed MBeans.
|
||||
*
|
||||
* @param value The matching notification's on/off switch value.
|
||||
*
|
||||
* @see #getNotifyMatch
|
||||
*/
|
||||
public synchronized void setNotifyMatch(boolean value) {
|
||||
if (notifyMatch == value)
|
||||
return;
|
||||
notifyMatch = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the differing notification's on/off switch value common to
|
||||
* all observed MBeans.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the string monitor notifies when
|
||||
* differing from the string to compare, <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setNotifyDiffer
|
||||
*/
|
||||
public synchronized boolean getNotifyDiffer() {
|
||||
return notifyDiffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the differing notification's on/off switch value common to
|
||||
* all observed MBeans.
|
||||
*
|
||||
* @param value The differing notification's on/off switch value.
|
||||
*
|
||||
* @see #getNotifyDiffer
|
||||
*/
|
||||
public synchronized void setNotifyDiffer(boolean value) {
|
||||
if (notifyDiffer == value)
|
||||
return;
|
||||
notifyDiffer = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <CODE>NotificationInfo</CODE> object containing the name of
|
||||
* the Java class of the notification and the notification types sent by
|
||||
* the string monitor.
|
||||
*/
|
||||
@Override
|
||||
public MBeanNotificationInfo[] getNotificationInfo() {
|
||||
return notifsInfo.clone();
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* PACKAGE METHODS
|
||||
* ------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Factory method for ObservedObject creation.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
@Override
|
||||
ObservedObject createObservedObject(ObjectName object) {
|
||||
final StringMonitorObservedObject smo =
|
||||
new StringMonitorObservedObject(object);
|
||||
smo.setStatus(MATCHING_OR_DIFFERING);
|
||||
return smo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the type of the supplied observed attribute
|
||||
* value is one of the value types supported by this monitor.
|
||||
*/
|
||||
@Override
|
||||
synchronized boolean isComparableTypeValid(ObjectName object,
|
||||
String attribute,
|
||||
Comparable<?> value) {
|
||||
// Check that the observed attribute is of type "String".
|
||||
//
|
||||
if (value instanceof String) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized void onErrorNotification(MonitorNotification notification) {
|
||||
final StringMonitorObservedObject o = (StringMonitorObservedObject)
|
||||
getObservedObject(notification.getObservedObject());
|
||||
if (o == null)
|
||||
return;
|
||||
|
||||
// Reset values.
|
||||
//
|
||||
o.setStatus(MATCHING_OR_DIFFERING);
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized MonitorNotification buildAlarmNotification(
|
||||
ObjectName object,
|
||||
String attribute,
|
||||
Comparable<?> value) {
|
||||
String type = null;
|
||||
String msg = null;
|
||||
Object trigger = null;
|
||||
|
||||
final StringMonitorObservedObject o =
|
||||
(StringMonitorObservedObject) getObservedObject(object);
|
||||
if (o == null)
|
||||
return null;
|
||||
|
||||
// Send matching notification if notifyMatch is true.
|
||||
// Send differing notification if notifyDiffer is true.
|
||||
//
|
||||
if (o.getStatus() == MATCHING_OR_DIFFERING) {
|
||||
if (o.getDerivedGauge().equals(stringToCompare)) {
|
||||
if (notifyMatch) {
|
||||
type = STRING_TO_COMPARE_VALUE_MATCHED;
|
||||
msg = "";
|
||||
trigger = stringToCompare;
|
||||
}
|
||||
o.setStatus(DIFFERING);
|
||||
} else {
|
||||
if (notifyDiffer) {
|
||||
type = STRING_TO_COMPARE_VALUE_DIFFERED;
|
||||
msg = "";
|
||||
trigger = stringToCompare;
|
||||
}
|
||||
o.setStatus(MATCHING);
|
||||
}
|
||||
} else {
|
||||
if (o.getStatus() == MATCHING) {
|
||||
if (o.getDerivedGauge().equals(stringToCompare)) {
|
||||
if (notifyMatch) {
|
||||
type = STRING_TO_COMPARE_VALUE_MATCHED;
|
||||
msg = "";
|
||||
trigger = stringToCompare;
|
||||
}
|
||||
o.setStatus(DIFFERING);
|
||||
}
|
||||
} else if (o.getStatus() == DIFFERING) {
|
||||
if (!o.getDerivedGauge().equals(stringToCompare)) {
|
||||
if (notifyDiffer) {
|
||||
type = STRING_TO_COMPARE_VALUE_DIFFERED;
|
||||
msg = "";
|
||||
trigger = stringToCompare;
|
||||
}
|
||||
o.setStatus(MATCHING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new MonitorNotification(type,
|
||||
this,
|
||||
0,
|
||||
0,
|
||||
msg,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
trigger);
|
||||
}
|
||||
}
|
||||
138
jdkSrc/jdk8/javax/management/monitor/StringMonitorMBean.java
Normal file
138
jdkSrc/jdk8/javax/management/monitor/StringMonitorMBean.java
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.monitor;
|
||||
|
||||
// jmx imports
|
||||
//
|
||||
import javax.management.ObjectName;
|
||||
|
||||
/**
|
||||
* Exposes the remote management interface of the string monitor MBean.
|
||||
*
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface StringMonitorMBean extends MonitorMBean {
|
||||
|
||||
// GETTERS AND SETTERS
|
||||
//--------------------
|
||||
|
||||
/**
|
||||
* Gets the derived gauge.
|
||||
*
|
||||
* @return The derived gauge.
|
||||
* @deprecated As of JMX 1.2, replaced by {@link #getDerivedGauge(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public String getDerivedGauge();
|
||||
|
||||
/**
|
||||
* Gets the derived gauge timestamp.
|
||||
*
|
||||
* @return The derived gauge timestamp.
|
||||
* @deprecated As of JMX 1.2, replaced by {@link #getDerivedGaugeTimeStamp(ObjectName)}
|
||||
*/
|
||||
@Deprecated
|
||||
public long getDerivedGaugeTimeStamp();
|
||||
|
||||
/**
|
||||
* Gets the derived gauge for the specified MBean.
|
||||
*
|
||||
* @param object the MBean for which the derived gauge is to be returned
|
||||
* @return The derived gauge for the specified MBean if this MBean is in the
|
||||
* set of observed MBeans, or <code>null</code> otherwise.
|
||||
*
|
||||
*/
|
||||
public String getDerivedGauge(ObjectName object);
|
||||
|
||||
/**
|
||||
* Gets the derived gauge timestamp for the specified MBean.
|
||||
*
|
||||
* @param object the MBean for which the derived gauge timestamp is to be returned
|
||||
* @return The derived gauge timestamp for the specified MBean if this MBean
|
||||
* is in the set of observed MBeans, or <code>null</code> otherwise.
|
||||
*
|
||||
*/
|
||||
public long getDerivedGaugeTimeStamp(ObjectName object);
|
||||
|
||||
/**
|
||||
* Gets the string to compare with the observed attribute.
|
||||
*
|
||||
* @return The string value.
|
||||
*
|
||||
* @see #setStringToCompare
|
||||
*/
|
||||
public String getStringToCompare();
|
||||
|
||||
/**
|
||||
* Sets the string to compare with the observed attribute.
|
||||
*
|
||||
* @param value The string value.
|
||||
* @exception java.lang.IllegalArgumentException The specified
|
||||
* string to compare is null.
|
||||
*
|
||||
* @see #getStringToCompare
|
||||
*/
|
||||
public void setStringToCompare(String value) throws java.lang.IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Gets the matching notification's on/off switch value.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the string monitor notifies when
|
||||
* matching, <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setNotifyMatch
|
||||
*/
|
||||
public boolean getNotifyMatch();
|
||||
|
||||
/**
|
||||
* Sets the matching notification's on/off switch value.
|
||||
*
|
||||
* @param value The matching notification's on/off switch value.
|
||||
*
|
||||
* @see #getNotifyMatch
|
||||
*/
|
||||
public void setNotifyMatch(boolean value);
|
||||
|
||||
/**
|
||||
* Gets the differing notification's on/off switch value.
|
||||
*
|
||||
* @return <CODE>true</CODE> if the string monitor notifies when
|
||||
* differing, <CODE>false</CODE> otherwise.
|
||||
*
|
||||
* @see #setNotifyDiffer
|
||||
*/
|
||||
public boolean getNotifyDiffer();
|
||||
|
||||
/**
|
||||
* Sets the differing notification's on/off switch value.
|
||||
*
|
||||
* @param value The differing notification's on/off switch value.
|
||||
*
|
||||
* @see #getNotifyDiffer
|
||||
*/
|
||||
public void setNotifyDiffer(boolean value);
|
||||
}
|
||||
Reference in New Issue
Block a user