0N/A/*
2362N/A * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.management;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.ObjectStreamField;
0N/Aimport java.util.EventObject;
0N/A
0N/Aimport java.security.AccessController;
0N/A
0N/Aimport com.sun.jmx.mbeanserver.GetPropertyAction;
0N/A
0N/A/**
0N/A * <p>The Notification class represents a notification emitted by an
0N/A * MBean. It contains a reference to the source MBean: if the
0N/A * notification has been forwarded through the MBean server, and the
0N/A * original source of the notification was a reference to the emitting
0N/A * MBean object, then the MBean server replaces it by the MBean's
0N/A * ObjectName. If the listener has registered directly with the
0N/A * MBean, this is either the object name or a direct reference to the
0N/A * MBean.</p>
0N/A *
0N/A * <p>It is strongly recommended that notification senders use the
0N/A * object name rather than a reference to the MBean object as the
0N/A * source.</p>
0N/A *
0N/A * <p>The <b>serialVersionUID</b> of this class is <code>-7516092053498031989L</code>.
0N/A *
0N/A * @since 1.5
0N/A */
0N/A@SuppressWarnings("serial") // serialVersionUID is not constant
1790N/Apublic class Notification extends EventObject {
0N/A
0N/A // Serialization compatibility stuff:
0N/A // Two serial forms are supported in this class. The selected form depends
0N/A // on system property "jmx.serial.form":
0N/A // - "1.0" for JMX 1.0
0N/A // - any other value for JMX 1.1 and higher
0N/A //
0N/A // Serial version for old serial form
0N/A private static final long oldSerialVersionUID = 1716977971058914352L;
0N/A //
0N/A // Serial version for new serial form
0N/A private static final long newSerialVersionUID = -7516092053498031989L;
0N/A //
0N/A // Serializable fields in old serial form
0N/A private static final ObjectStreamField[] oldSerialPersistentFields =
0N/A {
0N/A new ObjectStreamField("message", String.class),
0N/A new ObjectStreamField("sequenceNumber", Long.TYPE),
0N/A new ObjectStreamField("source", Object.class),
0N/A new ObjectStreamField("sourceObjectName", ObjectName.class),
0N/A new ObjectStreamField("timeStamp", Long.TYPE),
0N/A new ObjectStreamField("type", String.class),
0N/A new ObjectStreamField("userData", Object.class)
0N/A };
0N/A //
0N/A // Serializable fields in new serial form
0N/A private static final ObjectStreamField[] newSerialPersistentFields =
0N/A {
0N/A new ObjectStreamField("message", String.class),
0N/A new ObjectStreamField("sequenceNumber", Long.TYPE),
0N/A new ObjectStreamField("source", Object.class),
0N/A new ObjectStreamField("timeStamp", Long.TYPE),
0N/A new ObjectStreamField("type", String.class),
0N/A new ObjectStreamField("userData", Object.class)
0N/A };
0N/A //
0N/A // Actual serial version and serial form
0N/A private static final long serialVersionUID;
0N/A /**
0N/A * @serialField type String The notification type.
0N/A * A string expressed in a dot notation similar to Java properties.
0N/A * An example of a notification type is network.alarm.router
0N/A * @serialField sequenceNumber long The notification sequence number.
0N/A * A serial number which identify particular instance
0N/A * of notification in the context of the notification source.
0N/A * @serialField timeStamp long The notification timestamp.
0N/A * Indicating when the notification was generated
0N/A * @serialField userData Object The notification user data.
0N/A * Used for whatever other data the notification
0N/A * source wishes to communicate to its consumers
0N/A * @serialField message String The notification message.
0N/A * @serialField source Object The object on which the notification initially occurred.
0N/A */
0N/A private static final ObjectStreamField[] serialPersistentFields;
0N/A private static boolean compat = false;
0N/A static {
0N/A try {
0N/A GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
0N/A String form = AccessController.doPrivileged(act);
0N/A compat = (form != null && form.equals("1.0"));
0N/A } catch (Exception e) {
0N/A // OK: exception means no compat with 1.0, too bad
0N/A }
0N/A if (compat) {
0N/A serialPersistentFields = oldSerialPersistentFields;
0N/A serialVersionUID = oldSerialVersionUID;
0N/A } else {
0N/A serialPersistentFields = newSerialPersistentFields;
0N/A serialVersionUID = newSerialVersionUID;
0N/A }
0N/A }
0N/A //
0N/A // END Serialization compatibility stuff
0N/A
0N/A /**
0N/A * @serial The notification type.
0N/A * A string expressed in a dot notation similar to Java properties.
0N/A * An example of a notification type is network.alarm.router
0N/A */
0N/A private String type;
0N/A
0N/A /**
0N/A * @serial The notification sequence number.
0N/A * A serial number which identify particular instance
0N/A * of notification in the context of the notification source.
0N/A */
0N/A private long sequenceNumber;
0N/A
0N/A /**
0N/A * @serial The notification timestamp.
0N/A * Indicating when the notification was generated
0N/A */
0N/A private long timeStamp;
0N/A
0N/A /**
0N/A * @serial The notification user data.
0N/A * Used for whatever other data the notification
0N/A * source wishes to communicate to its consumers
0N/A */
0N/A private Object userData = null;
0N/A
0N/A /**
0N/A * @serial The notification message.
0N/A */
0N/A private String message = "";
0N/A
0N/A /**
0N/A * <p>This field hides the {@link EventObject#source} field in the
0N/A * parent class to make it non-transient and therefore part of the
0N/A * serialized form.</p>
0N/A *
0N/A * @serial The object on which the notification initially occurred.
0N/A */
0N/A protected Object source = null;
0N/A
0N/A
0N/A /**
0N/A * Creates a Notification object.
0N/A * The notification timeStamp is set to the current date.
0N/A *
0N/A * @param type The notification type.
0N/A * @param source The notification source.
0N/A * @param sequenceNumber The notification sequence number within the source object.
0N/A *
0N/A */
0N/A public Notification(String type, Object source, long sequenceNumber) {
0N/A super (source) ;
0N/A this.source = source;
0N/A this.type = type;
0N/A this.sequenceNumber = sequenceNumber ;
0N/A this.timeStamp = (new java.util.Date()).getTime() ;
0N/A }
0N/A
0N/A /**
0N/A * Creates a Notification object.
0N/A * The notification timeStamp is set to the current date.
0N/A *
0N/A * @param type The notification type.
0N/A * @param source The notification source.
0N/A * @param sequenceNumber The notification sequence number within the source object.
0N/A * @param message The detailed message.
0N/A *
0N/A */
0N/A public Notification(String type, Object source, long sequenceNumber, String message) {
0N/A super (source) ;
0N/A this.source = source;
0N/A this.type = type;
0N/A this.sequenceNumber = sequenceNumber ;
0N/A this.timeStamp = (new java.util.Date()).getTime() ;
0N/A this.message = message ;
0N/A }
0N/A
0N/A /**
0N/A * Creates a Notification object.
0N/A *
0N/A * @param type The notification type.
0N/A * @param source The notification source.
0N/A * @param sequenceNumber The notification sequence number within the source object.
0N/A * @param timeStamp The notification emission date.
0N/A *
0N/A */
0N/A public Notification(String type, Object source, long sequenceNumber, long timeStamp) {
0N/A super (source) ;
0N/A this.source = source;
0N/A this.type = type ;
0N/A this.sequenceNumber = sequenceNumber ;
0N/A this.timeStamp = timeStamp ;
0N/A }
0N/A
0N/A /**
0N/A * Creates a Notification object.
0N/A *
0N/A * @param type The notification type.
0N/A * @param source The notification source.
0N/A * @param sequenceNumber The notification sequence number within the source object.
0N/A * @param timeStamp The notification emission date.
0N/A * @param message The detailed message.
0N/A *
0N/A */
0N/A public Notification(String type, Object source, long sequenceNumber, long timeStamp, String message) {
0N/A super (source) ;
0N/A this.source = source;
0N/A this.type = type ;
0N/A this.sequenceNumber = sequenceNumber ;
0N/A this.timeStamp = timeStamp ;
0N/A this.message = message ;
0N/A }
0N/A
0N/A /**
0N/A * Sets the source.
0N/A *
0N/A * @param source the new source for this object.
0N/A *
0N/A * @see EventObject#getSource
0N/A */
0N/A public void setSource(Object source) {
0N/A super.source = source;
0N/A this.source = source;
0N/A }
0N/A
0N/A /**
0N/A * Get the notification sequence number.
0N/A *
0N/A * @return The notification sequence number within the source object. It's a serial number
0N/A * identifying a particular instance of notification in the context of the notification source.
0N/A * The notification model does not assume that notifications will be received in the same order
0N/A * that they are sent. The sequence number helps listeners to sort received notifications.
0N/A *
0N/A * @see #setSequenceNumber
0N/A */
0N/A public long getSequenceNumber() {
0N/A return sequenceNumber ;
0N/A }
0N/A
0N/A /**
0N/A * Set the notification sequence number.
0N/A *
0N/A * @param sequenceNumber The notification sequence number within the source object. It is
0N/A * a serial number identifying a particular instance of notification in the
0N/A * context of the notification source.
0N/A *
0N/A * @see #getSequenceNumber
0N/A */
0N/A public void setSequenceNumber(long sequenceNumber) {
0N/A this.sequenceNumber = sequenceNumber;
0N/A }
0N/A
0N/A /**
0N/A * Get the notification type.
0N/A *
699N/A * @return The notification type. It's a string expressed in a dot notation
699N/A * similar to Java properties. It is recommended that the notification type
699N/A * should follow the reverse-domain-name convention used by Java package
699N/A * names. An example of a notification type is com.example.alarm.router.
0N/A */
0N/A public String getType() {
0N/A return type ;
0N/A }
0N/A
0N/A /**
0N/A * Get the notification timestamp.
0N/A *
0N/A * @return The notification timestamp.
0N/A *
0N/A * @see #setTimeStamp
0N/A */
0N/A public long getTimeStamp() {
0N/A return timeStamp ;
0N/A }
0N/A
0N/A /**
0N/A * Set the notification timestamp.
0N/A *
0N/A * @param timeStamp The notification timestamp. It indicates when the notification was generated.
0N/A *
0N/A * @see #getTimeStamp
0N/A */
0N/A public void setTimeStamp(long timeStamp) {
0N/A this.timeStamp = timeStamp;
0N/A }
0N/A
0N/A /**
0N/A * Get the notification message.
0N/A *
699N/A * @return The message string of this notification object.
0N/A *
0N/A */
0N/A public String getMessage() {
0N/A return message ;
0N/A }
0N/A
0N/A /**
0N/A * Get the user data.
0N/A *
0N/A * @return The user data object. It is used for whatever data
0N/A * the notification source wishes to communicate to its consumers.
0N/A *
0N/A * @see #setUserData
0N/A */
0N/A public Object getUserData() {
0N/A return userData ;
0N/A }
0N/A
0N/A /**
0N/A * Set the user data.
0N/A *
0N/A * @param userData The user data object. It is used for whatever data
0N/A * the notification source wishes to communicate to its consumers.
0N/A *
0N/A * @see #getUserData
0N/A */
0N/A public void setUserData(Object userData) {
0N/A
0N/A this.userData = userData ;
0N/A }
0N/A
0N/A /**
0N/A * Returns a String representation of this notification.
0N/A *
0N/A * @return A String representation of this notification.
0N/A */
699N/A @Override
0N/A public String toString() {
0N/A return super.toString()+"[type="+type+"][message="+message+"]";
0N/A }
0N/A
0N/A /**
0N/A * Deserializes a {@link Notification} from an {@link ObjectInputStream}.
0N/A */
0N/A private void readObject(ObjectInputStream in)
0N/A throws IOException, ClassNotFoundException {
0N/A // New serial form ignores extra field "sourceObjectName"
0N/A in.defaultReadObject();
0N/A super.source = source;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Serializes a {@link Notification} to an {@link ObjectOutputStream}.
0N/A */
0N/A private void writeObject(ObjectOutputStream out)
0N/A throws IOException {
0N/A if (compat) {
0N/A // Serializes this instance in the old serial form
0N/A //
0N/A ObjectOutputStream.PutField fields = out.putFields();
0N/A fields.put("type", type);
0N/A fields.put("sequenceNumber", sequenceNumber);
0N/A fields.put("timeStamp", timeStamp);
0N/A fields.put("userData", userData);
0N/A fields.put("message", message);
0N/A fields.put("source", source);
0N/A out.writeFields();
0N/A } else {
0N/A // Serializes this instance in the new serial form
0N/A //
0N/A out.defaultWriteObject();
0N/A }
0N/A }
0N/A}