2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package javax.management.remote;
|
|
27 |
|
|
28 |
import java.io.Serializable;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* <p>Result of a query for buffered notifications. Notifications in
|
|
32 |
* a notification buffer have positive, monotonically increasing
|
|
33 |
* sequence numbers. The result of a notification query contains the
|
|
34 |
* following elements:</p>
|
|
35 |
*
|
|
36 |
* <ul>
|
|
37 |
*
|
|
38 |
* <li>The sequence number of the earliest notification still in
|
|
39 |
* the buffer.
|
|
40 |
*
|
|
41 |
* <li>The sequence number of the next notification available for
|
|
42 |
* querying. This will be the starting sequence number for the next
|
|
43 |
* notification query.
|
|
44 |
*
|
|
45 |
* <li>An array of (Notification,listenerID) pairs corresponding to
|
|
46 |
* the returned notifications and the listeners they correspond to.
|
|
47 |
*
|
|
48 |
* </ul>
|
|
49 |
*
|
|
50 |
* <p>It is possible for the <code>nextSequenceNumber</code> to be less
|
|
51 |
* than the <code>earliestSequenceNumber</code>. This signifies that
|
|
52 |
* notifications between the two might have been lost.</p>
|
|
53 |
*
|
|
54 |
* @since 1.5
|
|
55 |
*/
|
|
56 |
public class NotificationResult implements Serializable {
|
|
57 |
|
|
58 |
private static final long serialVersionUID = 1191800228721395279L;
|
|
59 |
|
|
60 |
/**
|
|
61 |
* <p>Constructs a notification query result.</p>
|
|
62 |
*
|
|
63 |
* @param earliestSequenceNumber the sequence number of the
|
|
64 |
* earliest notification still in the buffer.
|
|
65 |
* @param nextSequenceNumber the sequence number of the next
|
|
66 |
* notification available for querying.
|
|
67 |
* @param targetedNotifications the notifications resulting from
|
|
68 |
* the query, and the listeners they correspond to. This array
|
|
69 |
* can be empty.
|
|
70 |
*
|
|
71 |
* @exception IllegalArgumentException if
|
|
72 |
* <code>targetedNotifications</code> is null or if
|
|
73 |
* <code>earliestSequenceNumber</code> or
|
|
74 |
* <code>nextSequenceNumber</code> is negative.
|
|
75 |
*/
|
|
76 |
public NotificationResult(long earliestSequenceNumber,
|
|
77 |
long nextSequenceNumber,
|
|
78 |
TargetedNotification[] targetedNotifications) {
|
|
79 |
if (targetedNotifications == null) {
|
|
80 |
final String msg = "Notifications null";
|
|
81 |
throw new IllegalArgumentException(msg);
|
|
82 |
}
|
|
83 |
|
|
84 |
if (earliestSequenceNumber < 0 || nextSequenceNumber < 0)
|
|
85 |
throw new IllegalArgumentException("Bad sequence numbers");
|
|
86 |
/* We used to check nextSequenceNumber >= earliestSequenceNumber
|
|
87 |
here. But in fact the opposite can legitimately be true if
|
|
88 |
notifications have been lost. */
|
|
89 |
|
|
90 |
this.earliestSequenceNumber = earliestSequenceNumber;
|
|
91 |
this.nextSequenceNumber = nextSequenceNumber;
|
18189
|
92 |
this.targetedNotifications = (targetedNotifications.length == 0 ? targetedNotifications : targetedNotifications.clone());
|
2
|
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
* Returns the sequence number of the earliest notification still
|
|
97 |
* in the buffer.
|
|
98 |
*
|
|
99 |
* @return the sequence number of the earliest notification still
|
|
100 |
* in the buffer.
|
|
101 |
*/
|
|
102 |
public long getEarliestSequenceNumber() {
|
|
103 |
return earliestSequenceNumber;
|
|
104 |
}
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Returns the sequence number of the next notification available
|
|
108 |
* for querying.
|
|
109 |
*
|
|
110 |
* @return the sequence number of the next notification available
|
|
111 |
* for querying.
|
|
112 |
*/
|
|
113 |
public long getNextSequenceNumber() {
|
|
114 |
return nextSequenceNumber;
|
|
115 |
}
|
|
116 |
|
|
117 |
/**
|
|
118 |
* Returns the notifications resulting from the query, and the
|
|
119 |
* listeners they correspond to.
|
|
120 |
*
|
|
121 |
* @return the notifications resulting from the query, and the
|
|
122 |
* listeners they correspond to. This array can be empty.
|
|
123 |
*/
|
|
124 |
public TargetedNotification[] getTargetedNotifications() {
|
18189
|
125 |
return targetedNotifications.length == 0 ? targetedNotifications : targetedNotifications.clone();
|
2
|
126 |
}
|
|
127 |
|
|
128 |
/**
|
|
129 |
* Returns a string representation of the object. The result
|
|
130 |
* should be a concise but informative representation that is easy
|
|
131 |
* for a person to read.
|
|
132 |
*
|
|
133 |
* @return a string representation of the object.
|
|
134 |
*/
|
|
135 |
public String toString() {
|
|
136 |
return "NotificationResult: earliest=" + getEarliestSequenceNumber() +
|
|
137 |
"; next=" + getNextSequenceNumber() + "; nnotifs=" +
|
|
138 |
getTargetedNotifications().length;
|
|
139 |
}
|
|
140 |
|
|
141 |
private final long earliestSequenceNumber;
|
|
142 |
private final long nextSequenceNumber;
|
|
143 |
private final TargetedNotification[] targetedNotifications;
|
|
144 |
}
|