001: /*
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */
008:
009: package javax.management.monitor;
010:
011: import javax.management.MBeanRegistration;
012: import javax.management.MBeanServer;
013: import javax.management.NotificationBroadcasterSupport;
014: import javax.management.ObjectName;
015:
016: import mx4j.monitor.MX4JMonitor;
017:
018: /**
019: * @version $Revision: 1.16 $
020: */
021: public abstract class Monitor extends NotificationBroadcasterSupport
022: implements MonitorMBean, MBeanRegistration {
023: /**
024: * @deprecated
025: */
026: protected int alreadyNotified;
027: protected int alreadyNotifieds[];
028: protected static final int capacityIncrement = 16;
029: /**
030: * @deprecated
031: */
032: protected String dbgTag;
033: protected int elementCount;
034: protected static final int OBSERVED_ATTRIBUTE_ERROR_NOTIFIED = 2;
035: protected static final int OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED = 4;
036: protected static final int OBSERVED_OBJECT_ERROR_NOTIFIED = 1;
037: protected static final int RESET_FLAGS_ALREADY_NOTIFIED = 0;
038: protected static final int RUNTIME_ERROR_NOTIFIED = 8;
039:
040: // Fields above are a mistake in the spec: JMX 1.0 was poorly written and these fields
041: // made their way into the specification. MX4J's implementation is different from RI's
042: // and we don't value the fields above.
043:
044: protected MBeanServer server;
045:
046: private MX4JMonitor monitor;
047:
048: abstract MX4JMonitor createMX4JMonitor();
049:
050: synchronized MX4JMonitor getMX4JMonitor() {
051: if (monitor == null) {
052: monitor = createMX4JMonitor();
053: }
054: return monitor;
055: }
056:
057: public abstract void start();
058:
059: public abstract void stop();
060:
061: /**
062: * @deprecated
063: */
064: public ObjectName getObservedObject() {
065: ObjectName[] observed = getObservedObjects();
066: if (observed == null || observed.length < 1)
067: return null;
068: return observed[0];
069: }
070:
071: /**
072: * @deprecated
073: */
074: public void setObservedObject(ObjectName objectName)
075: throws java.lang.IllegalArgumentException {
076: MX4JMonitor monitor = getMX4JMonitor();
077: synchronized (monitor) {
078: monitor.clearObservedObjects();
079: monitor.addObservedObject(objectName);
080: }
081: }
082:
083: public String getObservedAttribute() {
084: MX4JMonitor monitor = getMX4JMonitor();
085: return monitor.getObservedAttribute();
086: }
087:
088: public void setObservedAttribute(String attribute)
089: throws java.lang.IllegalArgumentException {
090: MX4JMonitor monitor = getMX4JMonitor();
091: monitor.setObservedAttribute(attribute);
092: }
093:
094: public long getGranularityPeriod() {
095: MX4JMonitor monitor = getMX4JMonitor();
096: return monitor.getGranularityPeriod();
097: }
098:
099: public void setGranularityPeriod(long period)
100: throws java.lang.IllegalArgumentException {
101: MX4JMonitor monitor = getMX4JMonitor();
102: monitor.setGranularityPeriod(period);
103: }
104:
105: public boolean isActive() {
106: MX4JMonitor monitor = getMX4JMonitor();
107: return monitor.isActive();
108: }
109:
110: public ObjectName preRegister(MBeanServer server, ObjectName name)
111: throws Exception {
112: this .server = server;
113: MX4JMonitor monitor = getMX4JMonitor();
114: return monitor.preRegister(server, name);
115: }
116:
117: public void postRegister(Boolean registrationDone) {
118: MX4JMonitor monitor = getMX4JMonitor();
119: monitor.postRegister(registrationDone);
120: }
121:
122: public void preDeregister() throws Exception {
123: MX4JMonitor monitor = getMX4JMonitor();
124: monitor.preDeregister();
125: }
126:
127: public void postDeregister() {
128: MX4JMonitor monitor = getMX4JMonitor();
129: monitor.postDeregister();
130: }
131:
132: public void addObservedObject(ObjectName objectName)
133: throws IllegalArgumentException {
134: MX4JMonitor monitor = getMX4JMonitor();
135: monitor.addObservedObject(objectName);
136: }
137:
138: public ObjectName[] getObservedObjects() {
139: MX4JMonitor monitor = getMX4JMonitor();
140: return monitor.getObservedObjects();
141: }
142:
143: public boolean containsObservedObject(ObjectName objectName) {
144: MX4JMonitor monitor = getMX4JMonitor();
145: return monitor.containsObservedObject(objectName);
146: }
147:
148: public void removeObservedObject(ObjectName objectName) {
149: MX4JMonitor monitor = getMX4JMonitor();
150: monitor.removeObservedObject(objectName);
151: }
152: }
|