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.MBeanNotificationInfo;
012: import javax.management.NotCompliantMBeanException;
013: import javax.management.Notification;
014: import javax.management.NotificationBroadcasterSupport;
015: import javax.management.ObjectName;
016:
017: import mx4j.monitor.MX4JCounterMonitor;
018: import mx4j.monitor.MX4JMonitor;
019:
020: /**
021: * @version $Revision: 1.9 $
022: */
023: public class CounterMonitor extends Monitor implements
024: CounterMonitorMBean {
025: private static final MBeanNotificationInfo[] notificationInfos = { new MBeanNotificationInfo(
026: new String[] { MonitorNotification.RUNTIME_ERROR,
027: MonitorNotification.OBSERVED_OBJECT_ERROR,
028: MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
029: MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
030: MonitorNotification.THRESHOLD_ERROR,
031: MonitorNotification.THRESHOLD_VALUE_EXCEEDED },
032: MonitorNotification.class.getName(),
033: "Notifications sent by the CounterMonitor MBean") };
034:
035: MX4JMonitor createMX4JMonitor() {
036: try {
037: return new MX4JCounterMonitor() {
038: protected NotificationBroadcasterSupport createNotificationEmitter() {
039: return CounterMonitor.this ;
040: }
041:
042: public MBeanNotificationInfo[] getNotificationInfo() {
043: return notificationInfos;
044: }
045:
046: protected Notification createMonitorNotification(
047: String type, long sequence, String message,
048: ObjectName observed, String attribute,
049: Object gauge, Object trigger) {
050: return new MonitorNotification(type, this ,
051: sequence, System.currentTimeMillis(),
052: message, observed, attribute, gauge,
053: trigger);
054: }
055: };
056: } catch (NotCompliantMBeanException x) {
057: return null;
058: }
059: }
060:
061: public void start() {
062: MX4JMonitor monitor = getMX4JMonitor();
063: monitor.start();
064: }
065:
066: public void stop() {
067: MX4JMonitor monitor = getMX4JMonitor();
068: monitor.stop();
069: }
070:
071: /**
072: * @deprecated
073: */
074: public Number getDerivedGauge() {
075: return getDerivedGauge(getObservedObject());
076: }
077:
078: /**
079: * @deprecated
080: */
081: public long getDerivedGaugeTimeStamp() {
082: return getDerivedGaugeTimeStamp(getObservedObject());
083: }
084:
085: /**
086: * @deprecated
087: */
088: public Number getThreshold() {
089: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
090: return monitor.getThreshold(getObservedObject());
091: }
092:
093: /**
094: * @deprecated
095: */
096: public void setThreshold(Number value)
097: throws java.lang.IllegalArgumentException {
098: setInitThreshold(value);
099: }
100:
101: public Number getDerivedGauge(ObjectName objectName) {
102: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
103: return monitor.getDerivedGauge(objectName);
104: }
105:
106: public long getDerivedGaugeTimeStamp(ObjectName objectName) {
107: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
108: return monitor.getDerivedGaugeTimeStamp(objectName);
109: }
110:
111: public Number getThreshold(ObjectName objectName) {
112: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
113: return monitor.getThreshold(objectName);
114: }
115:
116: public Number getInitThreshold() {
117: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
118: return monitor.getInitThreshold();
119: }
120:
121: public void setInitThreshold(Number value)
122: throws java.lang.IllegalArgumentException {
123: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
124: monitor.setInitThreshold(value);
125: }
126:
127: public Number getOffset() {
128: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
129: return monitor.getOffset();
130: }
131:
132: public synchronized void setOffset(Number value)
133: throws java.lang.IllegalArgumentException {
134: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
135: monitor.setOffset(value);
136: }
137:
138: public Number getModulus() {
139: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
140: return monitor.getModulus();
141: }
142:
143: public void setModulus(Number value)
144: throws java.lang.IllegalArgumentException {
145: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
146: monitor.setModulus(value);
147: }
148:
149: public boolean getNotify() {
150: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
151: return monitor.getNotify();
152: }
153:
154: public void setNotify(boolean value) {
155: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
156: monitor.setNotify(value);
157: }
158:
159: public boolean getDifferenceMode() {
160: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
161: return monitor.getDifferenceMode();
162: }
163:
164: public void setDifferenceMode(boolean value) {
165: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
166: monitor.setDifferenceMode(value);
167: }
168:
169: public MBeanNotificationInfo[] getNotificationInfo() {
170: MX4JCounterMonitor monitor = (MX4JCounterMonitor) getMX4JMonitor();
171: return monitor.getNotificationInfo();
172: }
173: }
|