jdk/src/share/classes/javax/management/remote/NotificationResult.java
author yan
Mon, 12 May 2014 14:33:13 +0400
changeset 24368 2b4801b94265
parent 23010 6dadb192ad81
permissions -rw-r--r--
8038795: Tidy warnings cleanup for javax.management Reviewed-by: dfuchs Contributed-by: Alexander Stepanov <alexander.v.stepanov@oracle.com>
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
package javax.management.remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
    28
import java.io.IOException;
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
    29
import java.io.InvalidObjectException;
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
    30
import java.io.ObjectInputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>Result of a query for buffered notifications.  Notifications in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * a notification buffer have positive, monotonically increasing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * sequence numbers.  The result of a notification query contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * following elements:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <li>The sequence number of the earliest notification still in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <li>The sequence number of the next notification available for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * querying.  This will be the starting sequence number for the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * notification query.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <li>An array of (Notification,listenerID) pairs corresponding to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * the returned notifications and the listeners they correspond to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>It is possible for the <code>nextSequenceNumber</code> to be less
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * than the <code>earliestSequenceNumber</code>.  This signifies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * notifications between the two might have been lost.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
public class NotificationResult implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static final long serialVersionUID = 1191800228721395279L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * <p>Constructs a notification query result.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @param earliestSequenceNumber the sequence number of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * earliest notification still in the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @param nextSequenceNumber the sequence number of the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * notification available for querying.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param targetedNotifications the notifications resulting from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * the query, and the listeners they correspond to.  This array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * can be empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <code>targetedNotifications</code> is null or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <code>earliestSequenceNumber</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * <code>nextSequenceNumber</code> is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public NotificationResult(long earliestSequenceNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                              long nextSequenceNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                              TargetedNotification[] targetedNotifications) {
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
    82
        validate(targetedNotifications, earliestSequenceNumber, nextSequenceNumber);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        this.earliestSequenceNumber = earliestSequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        this.nextSequenceNumber = nextSequenceNumber;
18189
ef33730f6b2b 8009034: Improve resulting notifications in JMX
jbachorik
parents: 5506
diff changeset
    85
        this.targetedNotifications = (targetedNotifications.length == 0 ? targetedNotifications : targetedNotifications.clone());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Returns the sequence number of the earliest notification still
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * in the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @return the sequence number of the earliest notification still
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * in the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public long getEarliestSequenceNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return earliestSequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Returns the sequence number of the next notification available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * for querying.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @return the sequence number of the next notification available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * for querying.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public long getNextSequenceNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return nextSequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Returns the notifications resulting from the query, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * listeners they correspond to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @return the notifications resulting from the query, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * listeners they correspond to.  This array can be empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public TargetedNotification[] getTargetedNotifications() {
18189
ef33730f6b2b 8009034: Improve resulting notifications in JMX
jbachorik
parents: 5506
diff changeset
   118
        return targetedNotifications.length == 0 ? targetedNotifications : targetedNotifications.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Returns a string representation of the object.  The result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * should be a concise but informative representation that is easy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * for a person to read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @return a string representation of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return "NotificationResult: earliest=" + getEarliestSequenceNumber() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            "; next=" + getNextSequenceNumber() + "; nnotifs=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            getTargetedNotifications().length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
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: 18189
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(
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
   138
                this.targetedNotifications,
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
   139
                this.earliestSequenceNumber,
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
   140
                this.nextSequenceNumber
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
   141
            );
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   142
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
   143
            this.targetedNotifications = this.targetedNotifications.length == 0 ?
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
   144
                                            this.targetedNotifications :
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
   145
                                            this.targetedNotifications.clone();
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   146
        } catch (IllegalArgumentException e) {
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   147
            throw new InvalidObjectException(e.getMessage());
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   148
        }
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   149
    }
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   150
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   151
    private long earliestSequenceNumber;
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   152
    private long nextSequenceNumber;
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   153
    private TargetedNotification[] targetedNotifications;
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   154
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   155
    private static void validate(TargetedNotification[] targetedNotifications,
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   156
                                 long earliestSequenceNumber,
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   157
                                 long nextSequenceNumber)
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   158
        throws IllegalArgumentException {
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   159
        if (targetedNotifications == null) {
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   160
            final String msg = "Notifications null";
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   161
            throw new IllegalArgumentException(msg);
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   162
        }
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   163
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   164
        if (earliestSequenceNumber < 0 || nextSequenceNumber < 0)
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   165
            throw new IllegalArgumentException("Bad sequence numbers");
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   166
        /* We used to check nextSequenceNumber >= earliestSequenceNumber
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   167
           here.  But in fact the opposite can legitimately be true if
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   168
           notifications have been lost.  */
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 18189
diff changeset
   169
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
}