author | jbachorik |
Thu, 20 Jun 2013 08:51:47 +0200 | |
changeset 20809 | b5e0612d60b9 |
parent 5506 | 202f599c92aa |
child 20829 | 61b4adb0a695 |
permissions | -rw-r--r-- |
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 |
||
27 |
package javax.management.remote; |
|
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 | 32 |
import java.io.Serializable; |
33 |
import javax.management.Notification; |
|
34 |
||
35 |
/** |
|
36 |
* <p>A (Notification, Listener ID) pair.</p> |
|
37 |
* <p>This class is used to associate an emitted notification |
|
38 |
* with the listener ID to which it is targeted.</p> |
|
39 |
* |
|
40 |
* @since 1.5 |
|
41 |
*/ |
|
42 |
public class TargetedNotification implements Serializable { |
|
43 |
||
44 |
private static final long serialVersionUID = 7676132089779300926L; |
|
45 |
||
46 |
// If we replace Integer with int... |
|
47 |
// /** |
|
48 |
// * <p>Constructs a <code>TargetedNotification</code> object. The |
|
49 |
// * object contains a pair (Notification, Listener ID). |
|
50 |
// * The Listener ID identifies the client listener to which that |
|
51 |
// * notification is targeted. The client listener ID is one |
|
52 |
// * previously returned by the connector server in response to an |
|
53 |
// * <code>addNotificationListener</code> request.</p> |
|
54 |
// * @param notification Notification emitted from the MBean server. |
|
55 |
// * @param listenerID The ID of the listener to which this |
|
56 |
// * notification is targeted. |
|
57 |
// */ |
|
58 |
// public TargetedNotification(Notification notification, |
|
59 |
// int listenerID) { |
|
60 |
// this.notif = notification; |
|
61 |
// this.id = listenerID; |
|
62 |
// } |
|
63 |
||
64 |
/** |
|
65 |
* <p>Constructs a <code>TargetedNotification</code> object. The |
|
66 |
* object contains a pair (Notification, Listener ID). |
|
67 |
* The Listener ID identifies the client listener to which that |
|
68 |
* notification is targeted. The client listener ID is one |
|
69 |
* previously returned by the connector server in response to an |
|
70 |
* <code>addNotificationListener</code> request.</p> |
|
71 |
* @param notification Notification emitted from the MBean server. |
|
72 |
* @param listenerID The ID of the listener to which this |
|
73 |
* notification is targeted. |
|
74 |
* @exception IllegalArgumentException if the <var>listenerID</var> |
|
75 |
* or <var>notification</var> is null. |
|
76 |
*/ |
|
77 |
public TargetedNotification(Notification notification, |
|
78 |
Integer listenerID) { |
|
20809
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
79 |
validate(notification, listenerID); |
2 | 80 |
// If we replace integer with int... |
81 |
// this(notification,intValue(listenerID)); |
|
82 |
this.notif = notification; |
|
83 |
this.id = listenerID; |
|
84 |
} |
|
85 |
||
86 |
/** |
|
87 |
* <p>The emitted notification.</p> |
|
88 |
* |
|
89 |
* @return The notification. |
|
90 |
*/ |
|
91 |
public Notification getNotification() { |
|
92 |
return notif; |
|
93 |
} |
|
94 |
||
95 |
/** |
|
96 |
* <p>The ID of the listener to which the notification is |
|
97 |
* targeted.</p> |
|
98 |
* |
|
99 |
* @return The listener ID. |
|
100 |
*/ |
|
101 |
public Integer getListenerID() { |
|
102 |
return id; |
|
103 |
} |
|
104 |
||
105 |
/** |
|
106 |
* Returns a textual representation of this Targeted Notification. |
|
107 |
* |
|
108 |
* @return a String representation of this Targeted Notification. |
|
109 |
**/ |
|
110 |
public String toString() { |
|
111 |
return "{" + notif + ", " + id + "}"; |
|
112 |
} |
|
113 |
||
114 |
/** |
|
115 |
* @serial A notification to transmit to the other side. |
|
116 |
* @see #getNotification() |
|
117 |
**/ |
|
20809
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
118 |
private Notification notif; |
2 | 119 |
/** |
120 |
* @serial The ID of the listener to which the notification is |
|
121 |
* targeted. |
|
122 |
* @see #getListenerID() |
|
123 |
**/ |
|
20809
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
124 |
private Integer id; |
2 | 125 |
//private final int id; |
126 |
||
127 |
// Needed if we use int instead of Integer... |
|
128 |
// private static int intValue(Integer id) { |
|
129 |
// if (id == null) throw new |
|
130 |
// IllegalArgumentException("Invalid listener ID: null"); |
|
131 |
// return id.intValue(); |
|
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 { |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
135 |
ObjectInputStream.GetField gf = ois.readFields(); |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
136 |
Notification notification = (Notification)gf.get("notif", null); |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
137 |
Integer listenerId = (Integer)gf.get("id", null); |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
138 |
try { |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
139 |
validate(notification, listenerId); |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
140 |
this.notif = notification; |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
141 |
this.id = listenerId; |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
142 |
} catch (IllegalArgumentException e) { |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
143 |
throw new InvalidObjectException(e.getMessage()); |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
144 |
} |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
145 |
} |
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 |
private static void validate(Notification notif, Integer id) throws IllegalArgumentException { |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
148 |
if (notif == null) { |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
149 |
throw new IllegalArgumentException("Invalid notification: null"); |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
150 |
} |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
151 |
if (id == null) { |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
152 |
throw new IllegalArgumentException("Invalid listener ID: null"); |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
153 |
} |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
154 |
} |
2 | 155 |
} |