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;
010:
011: import java.io.IOException;
012: import java.io.ObjectInputStream;
013: import java.util.EventObject;
014:
015: /**
016: * Notifications are events emitted by {@link NotificationEmitter}s
017: *
018: * @version $Revision: 1.8 $
019: */
020: public class Notification extends EventObject {
021: private static final long serialVersionUID = -7516092053498031989L;
022:
023: /**
024: * @serial The notification type
025: */
026: private String type;
027: /**
028: * @serial The notification sequence number
029: */
030: private long sequenceNumber;
031: /**
032: * @serial The notification timestamp
033: */
034: private long timeStamp;
035: /**
036: * @serial The notification message
037: */
038: private String message;
039: /**
040: * @serial The notification user data
041: */
042: private Object userData;
043: /**
044: * A duplicate for the existing data member in EventObject: this one is not transient and should hold only
045: * ObjectNames (so they are Serializable and can be sent along the wire for remote notifications), and it's
046: * protected and not private for a mistake in JMX 1.0, but for binary compatibility we leave it protected.
047: *
048: * @serial The ObjectName of the emitter MBean
049: */
050: protected Object source;
051:
052: /**
053: * Convenience constructor for <code>Notification(type, source, sequenceNumber, System.currentTimeMillis(), null)</code>
054: *
055: * @see #Notification(String, Object, long, long, String)
056: */
057: public Notification(String type, Object source, long sequenceNumber) {
058: this (type, source, sequenceNumber, System.currentTimeMillis(),
059: null);
060: }
061:
062: /**
063: * Convenience constructor for <code>Notification(type, source, sequenceNumber, timestamp, null)</code>
064: *
065: * @see #Notification(String, Object, long, long, String)
066: */
067: public Notification(String type, Object source,
068: long sequenceNumber, long timeStamp) {
069: this (type, source, sequenceNumber, timeStamp, null);
070: }
071:
072: /**
073: * Convenience constructor for <code>Notification(type, source, sequenceNumber, System.currentTimeMillis(), message)</code>
074: *
075: * @see #Notification(String, Object, long, long, String)
076: */
077: public Notification(String type, Object source,
078: long sequenceNumber, String message) {
079: this (type, source, sequenceNumber, System.currentTimeMillis(),
080: message);
081: }
082:
083: /**
084: * Creates a new Notification
085: *
086: * @param type The notification type
087: * @param source The ObjectName of the emitter MBean
088: * @param sequenceNumber The Notification sequence number
089: * @param timeStamp The notification timestamp
090: * @param message The Notification message
091: */
092: public Notification(String type, Object source,
093: long sequenceNumber, long timeStamp, String message) {
094: // Data member source of EventObject is transient
095: super (source);
096: this .source = source;
097: this .type = type;
098: this .sequenceNumber = sequenceNumber;
099: this .timeStamp = timeStamp;
100: this .message = message;
101: }
102:
103: /**
104: * Returns the notification message
105: */
106: public String getMessage() {
107: return message;
108: }
109:
110: /**
111: * Returns the notification type
112: */
113: public String getType() {
114: return type;
115: }
116:
117: /**
118: * Returns the notification source
119: *
120: * @see #setSource
121: */
122: public Object getSource() {
123: return this .source;
124: }
125:
126: /**
127: * Sets the notification source
128: *
129: * @see #getSource
130: */
131: public void setSource(Object source) {
132: this .source = source;
133: }
134:
135: /**
136: * Returns the notification sequence number
137: *
138: * @see #setSequenceNumber
139: */
140: public long getSequenceNumber() {
141: return sequenceNumber;
142: }
143:
144: /**
145: * Sets the notification sequence number
146: *
147: * @see #getSequenceNumber
148: */
149: public void setSequenceNumber(long sequenceNumber) {
150: this .sequenceNumber = sequenceNumber;
151: }
152:
153: /**
154: * Returns the notification timestamp
155: *
156: * @see #setTimeStamp
157: */
158: public long getTimeStamp() {
159: return timeStamp;
160: }
161:
162: /**
163: * Sets the notification timestamp
164: *
165: * @see #getTimeStamp
166: */
167: public void setTimeStamp(long timeStamp) {
168: this .timeStamp = timeStamp;
169: }
170:
171: /**
172: * Returns the notification user data
173: *
174: * @see #setUserData
175: */
176: public Object getUserData() {
177: return userData;
178: }
179:
180: /**
181: * Sets the notification user data
182: *
183: * @see #getUserData
184: */
185: public void setUserData(Object userData) {
186: this .userData = userData;
187: }
188:
189: public String toString() {
190: StringBuffer b = new StringBuffer("[");
191: b.append("source=").append(getSource()).append(", ");
192: b.append("message=").append(getMessage()).append(", ");
193: b.append("sequence=").append(getSequenceNumber()).append(", ");
194: b.append("type=").append(getType()).append(", ");
195: b.append("time=").append(getTimeStamp()).append(", ");
196: b.append("data=").append(getUserData());
197: b.append("]");
198: return b.toString();
199: }
200:
201: private void readObject(ObjectInputStream in) throws IOException,
202: ClassNotFoundException {
203: in.defaultReadObject();
204: // EventObject data member is transient
205: super.source = source;
206: }
207: }
|