1 7 8 package javax.management; 9 10 import java.io.IOException ; 11 import java.io.ObjectInputStream ; 12 import java.io.ObjectOutputStream ; 13 import java.io.ObjectStreamField ; 14 15 import java.util.Date ; 16 import java.util.EventObject ; 17 18 import java.security.AccessController ; 19 import java.security.PrivilegedAction ; 20 21 import com.sun.jmx.mbeanserver.GetPropertyAction; 22 23 39 public class Notification extends EventObject { 40 41 private static final long oldSerialVersionUID = 1716977971058914352L; 49 private static final long newSerialVersionUID = -7516092053498031989L; 52 private static final ObjectStreamField [] oldSerialPersistentFields = 55 { 56 new ObjectStreamField ("message", String .class), 57 new ObjectStreamField ("sequenceNumber", Long.TYPE), 58 new ObjectStreamField ("source", Object .class), 59 new ObjectStreamField ("sourceObjectName", ObjectName .class), 60 new ObjectStreamField ("timeStamp", Long.TYPE), 61 new ObjectStreamField ("type", String .class), 62 new ObjectStreamField ("userData", Object .class) 63 }; 64 private static final ObjectStreamField [] newSerialPersistentFields = 67 { 68 new ObjectStreamField ("message", String .class), 69 new ObjectStreamField ("sequenceNumber", Long.TYPE), 70 new ObjectStreamField ("source", Object .class), 71 new ObjectStreamField ("timeStamp", Long.TYPE), 72 new ObjectStreamField ("type", String .class), 73 new ObjectStreamField ("userData", Object .class) 74 }; 75 private static final long serialVersionUID; 78 93 private static final ObjectStreamField [] serialPersistentFields; 94 private static boolean compat = false; 95 static { 96 try { 97 PrivilegedAction act = new GetPropertyAction("jmx.serial.form"); 98 String form = (String ) AccessController.doPrivileged(act); 99 compat = (form != null && form.equals("1.0")); 100 } catch (Exception e) { 101 } 103 if (compat) { 104 serialPersistentFields = oldSerialPersistentFields; 105 serialVersionUID = oldSerialVersionUID; 106 } else { 107 serialPersistentFields = newSerialPersistentFields; 108 serialVersionUID = newSerialVersionUID; 109 } 110 } 111 114 119 private String type; 120 121 126 private long sequenceNumber; 127 128 132 private long timeStamp; 133 134 139 private Object userData = null; 140 141 144 private String message = ""; 145 146 153 protected Object source = null; 154 155 156 165 public Notification(String type, Object source, long sequenceNumber) { 166 super (source) ; 167 this.source = source; 168 this.type = type; 169 this.sequenceNumber = sequenceNumber ; 170 this.timeStamp = (new java.util.Date ()).getTime() ; 171 } 172 173 183 public Notification(String type, Object source, long sequenceNumber, String message) { 184 super (source) ; 185 this.source = source; 186 this.type = type; 187 this.sequenceNumber = sequenceNumber ; 188 this.timeStamp = (new java.util.Date ()).getTime() ; 189 this.message = message ; 190 } 191 192 201 public Notification(String type, Object source, long sequenceNumber, long timeStamp) { 202 super (source) ; 203 this.source = source; 204 this.type = type ; 205 this.sequenceNumber = sequenceNumber ; 206 this.timeStamp = timeStamp ; 207 } 208 209 219 public Notification(String type, Object source, long sequenceNumber, long timeStamp, String message) { 220 super (source) ; 221 this.source = source; 222 this.type = type ; 223 this.sequenceNumber = sequenceNumber ; 224 this.timeStamp = timeStamp ; 225 this.message = message ; 226 } 227 228 235 public void setSource(Object source) { 236 super.source = source; 237 this.source = source; 238 } 239 240 250 public long getSequenceNumber() { 251 return sequenceNumber ; 252 } 253 254 263 public void setSequenceNumber(long sequenceNumber) { 264 this.sequenceNumber = sequenceNumber; 265 } 266 267 273 public String getType() { 274 return type ; 275 } 276 277 284 public long getTimeStamp() { 285 return timeStamp ; 286 } 287 288 295 public void setTimeStamp(long timeStamp) { 296 this.timeStamp = timeStamp; 297 } 298 299 306 public String getMessage() { 307 return message ; 308 } 309 310 318 public Object getUserData() { 319 return userData ; 320 } 321 322 330 public void setUserData(Object userData) { 331 332 this.userData = userData ; 333 } 334 335 340 public String toString() { 341 return super.toString()+"[type="+type+"][message="+message+"]"; 342 } 343 344 347 private void readObject(ObjectInputStream in) 348 throws IOException , ClassNotFoundException { 349 in.defaultReadObject(); 351 super.source = source; 352 } 353 354 355 358 private void writeObject(ObjectOutputStream out) 359 throws IOException { 360 if (compat) { 361 ObjectOutputStream.PutField fields = out.putFields(); 364 fields.put("type", type); 365 fields.put("sequenceNumber", sequenceNumber); 366 fields.put("timeStamp", timeStamp); 367 fields.put("userData", userData); 368 fields.put("message", message); 369 fields.put("source", source); 370 out.writeFields(); 371 } else { 372 out.defaultWriteObject(); 375 } 376 } 377 } 378 | Popular Tags |