src/java.management/share/classes/javax/management/Notification.java
author darcy
Wed, 23 Oct 2019 13:01:40 -0700
changeset 58766 54ffb15c4839
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.* Reviewed-by: rriggs, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     2
 * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    23
 * questions.
2
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
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    57
public class Notification extends EventObject {
2
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
     *
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   288
     * @return The notification type. It's a string expressed in a dot notation
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   289
     * similar to Java properties. It is recommended that the notification type
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   290
     * should follow the reverse-domain-name convention used by Java package
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   291
     * names.  An example of a notification type is com.example.alarm.router.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return type ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Get the notification timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @return The notification timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @see #setTimeStamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public long getTimeStamp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return timeStamp ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Set the notification timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @param timeStamp The notification timestamp. It indicates when the notification was generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @see #getTimeStamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public void setTimeStamp(long timeStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        this.timeStamp = timeStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Get the notification message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   322
     * @return The message string of this notification object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return message ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Get the user data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @return The user data object. It is used for whatever data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * the notification source wishes to communicate to its consumers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @see #setUserData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public Object getUserData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        return userData ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * Set the user data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @param userData The user data object. It is used for whatever data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * the notification source wishes to communicate to its consumers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @see #getUserData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public void setUserData(Object userData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        this.userData = userData ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * Returns a String representation of this notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @return A String representation of this notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     */
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   359
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return super.toString()+"[type="+type+"][message="+message+"]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Deserializes a {@link Notification} from an {@link ObjectInputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
      // New serial form ignores extra field "sourceObjectName"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
      in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
      super.source = source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * Serializes a {@link Notification} to an {@link ObjectOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    private void writeObject(ObjectOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            // Serializes this instance in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            ObjectOutputStream.PutField fields = out.putFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            fields.put("type", type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            fields.put("sequenceNumber", sequenceNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            fields.put("timeStamp", timeStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            fields.put("userData", userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            fields.put("message", message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            fields.put("source", source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            out.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            // Serializes this instance in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            out.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
}