jdk/src/share/classes/javax/management/Notification.java
author sjiang
Thu, 31 Jul 2008 15:31:13 +0200
changeset 1004 5ba8217eb504
parent 2 90ce3da70b43
child 1570 4165709c91e3
permissions -rw-r--r--
5108776: Add reliable event handling to the JMX API 6218920: API bug - impossible to delete last MBeanServerForwarder on a connector Reviewed-by: emcmanus
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectStreamField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.EventObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jmx.mbeanserver.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>The Notification class represents a notification emitted by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * MBean.  It contains a reference to the source MBean: if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * notification has been forwarded through the MBean server, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * original source of the notification was a reference to the emitting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * MBean object, then the MBean server replaces it by the MBean's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * ObjectName.  If the listener has registered directly with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * MBean, this is either the object name or a direct reference to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * MBean.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>It is strongly recommended that notification senders use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * object name rather than a reference to the MBean object as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * source.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>The <b>serialVersionUID</b> of this class is <code>-7516092053498031989L</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
@SuppressWarnings("serial")  // serialVersionUID is not constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public class Notification extends EventObject {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // Serialization compatibility stuff:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    // Two serial forms are supported in this class. The selected form depends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // on system property "jmx.serial.form":
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    //  - "1.0" for JMX 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    //  - any other value for JMX 1.1 and higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // Serial version for old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final long oldSerialVersionUID = 1716977971058914352L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // Serial version for new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final long newSerialVersionUID = -7516092053498031989L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // Serializable fields in old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static final ObjectStreamField[] oldSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        new ObjectStreamField("message", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        new ObjectStreamField("sequenceNumber", Long.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        new ObjectStreamField("source", Object.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        new ObjectStreamField("sourceObjectName", ObjectName.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        new ObjectStreamField("timeStamp", Long.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        new ObjectStreamField("type", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        new ObjectStreamField("userData", Object.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // Serializable fields in new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static final ObjectStreamField[] newSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        new ObjectStreamField("message", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        new ObjectStreamField("sequenceNumber", Long.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        new ObjectStreamField("source", Object.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        new ObjectStreamField("timeStamp", Long.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        new ObjectStreamField("type", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        new ObjectStreamField("userData", Object.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // Actual serial version and serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static final long serialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @serialField type String The notification type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *              A string expressed in a dot notation similar to Java properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *              An example of a notification type is network.alarm.router
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @serialField sequenceNumber long The notification sequence number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *              A serial number which identify particular instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *              of notification in the context of the notification source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @serialField timeStamp long The notification timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *              Indicating when the notification was generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @serialField userData Object The notification user data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *              Used for whatever other data the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *              source wishes to communicate to its consumers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @serialField message String The notification message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @serialField source Object The object on which the notification initially occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static final ObjectStreamField[] serialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private static boolean compat = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            String form = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            compat = (form != null && form.equals("1.0"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            // OK: exception means no compat with 1.0, too bad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            serialPersistentFields = oldSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            serialVersionUID = oldSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            serialPersistentFields = newSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            serialVersionUID = newSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    // END Serialization compatibility stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @serial The notification type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *         A string expressed in a dot notation similar to Java properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *         An example of a notification type is network.alarm.router
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @serial The notification sequence number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *         A serial number which identify particular instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *         of notification in the context of the notification source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private long sequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @serial The notification timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *         Indicating when the notification was generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private long timeStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @serial The notification user data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *         Used for whatever other data the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *         source wishes to communicate to its consumers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private Object userData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @serial The notification message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private String message  = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * <p>This field hides the {@link EventObject#source} field in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * parent class to make it non-transient and therefore part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * serialized form.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @serial The object on which the notification initially occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    protected Object source = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Creates a Notification object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * The notification timeStamp is set to the current date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param type The notification type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param source The notification source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param sequenceNumber The notification sequence number within the source object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public Notification(String type, Object source, long sequenceNumber) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        super (source) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        this.source = source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        this.sequenceNumber = sequenceNumber ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        this.timeStamp = (new java.util.Date()).getTime() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Creates a Notification object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * The notification timeStamp is set to the current date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param type The notification type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param source The notification source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param sequenceNumber The notification sequence number within the source object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param message The detailed message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public Notification(String type, Object source, long sequenceNumber, String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        super (source) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        this.source = source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        this.sequenceNumber = sequenceNumber ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        this.timeStamp = (new java.util.Date()).getTime() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        this.message = message ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Creates a Notification object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param type The notification type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param source The notification source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param sequenceNumber The notification sequence number within the source object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param timeStamp The notification emission date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public Notification(String type, Object source, long sequenceNumber, long timeStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        super (source) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        this.source = source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        this.type = type ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        this.sequenceNumber = sequenceNumber ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        this.timeStamp = timeStamp ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Creates a Notification object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @param type The notification type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param source The notification source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param sequenceNumber The notification sequence number within the source object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param timeStamp The notification emission date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param message The detailed message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public Notification(String type, Object source, long sequenceNumber, long timeStamp, String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        super (source) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        this.source = source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        this.type = type ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        this.sequenceNumber = sequenceNumber ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        this.timeStamp = timeStamp ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        this.message = message ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Sets the source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @param source the new source for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @see EventObject#getSource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public void setSource(Object source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        super.source = source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        this.source = source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Get the notification sequence number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @return The notification sequence number within the source object. It's a serial number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * identifying a particular instance of notification in the context of the notification source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * The notification model does not assume that notifications will be received in the same order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * that they are sent. The sequence number helps listeners to sort received notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see #setSequenceNumber
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public long getSequenceNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return sequenceNumber ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Set the notification sequence number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param sequenceNumber The notification sequence number within the source object. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * a serial number identifying a particular instance of notification in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * context of the notification source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @see #getSequenceNumber
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public void setSequenceNumber(long sequenceNumber) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        this.sequenceNumber = sequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Get the notification type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @return The notification type. It's a string expressed in a dot notation similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * to Java properties. An example of a notification type is network.alarm.router .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return type ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Get the notification timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @return The notification timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @see #setTimeStamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public long getTimeStamp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return timeStamp ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * Set the notification timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @param timeStamp The notification timestamp. It indicates when the notification was generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @see #getTimeStamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public void setTimeStamp(long timeStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        this.timeStamp = timeStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Get the notification message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @return The message string of this notification object. It contains in a string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * which could be the explanation of the notification for displaying to a user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return message ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * Get the user data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @return The user data object. It is used for whatever data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * the notification source wishes to communicate to its consumers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @see #setUserData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public Object getUserData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return userData ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Set the user data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @param userData The user data object. It is used for whatever data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * the notification source wishes to communicate to its consumers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @see #getUserData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public void setUserData(Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        this.userData = userData ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Returns a String representation of this notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @return A String representation of this notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return super.toString()+"[type="+type+"][message="+message+"]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Deserializes a {@link Notification} from an {@link ObjectInputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
      // New serial form ignores extra field "sourceObjectName"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
      in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
      super.source = source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * Serializes a {@link Notification} to an {@link ObjectOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    private void writeObject(ObjectOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            // Serializes this instance in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            ObjectOutputStream.PutField fields = out.putFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            fields.put("type", type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            fields.put("sequenceNumber", sequenceNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            fields.put("timeStamp", timeStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            fields.put("userData", userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            fields.put("message", message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            fields.put("source", source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            out.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            // Serializes this instance in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            out.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
}