001: /* JFox, the OpenSource J2EE Application Server
002: *
003: * Copyright (C) 2002 huihoo.org
004: * Distributable under GNU LGPL license
005: * See the GNU Lesser General Public License for more details.
006: */
007:
008: package javax.management;
009:
010: import java.util.EventObject;
011: import java.io.ObjectInputStream;
012: import java.io.IOException;
013: import java.io.ObjectOutputStream;
014:
015: /**
016: * The Notification class represents a notification emitted by an MBean.
017: * It contains a reference to the source MBean: if the notification has been forwarded through the MBean server,
018: * this is the object name of the MBean. If the listener has registered directly with the MBean, this is a direct reference
019: * to the MBean.
020: *
021: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
022: */
023:
024: public class Notification extends EventObject {
025:
026: /**
027: * The notification type. A string expressed in a dot notation similar to Java properties.
028: * An example of a notification type is network.alarm.router
029: */
030: private String type;
031:
032: /**
033: * The notification sequence number. A serial number which identify particular instance
034: * of notification in the context of the notification source.
035: */
036: private long sequenceNumber;
037:
038: /**
039: * The notification timestamp. Indicating when the notification was generated
040: */
041: private long timeStamp;
042:
043: /**
044: * The notification user data. Used for whatever other data the notification
045: * source wishes to communicate to its consumers
046: */
047: private Object userData = null;
048:
049: /**
050: * The notification message.
051: */
052: private String message = new String();
053:
054: /**
055: * The ObjectName source
056: */
057: private ObjectName sourceObjectName = null;
058:
059: /**
060: * The object on which the notification initially occurred.
061: */
062: protected Object source = null;
063:
064: /**
065: * Creates a Notification object.
066: * The notification timeStamp is set to the curent date.
067: *
068: * @param type The notification type.
069: * @param source The notification source.
070: * @param sequenceNumber The notification sequence number within the source object.
071: *
072: */
073: public Notification(String type, Object source, long sequenceNumber) {
074: super (source);
075: this .source = source;
076: this .type = type;
077: this .sequenceNumber = sequenceNumber;
078: this .timeStamp = (new java.util.Date()).getTime();
079: }
080:
081: /**
082: * Creates a Notification object.
083: * The notification timeStamp is set to the curent date.
084: *
085: * @param type The notification type.
086: * @param source The notification source.
087: * @param sequenceNumber The notification sequence number within the source object.
088: * @param message The detailed message.
089: *
090: */
091: public Notification(String type, Object source,
092: long sequenceNumber, String message) {
093: super (source);
094: this .source = source;
095: this .type = type;
096: this .sequenceNumber = sequenceNumber;
097: this .timeStamp = (new java.util.Date()).getTime();
098: this .message = message;
099: }
100:
101: /**
102: * Creates a Notification object.
103: *
104: * @param type The notification type.
105: * @param source The notification source.
106: * @param sequenceNumber The notification sequence number within the source object.
107: * @param timeStamp The notification emission date.
108: *
109: */
110: public Notification(String type, Object source,
111: long sequenceNumber, long timeStamp) {
112: super (source);
113: this .source = source;
114: this .type = type;
115: this .sequenceNumber = sequenceNumber;
116: this .timeStamp = timeStamp;
117: }
118:
119: /**
120: * Creates a Notification object.
121: *
122: * @param type The notification type.
123: * @param source The notification source.
124: * @param sequenceNumber The notification sequence number within the source object.
125: * @param timeStamp The notification emission date.
126: * @param message The detailed message.
127: *
128: */
129: public Notification(String type, Object source,
130: long sequenceNumber, long timeStamp, String message) {
131: super (source);
132: this .source = source;
133: this .type = type;
134: this .sequenceNumber = sequenceNumber;
135: this .timeStamp = timeStamp;
136: this .message = message;
137: }
138:
139: /**
140: * Get the source object name
141: *
142: *@return The MBean object name on which the notification initially occurred.
143: *
144: */
145: public Object getSource() {
146: if (sourceObjectName == null) {
147: return source;
148: } else {
149: return sourceObjectName;
150: }
151: }
152:
153: /**
154: * Set the source object name
155: *
156: * @exception java.lang.IllegalArgumentException The source is not a ObjectName
157: *
158: */
159: public void setSource(Object source)
160: throws java.lang.IllegalArgumentException {
161: if (!(source instanceof ObjectName)) {
162: throw new java.lang.IllegalArgumentException();
163: }
164: this .sourceObjectName = (ObjectName) source;
165: this .source = source;
166: }
167:
168: /**
169: * Get the notification sequence number.
170: *
171: * @return The notification sequence number within the source object. It's a serial number
172: * identifying a particular instance of notification in the context of the notification source.
173: * The notification model does not assume that notifications will be received in the same order
174: * that they are sent. The sequence number helps listeners to sort received notifications.
175: *
176: */
177: public long getSequenceNumber() {
178: return sequenceNumber;
179: }
180:
181: /**
182: * Set the notification sequence number.
183: *
184: * @param sequenceNumber The notification sequence number within the source object. It is
185: * a serial number identifying a particular instance of notification in the
186: * context of the notification source.
187: *
188: */
189: public void setSequenceNumber(long sequenceNumber) {
190: this .sequenceNumber = sequenceNumber;
191: }
192:
193: /**
194: * Get the notification type.
195: *
196: * @return The notification type. It's a string expressed in a dot notation similar
197: * to Java properties. An example of a notification type is network.alarm.router .
198: *
199: */
200: public String getType() {
201: return type;
202: }
203:
204: /**
205: * Get the notification timestamp.
206: *
207: * @return The notification timestamp.
208: *
209: */
210: public long getTimeStamp() {
211: return timeStamp;
212: }
213:
214: /**
215: * Set the notification timestamp.
216: *
217: * @param timeStamp The notification timestamp. It indicates when the notification was generated.
218: *
219: */
220: public void setTimeStamp(long timeStamp) {
221: this .timeStamp = timeStamp;
222: }
223:
224: /**
225: * Get the notification message.
226: *
227: * @return The message string of this notification object. It contains in a string,
228: * which could be the explanation of the notification for displaying to a user
229: *
230: */
231: public String getMessage() {
232: return message;
233: }
234:
235: /**
236: * Get the user data.
237: *
238: * @return The user data object. It is used for whatever data
239: * the notification source wishes to communicate to its consumers.
240: *
241: */
242: public Object getUserData() {
243: return userData;
244: }
245:
246: /**
247: * Set the user data.
248: *
249: * @param userData The user data object. It is used for whatever data
250: * the notification source wishes to communicate to its consumers.
251: *
252: */
253: public void setUserData(Object userData) {
254: this .userData = userData;
255: }
256:
257: private void readObject(ObjectInputStream in) throws IOException,
258: ClassNotFoundException {
259: in.defaultReadObject();
260: super .source = source;
261: }
262:
263: private void writeObject(ObjectOutputStream out) throws IOException {
264: out.defaultWriteObject();
265: }
266:
267: }
|