jdk/src/share/classes/javax/management/remote/NotificationResult.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 18189 ef33730f6b2b
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
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: 2
diff changeset
     2
 * Copyright (c) 2003, 2007, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * <p>Result of a query for buffered notifications.  Notifications in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * a notification buffer have positive, monotonically increasing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * sequence numbers.  The result of a notification query contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * following elements:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <li>The sequence number of the earliest notification still in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <li>The sequence number of the next notification available for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * querying.  This will be the starting sequence number for the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * notification query.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <li>An array of (Notification,listenerID) pairs corresponding to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * the returned notifications and the listeners they correspond to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>It is possible for the <code>nextSequenceNumber</code> to be less
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * than the <code>earliestSequenceNumber</code>.  This signifies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * notifications between the two might have been lost.</p>
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
public class NotificationResult implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static final long serialVersionUID = 1191800228721395279L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * <p>Constructs a notification query result.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @param earliestSequenceNumber the sequence number of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * earliest notification still in the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @param nextSequenceNumber the sequence number of the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * notification available for querying.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @param targetedNotifications the notifications resulting from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * the query, and the listeners they correspond to.  This array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * can be empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * <code>targetedNotifications</code> is null or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * <code>earliestSequenceNumber</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <code>nextSequenceNumber</code> is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public NotificationResult(long earliestSequenceNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                              long nextSequenceNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                              TargetedNotification[] targetedNotifications) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (targetedNotifications == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            final String msg = "Notifications null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            throw new IllegalArgumentException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (earliestSequenceNumber < 0 || nextSequenceNumber < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            throw new IllegalArgumentException("Bad sequence numbers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        /* We used to check nextSequenceNumber >= earliestSequenceNumber
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
           here.  But in fact the opposite can legitimately be true if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
           notifications have been lost.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        this.earliestSequenceNumber = earliestSequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        this.nextSequenceNumber = nextSequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        this.targetedNotifications = targetedNotifications;
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
     * Returns the sequence number of the earliest notification still
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * in the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @return the sequence number of the earliest notification still
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * in the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public long getEarliestSequenceNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return earliestSequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Returns the sequence number of the next notification available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * for querying.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @return the sequence number of the next notification available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * for querying.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public long getNextSequenceNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return nextSequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Returns the notifications resulting from the query, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * listeners they correspond to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return the notifications resulting from the query, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * listeners they correspond to.  This array can be empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public TargetedNotification[] getTargetedNotifications() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return targetedNotifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Returns a string representation of the object.  The result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * should be a concise but informative representation that is easy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * for a person to read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return a string representation of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return "NotificationResult: earliest=" + getEarliestSequenceNumber() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            "; next=" + getNextSequenceNumber() + "; nnotifs=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            getTargetedNotifications().length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private final long earliestSequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private final long nextSequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private final TargetedNotification[] targetedNotifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
}