author | yan |
Mon, 12 May 2014 14:33:13 +0400 | |
changeset 24368 | 2b4801b94265 |
parent 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
2 | 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 | 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 |
||
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 | 31 |
import java.io.Serializable; |
32 |
||
33 |
/** |
|
34 |
* <p>Result of a query for buffered notifications. Notifications in |
|
35 |
* a notification buffer have positive, monotonically increasing |
|
36 |
* sequence numbers. The result of a notification query contains the |
|
37 |
* following elements:</p> |
|
38 |
* |
|
39 |
* <ul> |
|
40 |
* |
|
41 |
* <li>The sequence number of the earliest notification still in |
|
42 |
* the buffer. |
|
43 |
* |
|
44 |
* <li>The sequence number of the next notification available for |
|
45 |
* querying. This will be the starting sequence number for the next |
|
46 |
* notification query. |
|
47 |
* |
|
48 |
* <li>An array of (Notification,listenerID) pairs corresponding to |
|
49 |
* the returned notifications and the listeners they correspond to. |
|
50 |
* |
|
51 |
* </ul> |
|
52 |
* |
|
53 |
* <p>It is possible for the <code>nextSequenceNumber</code> to be less |
|
54 |
* than the <code>earliestSequenceNumber</code>. This signifies that |
|
55 |
* notifications between the two might have been lost.</p> |
|
56 |
* |
|
57 |
* @since 1.5 |
|
58 |
*/ |
|
59 |
public class NotificationResult implements Serializable { |
|
60 |
||
61 |
private static final long serialVersionUID = 1191800228721395279L; |
|
62 |
||
63 |
/** |
|
64 |
* <p>Constructs a notification query result.</p> |
|
65 |
* |
|
66 |
* @param earliestSequenceNumber the sequence number of the |
|
67 |
* earliest notification still in the buffer. |
|
68 |
* @param nextSequenceNumber the sequence number of the next |
|
69 |
* notification available for querying. |
|
70 |
* @param targetedNotifications the notifications resulting from |
|
71 |
* the query, and the listeners they correspond to. This array |
|
72 |
* can be empty. |
|
73 |
* |
|
74 |
* @exception IllegalArgumentException if |
|
75 |
* <code>targetedNotifications</code> is null or if |
|
76 |
* <code>earliestSequenceNumber</code> or |
|
77 |
* <code>nextSequenceNumber</code> is negative. |
|
78 |
*/ |
|
79 |
public NotificationResult(long earliestSequenceNumber, |
|
80 |
long nextSequenceNumber, |
|
81 |
TargetedNotification[] targetedNotifications) { |
|
20809
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
18189
diff
changeset
|
82 |
validate(targetedNotifications, earliestSequenceNumber, nextSequenceNumber); |
2 | 83 |
this.earliestSequenceNumber = earliestSequenceNumber; |
84 |
this.nextSequenceNumber = nextSequenceNumber; |
|
18189 | 85 |
this.targetedNotifications = (targetedNotifications.length == 0 ? targetedNotifications : targetedNotifications.clone()); |
2 | 86 |
} |
87 |
||
88 |
/** |
|
89 |
* Returns the sequence number of the earliest notification still |
|
90 |
* in the buffer. |
|
91 |
* |
|
92 |
* @return the sequence number of the earliest notification still |
|
93 |
* in the buffer. |
|
94 |
*/ |
|
95 |
public long getEarliestSequenceNumber() { |
|
96 |
return earliestSequenceNumber; |
|
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* Returns the sequence number of the next notification available |
|
101 |
* for querying. |
|
102 |
* |
|
103 |
* @return the sequence number of the next notification available |
|
104 |
* for querying. |
|
105 |
*/ |
|
106 |
public long getNextSequenceNumber() { |
|
107 |
return nextSequenceNumber; |
|
108 |
} |
|
109 |
||
110 |
/** |
|
111 |
* Returns the notifications resulting from the query, and the |
|
112 |
* listeners they correspond to. |
|
113 |
* |
|
114 |
* @return the notifications resulting from the query, and the |
|
115 |
* listeners they correspond to. This array can be empty. |
|
116 |
*/ |
|
117 |
public TargetedNotification[] getTargetedNotifications() { |
|
18189 | 118 |
return targetedNotifications.length == 0 ? targetedNotifications : targetedNotifications.clone(); |
2 | 119 |
} |
120 |
||
121 |
/** |
|
122 |
* Returns a string representation of the object. The result |
|
123 |
* should be a concise but informative representation that is easy |
|
124 |
* for a person to read. |
|
125 |
* |
|
126 |
* @return a string representation of the object. |
|
127 |
*/ |
|
128 |
public String toString() { |
|
129 |
return "NotificationResult: earliest=" + getEarliestSequenceNumber() + |
|
130 |
"; next=" + getNextSequenceNumber() + "; nnotifs=" + |
|
131 |
getTargetedNotifications().length; |
|
132 |
} |
|
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 | 170 |
} |