001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package javax.management.monitor;
023:
024: import javax.management.Notification;
025: import javax.management.ObjectName;
026:
027: /**
028: * A notification from one of the monitor services.<p>
029: *
030: * The notification occurs only when the state is first entered.<p>
031: *
032: * All monitor services produce the following notifications.
033: * <ul>
034: * <li> {@link #OBSERVED_OBJECT_ERROR} when the MBean is not registered.
035: * </li>
036: * <li> {@link #OBSERVED_ATTRIBUTE_ERROR} when the MBean's attribute does
037: * not exist.
038: * </li>
039: * <li> {@link #OBSERVED_ATTRIBUTE_TYPE_ERROR} when the MBean's attribute is
040: * not of the correct type for the monitor or the derived gauge value.
041: * </li>
042: * <li> {@link #RUNTIME_ERROR} for any other error.
043: * </li>
044: * </ul>
045: * The counter monitor produces the following notifications.
046: * <ul>
047: * <li> {@link #THRESHOLD_ERROR} when one of the monitors threshold vaues is
048: * of an incorrect type.
049: * </li>
050: * <li> {@link #THRESHOLD_VALUE_EXCEEDED} when the counter exceeds the
051: * threshold.
052: * </li>
053: * </ul>
054: * The gauge monitor produces the following notifications.
055: * <ul>
056: * <li> {@link #THRESHOLD_ERROR} when one of the monitors threshold vaues is
057: * of an incorrect type.
058: * </li>
059: * <li> {@link #THRESHOLD_HIGH_VALUE_EXCEEDED} when the attribute exceeds
060: * the high threshold value.
061: * </li>
062: * <li> {@link #THRESHOLD_LOW_VALUE_EXCEEDED} when the attribute exceeds
063: * the low threshold value.
064: * </li>
065: * </ul>
066: * The string monitor produces the following notifications.
067: * <ul>
068: * <li> {@link #STRING_TO_COMPARE_VALUE_DIFFERED} when the attribute no longer
069: * matches the specified value.
070: * </li>
071: * <li> {@link #STRING_TO_COMPARE_VALUE_DIFFERED} when the attribute matches
072: * the specified value.
073: * </li>
074: * </ul>
075: *
076: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>
077: * @version $Revision: 57200 $
078: *
079: * <p><b>Revisions:</b>
080: * <p><b>20020816 Adrian Brock:</b>
081: * <ul>
082: * <li> Serialization </li>
083: * </ul>
084: */
085: public class MonitorNotification extends Notification {
086: // Constants -----------------------------------------------------
087:
088: private static final long serialVersionUID = -4608189663661929204L;
089:
090: /**
091: * Notification type when an MBean doesn't contain the specified
092: * attribute. The observed object name and observed attribute name
093: * are sent in the notification.
094: */
095: public static final String OBSERVED_ATTRIBUTE_ERROR = "jmx.monitor.error.attribute";
096:
097: /**
098: * Notification type when an attribute is null or the attribute has
099: * an incorrect type for the monitor service. The observed object name
100: * and observed attribute name are sent in the notification.
101: */
102: public static final String OBSERVED_ATTRIBUTE_TYPE_ERROR = "jmx.monitor.error.type";
103:
104: /**
105: * Notification type when an MBean is not registered. The observed object
106: * name is sent in the notification.
107: */
108: public static final String OBSERVED_OBJECT_ERROR = "jmx.monitor.error.mbean";
109:
110: /**
111: * Notification type for any other error.
112: */
113: public static final String RUNTIME_ERROR = "jmx.monitor.error.runtime";
114:
115: /**
116: * Notification type when an attribute no longer matches the specified
117: * value of a StringMonitor. The observed object name, observed attribute
118: * name, derived gauge (actual value) and trigger (monitor value) are
119: * sent in the notification.
120: * REVIEW: Verify this.
121: */
122: public static final String STRING_TO_COMPARE_VALUE_DIFFERED = "jmx.monitor.string.differs";
123:
124: /**
125: * Notification type when an attribute changes to match the specified
126: * value of a StringMonitor. The observed object name, observed attribute
127: * name, derived gauge (actual value) and trigger (monitor value) are
128: * sent in the notification.
129: * REVIEW: Verify this.
130: */
131: public static final String STRING_TO_COMPARE_VALUE_MATCHED = "jmx.monitor.string.matches";
132:
133: /**
134: * Notification type when an attribute's threshold parameters (threshold,
135: * low threshold, high threshold, offset or modules) are not of the
136: * correct type. The observed object name and observed attribute
137: * are sent in the notification.
138: * REVIEW: Verify this.
139: */
140: public static final String THRESHOLD_ERROR = "jmx.monitor.error.threshold";
141: /**
142: * Notification type when a counter attribute changes to exceed the
143: * specified threshold value. The observed object name, observed attribute
144: * name, derived gauge (actual value) and trigger (threshold value) are
145: * sent in the notification.
146: * REVIEW: Verify this.
147: */
148: public static final String THRESHOLD_VALUE_EXCEEDED = "jmx.monitor.counter.threshold";
149:
150: /**
151: * Notification type when a guage attribute changes to exceed the
152: * specified threshold high value. The observed object name,
153: * observed attribute name, derived gauge (actual value) and
154: * trigger (threshold value) are sent in the notification.
155: * REVIEW: Verify this.
156: */
157: public static final String THRESHOLD_HIGH_VALUE_EXCEEDED = "jmx.monitor.gauge.high";
158:
159: /**
160: * Notification type when a gauge attribute changes to exceed the
161: * specified threshold low value. The observed object name,
162: * observed attribute name, derived gauge (actual value) and
163: * trigger (threshold value) are sent in the notification.
164: * REVIEW: Verify this.
165: */
166: public static final String THRESHOLD_LOW_VALUE_EXCEEDED = "jmx.monitor.gauge.low";
167:
168: // Attributes ----------------------------------------------------
169:
170: /**
171: * The derived gauge.
172: */
173: private Object derivedGauge;
174:
175: /**
176: * The observed attribute.
177: */
178: private String observedAttribute;
179:
180: /**
181: * The observed object.
182: */
183: private ObjectName observedObject;
184:
185: /**
186: * The trigger of the notification.
187: */
188: private Object trigger;
189:
190: // Static --------------------------------------------------------
191:
192: // Constructors --------------------------------------------------
193:
194: /**
195: * Construct a new monitor notification.
196: *
197: * @param type the notification type.
198: * @param source the notification source.
199: * @param sequenceNumber the notification sequence within the source object.
200: * @param timeStamp the time the notification was sent.
201: * @param message the detailed message.
202: * @param derivedGauge the actual value.
203: * @param observedAttribute the monitored attribute.
204: * @param observedObject the monitored MBean.
205: * @param trigger the value monitor value.
206: */
207: /*package*/MonitorNotification(String type, Object source,
208: long sequenceNumber, long timeStamp, String message,
209: Object derivedGauge, String observedAttribute,
210: ObjectName observedObject, Object trigger) {
211: super (type, source, sequenceNumber, timeStamp, message);
212: this .derivedGauge = derivedGauge;
213: this .observedAttribute = observedAttribute;
214: this .observedObject = observedObject;
215: this .trigger = trigger;
216: }
217:
218: // Public --------------------------------------------------------
219:
220: /**
221: * Retrieves the derived gauge. See each monitor service for
222: * the definition of this value.
223: *
224: * @return the derived gauge.
225: */
226: public Object getDerivedGauge() {
227: return derivedGauge;
228: }
229:
230: /**
231: * Retrieves the name of the attribute monitored.
232: *
233: * @return the name of the monitored attribute.
234: */
235: public String getObservedAttribute() {
236: return observedAttribute;
237: }
238:
239: /**
240: * Retrieves the name of the MBean monitored.
241: *
242: * @return the registered object name.
243: */
244: public ObjectName getObservedObject() {
245: return observedObject;
246: }
247:
248: /**
249: * Retrieves the trigger value of the notification. See each monitor
250: * service for the values that trigger notifications.
251: *
252: * @return the trigger.
253: */
254: public Object getTrigger() {
255: return trigger;
256: }
257:
258: // X implementation ----------------------------------------------
259:
260: // Notification overrides ----------------------------------------
261:
262: /**
263: * @return human readable string.
264: */
265: public String toString() {
266: StringBuffer buffer = new StringBuffer(100);
267: buffer.append(getClass().getName()).append(":");
268: buffer.append(" type=").append(getType());
269: buffer.append(" source=").append(getSource());
270: buffer.append(" sequence=").append(getSequenceNumber());
271: buffer.append(" time=").append(getTimeStamp());
272: buffer.append(" message=").append(getMessage());
273: buffer.append(" derivedGauge=").append(getDerivedGauge());
274: buffer.append(" observedAttribute=").append(
275: getObservedAttribute());
276: buffer.append(" observedObject=").append(getObservedObject());
277: buffer.append(" trigger=").append(getTrigger());
278: return buffer.toString();
279: }
280:
281: // Package protected ---------------------------------------------
282:
283: // Protected -----------------------------------------------------
284:
285: // Private -------------------------------------------------------
286:
287: // Inner classes -------------------------------------------------
288: }
|