jdk/src/share/classes/javax/management/remote/TargetedNotification.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 20829 61b4adb0a695
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20829
diff changeset
     2
 * Copyright (c) 2003, 2013, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package javax.management.remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
    29
import java.io.IOException;
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
    30
import java.io.InvalidObjectException;
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
    31
import java.io.ObjectInputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.management.Notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>A (Notification, Listener ID) pair.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>This class is used to associate an emitted notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *    with the listener ID to which it is targeted.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class TargetedNotification implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static final long serialVersionUID = 7676132089779300926L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
// If we replace Integer with int...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
//     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
//      * <p>Constructs a <code>TargetedNotification</code> object.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
//      * object contains a pair (Notification, Listener ID).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
//      * The Listener ID identifies the client listener to which that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
//      * notification is targeted. The client listener ID is one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
//      * previously returned by the connector server in response to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
//      * <code>addNotificationListener</code> request.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
//      * @param notification Notification emitted from the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
//      * @param listenerID   The ID of the listener to which this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
//      *        notification is targeted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
//      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
//     public TargetedNotification(Notification notification,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
//                              int listenerID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
//      this.notif = notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
//      this.id = listenerID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
//     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * <p>Constructs a <code>TargetedNotification</code> object.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * object contains a pair (Notification, Listener ID).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * The Listener ID identifies the client listener to which that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * notification is targeted. The client listener ID is one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * previously returned by the connector server in response to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * <code>addNotificationListener</code> request.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param notification Notification emitted from the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @param listenerID   The ID of the listener to which this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *        notification is targeted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @exception IllegalArgumentException if the <var>listenerID</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *        or <var>notification</var> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public TargetedNotification(Notification notification,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                Integer listenerID) {
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
    79
        validate(notification, listenerID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        // If we replace integer with int...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        // this(notification,intValue(listenerID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        this.notif = notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        this.id = listenerID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <p>The emitted notification.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @return The notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public Notification getNotification() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return notif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <p>The ID of the listener to which the notification is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *    targeted.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @return The listener ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public Integer getListenerID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Returns a textual representation of this Targeted Notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @return a String representation of this Targeted Notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return "{" + notif + ", " + id + "}";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @serial A notification to transmit to the other side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @see #getNotification()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     **/
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   118
    private Notification notif;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @serial The ID of the listener to which the notification is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *         targeted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @see #getListenerID()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     **/
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   124
    private Integer id;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    //private final int id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
// Needed if we use int instead of Integer...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
//     private static int intValue(Integer id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
//      if (id == null) throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
//          IllegalArgumentException("Invalid listener ID: null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
//      return id.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
//     }
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   133
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   134
    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
20829
61b4adb0a695 8019584: javax/management/remote/mandatory/loading/MissingClassTest.java failed in nightly against jdk7u45: java.io.InvalidObjectException: Invalid notification: null
jbachorik
parents: 20809
diff changeset
   135
        ois.defaultReadObject();
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   136
        try {
20829
61b4adb0a695 8019584: javax/management/remote/mandatory/loading/MissingClassTest.java failed in nightly against jdk7u45: java.io.InvalidObjectException: Invalid notification: null
jbachorik
parents: 20809
diff changeset
   137
            validate(this.notif, this.id);
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   138
        } catch (IllegalArgumentException e) {
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   139
            throw new InvalidObjectException(e.getMessage());
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   140
        }
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   141
    }
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   142
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   143
    private static void validate(Notification notif, Integer id) throws IllegalArgumentException {
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   144
        if (notif == null) {
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   145
            throw new IllegalArgumentException("Invalid notification: null");
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   146
        }
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   147
        if (id == null) {
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   148
            throw new IllegalArgumentException("Invalid listener ID: null");
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   149
        }
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   150
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
}