author | jbachorik |
Mon, 29 Jul 2013 04:43:41 -0700 | |
changeset 20830 | bf6aed23937e |
parent 20809 | b5e0612d60b9 |
child 20851 | 9f284cf7836b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1999, 2006, 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; |
|
27 |
||
20809
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
28 |
import java.io.IOException; |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
29 |
import java.io.InvalidObjectException; |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
30 |
import java.io.ObjectInputStream; |
2 | 31 |
import java.util.Arrays; |
32 |
||
33 |
/** |
|
34 |
* <p>The <CODE>MBeanNotificationInfo</CODE> class is used to describe the |
|
35 |
* characteristics of the different notification instances |
|
36 |
* emitted by an MBean, for a given Java class of notification. |
|
37 |
* If an MBean emits notifications that can be instances of different Java classes, |
|
38 |
* then the metadata for that MBean should provide an <CODE>MBeanNotificationInfo</CODE> |
|
39 |
* object for each of these notification Java classes.</p> |
|
40 |
* |
|
41 |
* <p>Instances of this class are immutable. Subclasses may be |
|
42 |
* mutable but this is not recommended.</p> |
|
43 |
* |
|
44 |
* <p>This class extends <CODE>javax.management.MBeanFeatureInfo</CODE> |
|
45 |
* and thus provides <CODE>name</CODE> and <CODE>description</CODE> fields. |
|
46 |
* The <CODE>name</CODE> field should be the fully qualified Java class name of |
|
47 |
* the notification objects described by this class.</p> |
|
48 |
* |
|
49 |
* <p>The <CODE>getNotifTypes</CODE> method returns an array of |
|
50 |
* strings containing the notification types that the MBean may |
|
51 |
* emit. The notification type is a dot-notation string which |
|
52 |
* describes what the emitted notification is about, not the Java |
|
53 |
* class of the notification. A single generic notification class can |
|
54 |
* be used to send notifications of several types. All of these types |
|
55 |
* are returned in the string array result of the |
|
56 |
* <CODE>getNotifTypes</CODE> method. |
|
57 |
* |
|
58 |
* @since 1.5 |
|
59 |
*/ |
|
60 |
public class MBeanNotificationInfo extends MBeanFeatureInfo implements Cloneable { |
|
61 |
||
62 |
/* Serial version */ |
|
63 |
static final long serialVersionUID = -3888371564530107064L; |
|
64 |
||
65 |
private static final String[] NO_TYPES = new String[0]; |
|
66 |
||
67 |
static final MBeanNotificationInfo[] NO_NOTIFICATIONS = |
|
68 |
new MBeanNotificationInfo[0]; |
|
69 |
||
70 |
/** |
|
71 |
* @serial The different types of the notification. |
|
72 |
*/ |
|
20809
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
73 |
private String[] types; |
2 | 74 |
|
75 |
/** @see MBeanInfo#arrayGettersSafe */ |
|
76 |
private final transient boolean arrayGettersSafe; |
|
77 |
||
78 |
/** |
|
79 |
* Constructs an <CODE>MBeanNotificationInfo</CODE> object. |
|
80 |
* |
|
81 |
* @param notifTypes The array of strings (in dot notation) |
|
82 |
* containing the notification types that the MBean may emit. |
|
83 |
* This may be null with the same effect as a zero-length array. |
|
84 |
* @param name The fully qualified Java class name of the |
|
85 |
* described notifications. |
|
86 |
* @param description A human readable description of the data. |
|
87 |
*/ |
|
88 |
public MBeanNotificationInfo(String[] notifTypes, |
|
89 |
String name, |
|
90 |
String description) { |
|
91 |
this(notifTypes, name, description, null); |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
* Constructs an <CODE>MBeanNotificationInfo</CODE> object. |
|
96 |
* |
|
97 |
* @param notifTypes The array of strings (in dot notation) |
|
98 |
* containing the notification types that the MBean may emit. |
|
99 |
* This may be null with the same effect as a zero-length array. |
|
100 |
* @param name The fully qualified Java class name of the |
|
101 |
* described notifications. |
|
102 |
* @param description A human readable description of the data. |
|
103 |
* @param descriptor The descriptor for the notifications. This may be null |
|
104 |
* which is equivalent to an empty descriptor. |
|
105 |
* |
|
106 |
* @since 1.6 |
|
107 |
*/ |
|
108 |
public MBeanNotificationInfo(String[] notifTypes, |
|
109 |
String name, |
|
110 |
String description, |
|
111 |
Descriptor descriptor) { |
|
112 |
super(name, description, descriptor); |
|
113 |
||
114 |
/* We do not validate the notifTypes, since the spec just says |
|
115 |
they are dot-separated, not that they must look like Java |
|
116 |
classes. E.g. the spec doesn't forbid "sun.prob.25" as a |
|
117 |
notifType, though it doesn't explicitly allow it |
|
118 |
either. */ |
|
119 |
||
20809
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
120 |
this.types = (notifTypes != null && notifTypes.length > 0) ? |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
121 |
notifTypes.clone() : NO_TYPES; |
2 | 122 |
this.arrayGettersSafe = |
123 |
MBeanInfo.arrayGettersSafe(this.getClass(), |
|
124 |
MBeanNotificationInfo.class); |
|
125 |
} |
|
126 |
||
127 |
||
128 |
/** |
|
129 |
* Returns a shallow clone of this instance. |
|
130 |
* The clone is obtained by simply calling <tt>super.clone()</tt>, |
|
131 |
* thus calling the default native shallow cloning mechanism |
|
132 |
* implemented by <tt>Object.clone()</tt>. |
|
133 |
* No deeper cloning of any internal field is made. |
|
134 |
*/ |
|
135 |
public Object clone () { |
|
136 |
try { |
|
137 |
return super.clone() ; |
|
138 |
} catch (CloneNotSupportedException e) { |
|
139 |
// should not happen as this class is cloneable |
|
140 |
return null; |
|
141 |
} |
|
142 |
} |
|
143 |
||
144 |
||
145 |
/** |
|
146 |
* Returns the array of strings (in dot notation) containing the |
|
147 |
* notification types that the MBean may emit. |
|
148 |
* |
|
149 |
* @return the array of strings. Changing the returned array has no |
|
150 |
* effect on this MBeanNotificationInfo. |
|
151 |
*/ |
|
152 |
public String[] getNotifTypes() { |
|
153 |
if (types.length == 0) |
|
154 |
return NO_TYPES; |
|
155 |
else |
|
156 |
return types.clone(); |
|
157 |
} |
|
158 |
||
159 |
private String[] fastGetNotifTypes() { |
|
160 |
if (arrayGettersSafe) |
|
161 |
return types; |
|
162 |
else |
|
163 |
return getNotifTypes(); |
|
164 |
} |
|
165 |
||
166 |
public String toString() { |
|
167 |
return |
|
168 |
getClass().getName() + "[" + |
|
169 |
"description=" + getDescription() + ", " + |
|
170 |
"name=" + getName() + ", " + |
|
171 |
"notifTypes=" + Arrays.asList(fastGetNotifTypes()) + ", " + |
|
172 |
"descriptor=" + getDescriptor() + |
|
173 |
"]"; |
|
174 |
} |
|
175 |
||
176 |
/** |
|
177 |
* Compare this MBeanNotificationInfo to another. |
|
178 |
* |
|
179 |
* @param o the object to compare to. |
|
180 |
* |
|
181 |
* @return true if and only if <code>o</code> is an MBeanNotificationInfo |
|
182 |
* such that its {@link #getName()}, {@link #getDescription()}, |
|
183 |
* {@link #getDescriptor()}, |
|
184 |
* and {@link #getNotifTypes()} values are equal (not necessarily |
|
185 |
* identical) to those of this MBeanNotificationInfo. Two |
|
186 |
* notification type arrays are equal if their corresponding |
|
187 |
* elements are equal. They are not equal if they have the same |
|
188 |
* elements but in a different order. |
|
189 |
*/ |
|
190 |
public boolean equals(Object o) { |
|
191 |
if (o == this) |
|
192 |
return true; |
|
193 |
if (!(o instanceof MBeanNotificationInfo)) |
|
194 |
return false; |
|
195 |
MBeanNotificationInfo p = (MBeanNotificationInfo) o; |
|
196 |
return (p.getName().equals(getName()) && |
|
197 |
p.getDescription().equals(getDescription()) && |
|
198 |
p.getDescriptor().equals(getDescriptor()) && |
|
199 |
Arrays.equals(p.fastGetNotifTypes(), fastGetNotifTypes())); |
|
200 |
} |
|
201 |
||
202 |
public int hashCode() { |
|
203 |
int hash = getName().hashCode(); |
|
204 |
for (int i = 0; i < types.length; i++) |
|
205 |
hash ^= types[i].hashCode(); |
|
206 |
return hash; |
|
207 |
} |
|
20809
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
208 |
|
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
209 |
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
210 |
ObjectInputStream.GetField gf = ois.readFields(); |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
211 |
String[] t = (String[])gf.get("types", null); |
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
212 |
|
20830
bf6aed23937e
8021577: JCK test api/javax_management/jmx_serial/modelmbean/ModelMBeanNotificationInfo/serial/index.html#Input has failed since jdk 7u45 b01
jbachorik
parents:
20809
diff
changeset
|
213 |
types = (t != null && t.length != 0) ? t.clone() : NO_TYPES; |
20809
b5e0612d60b9
8014085: Better serialization support in JMX classes
jbachorik
parents:
5506
diff
changeset
|
214 |
} |
2 | 215 |
} |