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.MX4JMonitor;
018: import mx4j.monitor.MX4JStringMonitor;
019:
020: /**
021: * @version $Revision: 1.8 $
022: */
023: public class StringMonitor extends Monitor implements
024: StringMonitorMBean {
025: private static final MBeanNotificationInfo[] notificationInfos = { new MBeanNotificationInfo(
026: new String[] {
027: javax.management.monitor.MonitorNotification.RUNTIME_ERROR,
028: MonitorNotification.OBSERVED_OBJECT_ERROR,
029: MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
030: MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
031: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED,
032: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED },
033: MonitorNotification.class.getName(),
034: "Notifications sent by the StringMonitor MBean") };
035:
036: MX4JMonitor createMX4JMonitor() {
037: try {
038: return new MX4JStringMonitor() {
039: protected NotificationBroadcasterSupport createNotificationEmitter() {
040: return StringMonitor.this ;
041: }
042:
043: public MBeanNotificationInfo[] getNotificationInfo() {
044: return notificationInfos;
045: }
046:
047: protected Notification createMonitorNotification(
048: String type, long sequence, String message,
049: ObjectName observed, String attribute,
050: Object gauge, Object trigger) {
051: return new MonitorNotification(type, this ,
052: sequence, System.currentTimeMillis(),
053: message, observed, attribute, gauge,
054: trigger);
055: }
056: };
057: } catch (NotCompliantMBeanException x) {
058: return null;
059: }
060: }
061:
062: public void start() {
063: MX4JMonitor monitor = getMX4JMonitor();
064: monitor.start();
065: }
066:
067: public void stop() {
068: MX4JMonitor monitor = getMX4JMonitor();
069: monitor.stop();
070: }
071:
072: /**
073: * @deprecated
074: */
075: public String getDerivedGauge() {
076: return getDerivedGauge(getObservedObject());
077: }
078:
079: /**
080: * @deprecated
081: */
082: public long getDerivedGaugeTimeStamp() {
083: return getDerivedGaugeTimeStamp(getObservedObject());
084: }
085:
086: public String getDerivedGauge(ObjectName objectName) {
087: MX4JStringMonitor monitor = (MX4JStringMonitor) getMX4JMonitor();
088: return monitor.getDerivedGauge(objectName);
089: }
090:
091: public long getDerivedGaugeTimeStamp(ObjectName objectName) {
092: MX4JStringMonitor monitor = (MX4JStringMonitor) getMX4JMonitor();
093: return monitor.getDerivedGaugeTimeStamp(objectName);
094: }
095:
096: public String getStringToCompare() {
097: MX4JStringMonitor monitor = (MX4JStringMonitor) getMX4JMonitor();
098: return monitor.getStringToCompare();
099: }
100:
101: public void setStringToCompare(String value)
102: throws IllegalArgumentException {
103: MX4JStringMonitor monitor = (MX4JStringMonitor) getMX4JMonitor();
104: monitor.setStringToCompare(value);
105: }
106:
107: public boolean getNotifyMatch() {
108: MX4JStringMonitor monitor = (MX4JStringMonitor) getMX4JMonitor();
109: return monitor.getNotifyMatch();
110: }
111:
112: public void setNotifyMatch(boolean value) {
113: MX4JStringMonitor monitor = (MX4JStringMonitor) getMX4JMonitor();
114: monitor.setNotifyMatch(value);
115: }
116:
117: public boolean getNotifyDiffer() {
118: MX4JStringMonitor monitor = (MX4JStringMonitor) getMX4JMonitor();
119: return monitor.getNotifyDiffer();
120: }
121:
122: public void setNotifyDiffer(boolean value) {
123: MX4JStringMonitor monitor = (MX4JStringMonitor) getMX4JMonitor();
124: monitor.setNotifyDiffer(value);
125: }
126:
127: public MBeanNotificationInfo[] getNotificationInfo() {
128: MX4JStringMonitor monitor = (MX4JStringMonitor) getMX4JMonitor();
129: return monitor.getNotificationInfo();
130: }
131: }
|