Method from javax.management.monitor.Monitor Detail: |
public synchronized void addObservedObject(ObjectName object) throws IllegalArgumentException {
if (object == null) {
throw new IllegalArgumentException("Null observed object");
}
// Check that the specified object is not already contained.
//
if (containsObservedObject(object))
return;
// Add the specified object in the list.
//
ObservedObject o = createObservedObject(object);
o.setAlreadyNotified(RESET_FLAGS_ALREADY_NOTIFIED);
o.setDerivedGauge(null);
o.setDerivedGaugeTimeStamp(System.currentTimeMillis());
observedObjects.add(o);
// Update legacy protected stuff.
//
createAlreadyNotified();
}
Adds the specified object in the set of observed MBeans, if this object
is not already present. |
MonitorNotification buildAlarmNotification(ObjectName object,
String attribute,
Comparable<?> value) {
return null;
}
|
String buildErrorNotification(ObjectName object,
String attribute,
Comparable<?> value) {
return null;
}
|
static Class<Number> classForType(NumericalType type) {
switch (type) {
case BYTE:
return Byte.class;
case SHORT:
return Short.class;
case INTEGER:
return Integer.class;
case LONG:
return Long.class;
case FLOAT:
return Float.class;
case DOUBLE:
return Double.class;
default:
throw new IllegalArgumentException(
"Unsupported numerical type");
}
}
|
synchronized int computeAlreadyNotifiedIndex(ObservedObject o,
int index,
int[] an) {
if (an == alreadyNotifieds) {
return index;
} else {
return observedObjects.indexOf(o);
}
}
Check if the #alreadyNotifieds array has been modified.
If true recompute the index for the given observed object. |
public synchronized boolean containsObservedObject(ObjectName object) {
return getObservedObject(object) != null;
}
Tests whether the specified object is in the set of observed MBeans. |
synchronized void createAlreadyNotified() {
// Update elementCount.
//
elementCount = observedObjects.size();
// Update arrays.
//
alreadyNotifieds = new int[elementCount];
for (int i = 0; i < elementCount; i++) {
alreadyNotifieds[i] = observedObjects.get(i).getAlreadyNotified();
}
updateDeprecatedAlreadyNotified();
}
|
ObservedObject createObservedObject(ObjectName object) {
return new ObservedObject(object);
}
Factory method for ObservedObject creation. |
void doStart() {
MONITOR_LOGGER.logp(Level.FINER, Monitor.class.getName(),
"doStart()", "start the monitor");
synchronized (this) {
if (isActive()) {
MONITOR_LOGGER.logp(Level.FINER, Monitor.class.getName(),
"doStart()", "the monitor is already active");
return;
}
isActive = true;
// Reset the complex type attribute information
// such that it is recalculated again.
//
cleanupIsComplexTypeAttribute();
// Cache the AccessControlContext of the Monitor.start() caller.
// The monitor tasks will be executed within this context.
//
acc = AccessController.getContext();
// Start the scheduler.
//
cleanupFutures();
schedulerFuture = scheduler.schedule(schedulerTask,
getGranularityPeriod(),
TimeUnit.MILLISECONDS);
}
}
|
void doStop() {
MONITOR_LOGGER.logp(Level.FINER, Monitor.class.getName(),
"doStop()", "stop the monitor");
synchronized (this) {
if (!isActive()) {
MONITOR_LOGGER.logp(Level.FINER, Monitor.class.getName(),
"doStop()", "the monitor is not active");
return;
}
isActive = false;
// Cancel the scheduler task associated with the
// scheduler and its associated monitor task.
//
cleanupFutures();
// Reset the AccessControlContext.
//
acc = null;
// Reset the complex type attribute information
// such that it is recalculated again.
//
cleanupIsComplexTypeAttribute();
}
}
|
Object getAttribute(MBeanServerConnection mbsc,
ObjectName object,
String attribute) throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException {
// Check for "ObservedAttribute" replacement.
// This could happen if a thread A called setObservedAttribute()
// while other thread B was in the middle of the monitor() method
// and received the old observed attribute value.
//
final boolean lookupMBeanInfo;
synchronized (this) {
if (!isActive())
throw new IllegalArgumentException(
"The monitor has been stopped");
if (!attribute.equals(getObservedAttribute()))
throw new IllegalArgumentException(
"The observed attribute has been changed");
lookupMBeanInfo =
(firstAttribute == null && attribute.indexOf('.') != -1);
}
// Look up MBeanInfo if needed
//
final MBeanInfo mbi;
if (lookupMBeanInfo) {
try {
mbi = mbsc.getMBeanInfo(object);
} catch (IntrospectionException e) {
throw new IllegalArgumentException(e);
}
} else {
mbi = null;
}
// Check for complex type attribute
//
final String fa;
synchronized (this) {
if (!isActive())
throw new IllegalArgumentException(
"The monitor has been stopped");
if (!attribute.equals(getObservedAttribute()))
throw new IllegalArgumentException(
"The observed attribute has been changed");
if (firstAttribute == null) {
if (attribute.indexOf('.') != -1) {
MBeanAttributeInfo mbaiArray[] = mbi.getAttributes();
for (MBeanAttributeInfo mbai : mbaiArray) {
if (attribute.equals(mbai.getName())) {
firstAttribute = attribute;
break;
}
}
if (firstAttribute == null) {
String tokens[] = attribute.split("\\.", -1);
firstAttribute = tokens[0];
for (int i = 1; i < tokens.length; i++)
remainingAttributes.add(tokens[i]);
isComplexTypeAttribute = true;
}
} else {
firstAttribute = attribute;
}
}
fa = firstAttribute;
}
return mbsc.getAttribute(object, fa);
}
|
Comparable<?> getComparableFromAttribute(ObjectName object,
String attribute,
Object value) throws AttributeNotFoundException {
if (isComplexTypeAttribute) {
Object v = value;
for (String attr : remainingAttributes)
v = Introspector.elementFromComplex(v, attr);
return (Comparable< ? >) v;
} else {
return (Comparable< ? >) value;
}
}
|
synchronized Object getDerivedGauge(ObjectName object) {
final ObservedObject o = getObservedObject(object);
return o == null ? null : o.getDerivedGauge();
}
Gets the derived gauge of the specified object, if this object is
contained in the set of observed MBeans, or null otherwise. |
Comparable<?> getDerivedGaugeFromComparable(ObjectName object,
String attribute,
Comparable<?> value) {
return (Comparable< ? >) value;
}
|
synchronized long getDerivedGaugeTimeStamp(ObjectName object) {
final ObservedObject o = getObservedObject(object);
return o == null ? 0 : o.getDerivedGaugeTimeStamp();
}
Gets the derived gauge timestamp of the specified object, if
this object is contained in the set of observed MBeans, or
0 otherwise. |
public synchronized long getGranularityPeriod() {
return granularityPeriod;
}
Gets the granularity period (in milliseconds).
The default value of the granularity period is 10 seconds. |
public synchronized String getObservedAttribute() {
return observedAttribute;
}
Gets the attribute being observed.
The observed attribute is not initialized by default (set to null). |
public synchronized ObjectName getObservedObject() {
if (observedObjects.isEmpty()) {
return null;
} else {
return observedObjects.get(0).getObservedObject();
}
} Deprecated! As - of JMX 1.2, replaced by #getObservedObjects
Returns the object name of the first object in the set of observed
MBeans, or null if there is no such object. |
synchronized ObservedObject getObservedObject(ObjectName object) {
for (ObservedObject o : observedObjects)
if (o.getObservedObject().equals(object))
return o;
return null;
}
Get the specified {@code ObservedObject} if this object is
contained in the set of observed MBeans, or {@code null}
otherwise. |
public synchronized ObjectName[] getObservedObjects() {
ObjectName[] names = new ObjectName[observedObjects.size()];
for (int i = 0; i < names.length; i++)
names[i] = observedObjects.get(i).getObservedObject();
return names;
}
Returns an array containing the objects being observed. |
public synchronized boolean isActive() {
return isActive;
}
Tests whether the monitor MBean is active. A monitor MBean is
marked active when the start method is called.
It becomes inactive when the stop method is
called. |
synchronized boolean isAlreadyNotified(ObservedObject o,
int mask) {
return ((o.getAlreadyNotified() & mask) != 0);
}
|
boolean isComparableTypeValid(ObjectName object,
String attribute,
Comparable<?> value) {
return true;
}
|
boolean isThresholdTypeValid(ObjectName object,
String attribute,
Comparable<?> value) {
return true;
}
|
static boolean isValidForType(Object value,
Class<Number> c) {
return ((value == INTEGER_ZERO) || c.isInstance(value));
}
|
void onErrorNotification(MonitorNotification notification) {
}
|
public void postDeregister() {
}
|
public void postRegister(Boolean registrationDone) {
}
|
public void preDeregister() throws Exception {
MONITOR_LOGGER.logp(Level.FINER, Monitor.class.getName(),
"preDeregister()", "stop the monitor");
// Stop the Monitor.
//
stop();
}
Allows the monitor MBean to perform any operations it needs
before being unregistered by the MBean server.
Stops the monitor. |
public ObjectName preRegister(MBeanServer server,
ObjectName name) throws Exception {
MONITOR_LOGGER.logp(Level.FINER, Monitor.class.getName(),
"preRegister(MBeanServer, ObjectName)",
"initialize the reference on the MBean server");
this.server = server;
return name;
}
|
public synchronized void removeObservedObject(ObjectName object) {
// Check for null object.
//
if (object == null)
return;
final ObservedObject o = getObservedObject(object);
if (o != null) {
// Remove the specified object from the list.
//
observedObjects.remove(o);
// Update legacy protected stuff.
//
createAlreadyNotified();
}
}
Removes the specified object from the set of observed MBeans. |
synchronized void resetAllAlreadyNotified(ObservedObject o,
int index,
int[] an) {
final int i = computeAlreadyNotifiedIndex(o, index, an);
if (i == -1)
return;
o.setAlreadyNotified(RESET_FLAGS_ALREADY_NOTIFIED);
updateAlreadyNotified(o, index);
}
|
synchronized void resetAlreadyNotified(ObservedObject o,
int index,
int mask) {
o.setAlreadyNotified(o.getAlreadyNotified() & ~mask);
updateAlreadyNotified(o, index);
}
|
synchronized void setAlreadyNotified(ObservedObject o,
int index,
int mask,
int[] an) {
final int i = computeAlreadyNotifiedIndex(o, index, an);
if (i == -1)
return;
o.setAlreadyNotified(o.getAlreadyNotified() | mask);
updateAlreadyNotified(o, i);
}
|
public synchronized void setGranularityPeriod(long period) throws IllegalArgumentException {
if (period < = 0) {
throw new IllegalArgumentException("Nonpositive granularity " +
"period");
}
if (granularityPeriod == period)
return;
granularityPeriod = period;
// Reschedule the scheduler task if the monitor is active.
//
if (isActive()) {
cleanupFutures();
schedulerFuture = scheduler.schedule(schedulerTask,
period,
TimeUnit.MILLISECONDS);
}
}
Sets the granularity period (in milliseconds).
The default value of the granularity period is 10 seconds. |
public void setObservedAttribute(String attribute) throws IllegalArgumentException {
if (attribute == null) {
throw new IllegalArgumentException("Null observed attribute");
}
// Update alreadyNotified array.
//
synchronized (this) {
if (observedAttribute != null &&
observedAttribute.equals(attribute))
return;
observedAttribute = attribute;
// Reset the complex type attribute information
// such that it is recalculated again.
//
cleanupIsComplexTypeAttribute();
int index = 0;
for (ObservedObject o : observedObjects) {
resetAlreadyNotified(o, index++,
OBSERVED_ATTRIBUTE_ERROR_NOTIFIED |
OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED);
}
}
}
Sets the attribute to observe.
The observed attribute is not initialized by default (set to null). |
public synchronized void setObservedObject(ObjectName object) throws IllegalArgumentException {
if (object == null)
throw new IllegalArgumentException("Null observed object");
if (observedObjects.size() == 1 && containsObservedObject(object))
return;
observedObjects.clear();
addObservedObject(object);
} Deprecated! As - of JMX 1.2, replaced by #addObservedObject
Removes all objects from the set of observed objects, and then adds the
specified object. |
abstract public void start()
|
abstract public void stop()
|
synchronized void updateAlreadyNotified(ObservedObject o,
int index) {
alreadyNotifieds[index] = o.getAlreadyNotified();
if (index == 0)
updateDeprecatedAlreadyNotified();
}
Update the #alreadyNotifieds array element at the given index
with the already notified flag in the given {@code ObservedObject}.
Ensure the deprecated #alreadyNotified field is updated
if appropriate. |
synchronized void updateDeprecatedAlreadyNotified() {
if (elementCount > 0)
alreadyNotified = alreadyNotifieds[0];
else
alreadyNotified = 0;
}
|