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.MX4JGaugeMonitor;
018: import mx4j.monitor.MX4JMonitor;
019:
020: /**
021: * @version $Revision: 1.13 $
022: */
023: public class GaugeMonitor extends Monitor implements GaugeMonitorMBean {
024: private static final MBeanNotificationInfo[] notificationInfos = { new MBeanNotificationInfo(
025: new String[] { MonitorNotification.RUNTIME_ERROR,
026: MonitorNotification.OBSERVED_OBJECT_ERROR,
027: MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
028: MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
029: MonitorNotification.THRESHOLD_ERROR,
030: MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED,
031: MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED },
032: MonitorNotification.class.getName(),
033: "Notifications sent by the GaugeMonitor MBean") };
034:
035: MX4JMonitor createMX4JMonitor() {
036: try {
037: return new MX4JGaugeMonitor() {
038: protected NotificationBroadcasterSupport createNotificationEmitter() {
039: return GaugeMonitor.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: public Number getDerivedGauge(ObjectName objectName) {
086: MX4JGaugeMonitor monitor = (MX4JGaugeMonitor) getMX4JMonitor();
087: return monitor.getDerivedGauge(objectName);
088: }
089:
090: public long getDerivedGaugeTimeStamp(ObjectName objectName) {
091: MX4JGaugeMonitor monitor = (MX4JGaugeMonitor) getMX4JMonitor();
092: return monitor.getDerivedGaugeTimeStamp(objectName);
093: }
094:
095: public Number getHighThreshold() {
096: MX4JGaugeMonitor monitor = (MX4JGaugeMonitor) getMX4JMonitor();
097: return monitor.getHighThreshold();
098: }
099:
100: public Number getLowThreshold() {
101: MX4JGaugeMonitor monitor = (MX4JGaugeMonitor) getMX4JMonitor();
102: return monitor.getLowThreshold();
103: }
104:
105: public void setThresholds(Number highValue, Number lowValue)
106: throws IllegalArgumentException {
107: MX4JGaugeMonitor monitor = (MX4JGaugeMonitor) getMX4JMonitor();
108: monitor.setThresholds(highValue, lowValue);
109: }
110:
111: public boolean getNotifyHigh() {
112: MX4JGaugeMonitor monitor = (MX4JGaugeMonitor) getMX4JMonitor();
113: return monitor.getNotifyHigh();
114: }
115:
116: public void setNotifyHigh(boolean value) {
117: MX4JGaugeMonitor monitor = (MX4JGaugeMonitor) getMX4JMonitor();
118: monitor.setNotifyHigh(value);
119: }
120:
121: public boolean getNotifyLow() {
122: MX4JGaugeMonitor monitor = (MX4JGaugeMonitor) getMX4JMonitor();
123: return monitor.getNotifyLow();
124: }
125:
126: public void setNotifyLow(boolean value) {
127: MX4JGaugeMonitor monitor = (MX4JGaugeMonitor) getMX4JMonitor();
128: monitor.setNotifyLow(value);
129: }
130:
131: public boolean getDifferenceMode() {
132: MX4JGaugeMonitor monitor = (MX4JGaugeMonitor) getMX4JMonitor();
133: return monitor.getDifferenceMode();
134: }
135:
136: public void setDifferenceMode(boolean value) {
137: MX4JGaugeMonitor monitor = (MX4JGaugeMonitor) getMX4JMonitor();
138: monitor.setDifferenceMode(value);
139: }
140:
141: public MBeanNotificationInfo[] getNotificationInfo() {
142: MX4JGaugeMonitor monitor = (MX4JGaugeMonitor) getMX4JMonitor();
143: return monitor.getNotificationInfo();
144: }
145: }
|