author | chegar |
Sun, 17 Aug 2014 15:54:13 +0100 | |
changeset 25859 | 3317bb8137f4 |
parent 23010 | jdk/src/share/classes/javax/management/JMX.java@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:
21656
diff
changeset
|
2 |
* Copyright (c) 2005, 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; |
|
27 |
||
28 |
import com.sun.jmx.mbeanserver.Introspector; |
|
29 |
import java.lang.reflect.InvocationHandler; |
|
18213
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
30 |
import java.lang.reflect.Modifier; |
2 | 31 |
import java.lang.reflect.Proxy; |
18213
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
32 |
import sun.reflect.misc.ReflectUtil; |
2 | 33 |
|
34 |
/** |
|
35 |
* Static methods from the JMX API. There are no instances of this class. |
|
36 |
* |
|
37 |
* @since 1.6 |
|
38 |
*/ |
|
39 |
public class JMX { |
|
40 |
/* Code within this package can prove that by providing this instance of |
|
41 |
* this class. |
|
42 |
*/ |
|
43 |
static final JMX proof = new JMX(); |
|
44 |
||
45 |
private JMX() {} |
|
46 |
||
47 |
/** |
|
48 |
* The name of the <a href="Descriptor.html#defaultValue">{@code |
|
49 |
* defaultValue}</a> field. |
|
50 |
*/ |
|
51 |
public static final String DEFAULT_VALUE_FIELD = "defaultValue"; |
|
52 |
||
1699
3611e5fd6da5
6250014: MBeanOperationInfo Descriptor field for exceptions
jfdenise
parents:
1636
diff
changeset
|
53 |
/** |
2 | 54 |
* The name of the <a href="Descriptor.html#immutableInfo">{@code |
55 |
* immutableInfo}</a> field. |
|
56 |
*/ |
|
57 |
public static final String IMMUTABLE_INFO_FIELD = "immutableInfo"; |
|
58 |
||
59 |
/** |
|
60 |
* The name of the <a href="Descriptor.html#interfaceClassName">{@code |
|
61 |
* interfaceClassName}</a> field. |
|
62 |
*/ |
|
63 |
public static final String INTERFACE_CLASS_NAME_FIELD = "interfaceClassName"; |
|
64 |
||
65 |
/** |
|
66 |
* The name of the <a href="Descriptor.html#legalValues">{@code |
|
67 |
* legalValues}</a> field. |
|
68 |
*/ |
|
69 |
public static final String LEGAL_VALUES_FIELD = "legalValues"; |
|
70 |
||
71 |
/** |
|
72 |
* The name of the <a href="Descriptor.html#maxValue">{@code |
|
73 |
* maxValue}</a> field. |
|
74 |
*/ |
|
75 |
public static final String MAX_VALUE_FIELD = "maxValue"; |
|
76 |
||
77 |
/** |
|
78 |
* The name of the <a href="Descriptor.html#minValue">{@code |
|
79 |
* minValue}</a> field. |
|
80 |
*/ |
|
81 |
public static final String MIN_VALUE_FIELD = "minValue"; |
|
82 |
||
83 |
/** |
|
84 |
* The name of the <a href="Descriptor.html#mxbean">{@code |
|
85 |
* mxbean}</a> field. |
|
86 |
*/ |
|
87 |
public static final String MXBEAN_FIELD = "mxbean"; |
|
88 |
||
89 |
/** |
|
90 |
* The name of the <a href="Descriptor.html#openType">{@code |
|
91 |
* openType}</a> field. |
|
92 |
*/ |
|
93 |
public static final String OPEN_TYPE_FIELD = "openType"; |
|
94 |
||
95 |
/** |
|
96 |
* The name of the <a href="Descriptor.html#originalType">{@code |
|
97 |
* originalType}</a> field. |
|
98 |
*/ |
|
99 |
public static final String ORIGINAL_TYPE_FIELD = "originalType"; |
|
100 |
||
101 |
/** |
|
102 |
* <p>Make a proxy for a Standard MBean in a local or remote |
|
103 |
* MBean Server.</p> |
|
104 |
* |
|
105 |
* <p>If you have an MBean Server {@code mbs} containing an MBean |
|
106 |
* with {@link ObjectName} {@code name}, and if the MBean's |
|
107 |
* management interface is described by the Java interface |
|
108 |
* {@code MyMBean}, you can construct a proxy for the MBean like |
|
109 |
* this:</p> |
|
110 |
* |
|
111 |
* <pre> |
|
112 |
* MyMBean proxy = JMX.newMBeanProxy(mbs, name, MyMBean.class); |
|
113 |
* </pre> |
|
114 |
* |
|
115 |
* <p>Suppose, for example, {@code MyMBean} looks like this:</p> |
|
116 |
* |
|
117 |
* <pre> |
|
118 |
* public interface MyMBean { |
|
119 |
* public String getSomeAttribute(); |
|
120 |
* public void setSomeAttribute(String value); |
|
121 |
* public void someOperation(String param1, int param2); |
|
122 |
* } |
|
123 |
* </pre> |
|
124 |
* |
|
125 |
* <p>Then you can execute:</p> |
|
126 |
* |
|
127 |
* <ul> |
|
128 |
* |
|
129 |
* <li>{@code proxy.getSomeAttribute()} which will result in a |
|
130 |
* call to {@code mbs.}{@link MBeanServerConnection#getAttribute |
|
131 |
* getAttribute}{@code (name, "SomeAttribute")}. |
|
132 |
* |
|
133 |
* <li>{@code proxy.setSomeAttribute("whatever")} which will result |
|
134 |
* in a call to {@code mbs.}{@link MBeanServerConnection#setAttribute |
|
135 |
* setAttribute}{@code (name, new Attribute("SomeAttribute", "whatever"))}. |
|
136 |
* |
|
137 |
* <li>{@code proxy.someOperation("param1", 2)} which will be |
|
138 |
* translated into a call to {@code mbs.}{@link |
|
139 |
* MBeanServerConnection#invoke invoke}{@code (name, "someOperation", <etc>)}. |
|
140 |
* |
|
141 |
* </ul> |
|
142 |
* |
|
143 |
* <p>The object returned by this method is a |
|
144 |
* {@link Proxy} whose {@code InvocationHandler} is an |
|
145 |
* {@link MBeanServerInvocationHandler}.</p> |
|
146 |
* |
|
147 |
* <p>This method is equivalent to {@link |
|
148 |
* #newMBeanProxy(MBeanServerConnection, ObjectName, Class, |
|
149 |
* boolean) newMBeanProxy(connection, objectName, interfaceClass, |
|
150 |
* false)}.</p> |
|
151 |
* |
|
152 |
* @param connection the MBean server to forward to. |
|
153 |
* @param objectName the name of the MBean within |
|
154 |
* {@code connection} to forward to. |
|
155 |
* @param interfaceClass the management interface that the MBean |
|
156 |
* exports, which will also be implemented by the returned proxy. |
|
157 |
* |
|
158 |
* @param <T> allows the compiler to know that if the {@code |
|
159 |
* interfaceClass} parameter is {@code MyMBean.class}, for |
|
160 |
* example, then the return type is {@code MyMBean}. |
|
161 |
* |
|
162 |
* @return the new proxy instance. |
|
18805
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
163 |
* |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
164 |
* @throws IllegalArgumentException if {@code interfaceClass} is not |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
165 |
* a <a href="package-summary.html#mgIface">compliant MBean |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
166 |
* interface</a> |
2 | 167 |
*/ |
168 |
public static <T> T newMBeanProxy(MBeanServerConnection connection, |
|
169 |
ObjectName objectName, |
|
170 |
Class<T> interfaceClass) { |
|
171 |
return newMBeanProxy(connection, objectName, interfaceClass, false); |
|
172 |
} |
|
173 |
||
174 |
/** |
|
175 |
* <p>Make a proxy for a Standard MBean in a local or remote MBean |
|
176 |
* Server that may also support the methods of {@link |
|
177 |
* NotificationEmitter}.</p> |
|
178 |
* |
|
179 |
* <p>This method behaves the same as {@link |
|
180 |
* #newMBeanProxy(MBeanServerConnection, ObjectName, Class)}, but |
|
687 | 181 |
* additionally, if {@code notificationEmitter} is {@code |
2 | 182 |
* true}, then the MBean is assumed to be a {@link |
183 |
* NotificationBroadcaster} or {@link NotificationEmitter} and the |
|
184 |
* returned proxy will implement {@link NotificationEmitter} as |
|
185 |
* well as {@code interfaceClass}. A call to {@link |
|
186 |
* NotificationBroadcaster#addNotificationListener} on the proxy |
|
187 |
* will result in a call to {@link |
|
188 |
* MBeanServerConnection#addNotificationListener(ObjectName, |
|
189 |
* NotificationListener, NotificationFilter, Object)}, and |
|
190 |
* likewise for the other methods of {@link |
|
191 |
* NotificationBroadcaster} and {@link NotificationEmitter}.</p> |
|
192 |
* |
|
193 |
* @param connection the MBean server to forward to. |
|
194 |
* @param objectName the name of the MBean within |
|
195 |
* {@code connection} to forward to. |
|
196 |
* @param interfaceClass the management interface that the MBean |
|
197 |
* exports, which will also be implemented by the returned proxy. |
|
687 | 198 |
* @param notificationEmitter make the returned proxy |
2 | 199 |
* implement {@link NotificationEmitter} by forwarding its methods |
200 |
* via {@code connection}. |
|
4156 | 201 |
* |
2 | 202 |
* @param <T> allows the compiler to know that if the {@code |
203 |
* interfaceClass} parameter is {@code MyMBean.class}, for |
|
204 |
* example, then the return type is {@code MyMBean}. |
|
4156 | 205 |
* |
2 | 206 |
* @return the new proxy instance. |
18805
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
207 |
* |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
208 |
* @throws IllegalArgumentException if {@code interfaceClass} is not |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
209 |
* a <a href="package-summary.html#mgIface">compliant MBean |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
210 |
* interface</a> |
2 | 211 |
*/ |
212 |
public static <T> T newMBeanProxy(MBeanServerConnection connection, |
|
213 |
ObjectName objectName, |
|
214 |
Class<T> interfaceClass, |
|
687 | 215 |
boolean notificationEmitter) { |
18213
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
216 |
return createProxy(connection, objectName, interfaceClass, notificationEmitter, false); |
2 | 217 |
} |
218 |
||
219 |
/** |
|
21656
d4c777ccb1db
8028014: Doclint warning/error cleanup in javax.management
rriggs
parents:
18805
diff
changeset
|
220 |
* Make a proxy for an MXBean in a local or remote MBean Server. |
2 | 221 |
* |
222 |
* <p>If you have an MBean Server {@code mbs} containing an |
|
223 |
* MXBean with {@link ObjectName} {@code name}, and if the |
|
224 |
* MXBean's management interface is described by the Java |
|
225 |
* interface {@code MyMXBean}, you can construct a proxy for |
|
226 |
* the MXBean like this:</p> |
|
227 |
* |
|
228 |
* <pre> |
|
229 |
* MyMXBean proxy = JMX.newMXBeanProxy(mbs, name, MyMXBean.class); |
|
230 |
* </pre> |
|
231 |
* |
|
232 |
* <p>Suppose, for example, {@code MyMXBean} looks like this:</p> |
|
233 |
* |
|
234 |
* <pre> |
|
235 |
* public interface MyMXBean { |
|
236 |
* public String getSimpleAttribute(); |
|
237 |
* public void setSimpleAttribute(String value); |
|
238 |
* public {@link java.lang.management.MemoryUsage} getMappedAttribute(); |
|
239 |
* public void setMappedAttribute(MemoryUsage memoryUsage); |
|
240 |
* public MemoryUsage someOperation(String param1, MemoryUsage param2); |
|
241 |
* } |
|
242 |
* </pre> |
|
243 |
* |
|
244 |
* <p>Then:</p> |
|
245 |
* |
|
246 |
* <ul> |
|
247 |
* |
|
248 |
* <li><p>{@code proxy.getSimpleAttribute()} will result in a |
|
249 |
* call to {@code mbs.}{@link MBeanServerConnection#getAttribute |
|
250 |
* getAttribute}{@code (name, "SimpleAttribute")}.</p> |
|
251 |
* |
|
252 |
* <li><p>{@code proxy.setSimpleAttribute("whatever")} will result |
|
253 |
* in a call to {@code mbs.}{@link |
|
254 |
* MBeanServerConnection#setAttribute setAttribute}<code>(name, |
|
21656
d4c777ccb1db
8028014: Doclint warning/error cleanup in javax.management
rriggs
parents:
18805
diff
changeset
|
255 |
* new Attribute("SimpleAttribute", "whatever"))</code>.</p> |
2 | 256 |
* |
257 |
* <p>Because {@code String} is a <em>simple type</em>, in the |
|
258 |
* sense of {@link javax.management.openmbean.SimpleType}, it |
|
259 |
* is not changed in the context of an MXBean. The MXBean |
|
260 |
* proxy behaves the same as a Standard MBean proxy (see |
|
261 |
* {@link #newMBeanProxy(MBeanServerConnection, ObjectName, |
|
262 |
* Class) newMBeanProxy}) for the attribute {@code |
|
263 |
* SimpleAttribute}.</p> |
|
264 |
* |
|
265 |
* <li><p>{@code proxy.getMappedAttribute()} will result in a call |
|
266 |
* to {@code mbs.getAttribute("MappedAttribute")}. The MXBean |
|
267 |
* mapping rules mean that the actual type of the attribute {@code |
|
268 |
* MappedAttribute} will be {@link |
|
269 |
* javax.management.openmbean.CompositeData CompositeData} and |
|
270 |
* that is what the {@code mbs.getAttribute} call will return. |
|
271 |
* The proxy will then convert the {@code CompositeData} back into |
|
272 |
* the expected type {@code MemoryUsage} using the MXBean mapping |
|
273 |
* rules.</p> |
|
274 |
* |
|
275 |
* <li><p>Similarly, {@code proxy.setMappedAttribute(memoryUsage)} |
|
276 |
* will convert the {@code MemoryUsage} argument into a {@code |
|
277 |
* CompositeData} before calling {@code mbs.setAttribute}.</p> |
|
278 |
* |
|
279 |
* <li><p>{@code proxy.someOperation("whatever", memoryUsage)} |
|
280 |
* will convert the {@code MemoryUsage} argument into a {@code |
|
281 |
* CompositeData} and call {@code mbs.invoke}. The value returned |
|
282 |
* by {@code mbs.invoke} will be also be a {@code CompositeData}, |
|
283 |
* and the proxy will convert this into the expected type {@code |
|
284 |
* MemoryUsage} using the MXBean mapping rules.</p> |
|
285 |
* |
|
286 |
* </ul> |
|
287 |
* |
|
4156 | 288 |
* <p>The object returned by this method is a |
289 |
* {@link Proxy} whose {@code InvocationHandler} is an |
|
290 |
* {@link MBeanServerInvocationHandler}.</p> |
|
291 |
* |
|
2 | 292 |
* <p>This method is equivalent to {@link |
293 |
* #newMXBeanProxy(MBeanServerConnection, ObjectName, Class, |
|
294 |
* boolean) newMXBeanProxy(connection, objectName, interfaceClass, |
|
295 |
* false)}.</p> |
|
296 |
* |
|
297 |
* @param connection the MBean server to forward to. |
|
298 |
* @param objectName the name of the MBean within |
|
299 |
* {@code connection} to forward to. |
|
300 |
* @param interfaceClass the MXBean interface, |
|
301 |
* which will also be implemented by the returned proxy. |
|
302 |
* |
|
303 |
* @param <T> allows the compiler to know that if the {@code |
|
304 |
* interfaceClass} parameter is {@code MyMXBean.class}, for |
|
305 |
* example, then the return type is {@code MyMXBean}. |
|
306 |
* |
|
307 |
* @return the new proxy instance. |
|
18805
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
308 |
* |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
309 |
* @throws IllegalArgumentException if {@code interfaceClass} is not |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
310 |
* a {@link javax.management.MXBean compliant MXBean interface} |
2 | 311 |
*/ |
312 |
public static <T> T newMXBeanProxy(MBeanServerConnection connection, |
|
313 |
ObjectName objectName, |
|
314 |
Class<T> interfaceClass) { |
|
315 |
return newMXBeanProxy(connection, objectName, interfaceClass, false); |
|
316 |
} |
|
317 |
||
318 |
/** |
|
319 |
* <p>Make a proxy for an MXBean in a local or remote MBean |
|
320 |
* Server that may also support the methods of {@link |
|
321 |
* NotificationEmitter}.</p> |
|
322 |
* |
|
323 |
* <p>This method behaves the same as {@link |
|
324 |
* #newMXBeanProxy(MBeanServerConnection, ObjectName, Class)}, but |
|
687 | 325 |
* additionally, if {@code notificationEmitter} is {@code |
2 | 326 |
* true}, then the MXBean is assumed to be a {@link |
327 |
* NotificationBroadcaster} or {@link NotificationEmitter} and the |
|
328 |
* returned proxy will implement {@link NotificationEmitter} as |
|
329 |
* well as {@code interfaceClass}. A call to {@link |
|
330 |
* NotificationBroadcaster#addNotificationListener} on the proxy |
|
331 |
* will result in a call to {@link |
|
332 |
* MBeanServerConnection#addNotificationListener(ObjectName, |
|
333 |
* NotificationListener, NotificationFilter, Object)}, and |
|
334 |
* likewise for the other methods of {@link |
|
335 |
* NotificationBroadcaster} and {@link NotificationEmitter}.</p> |
|
336 |
* |
|
337 |
* @param connection the MBean server to forward to. |
|
338 |
* @param objectName the name of the MBean within |
|
339 |
* {@code connection} to forward to. |
|
340 |
* @param interfaceClass the MXBean interface, |
|
341 |
* which will also be implemented by the returned proxy. |
|
687 | 342 |
* @param notificationEmitter make the returned proxy |
2 | 343 |
* implement {@link NotificationEmitter} by forwarding its methods |
344 |
* via {@code connection}. |
|
4156 | 345 |
* |
2 | 346 |
* @param <T> allows the compiler to know that if the {@code |
347 |
* interfaceClass} parameter is {@code MyMXBean.class}, for |
|
348 |
* example, then the return type is {@code MyMXBean}. |
|
4156 | 349 |
* |
2 | 350 |
* @return the new proxy instance. |
18805
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
351 |
* |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
352 |
* @throws IllegalArgumentException if {@code interfaceClass} is not |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
353 |
* a {@link javax.management.MXBean compliant MXBean interface} |
2 | 354 |
*/ |
355 |
public static <T> T newMXBeanProxy(MBeanServerConnection connection, |
|
356 |
ObjectName objectName, |
|
357 |
Class<T> interfaceClass, |
|
687 | 358 |
boolean notificationEmitter) { |
18213
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
359 |
return createProxy(connection, objectName, interfaceClass, notificationEmitter, true); |
2 | 360 |
} |
361 |
||
362 |
/** |
|
363 |
* <p>Test whether an interface is an MXBean interface. |
|
18805
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
364 |
* An interface is an MXBean interface if it is public, |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
365 |
* annotated {@link MXBean @MXBean} or {@code @MXBean(true)} |
2 | 366 |
* or if it does not have an {@code @MXBean} annotation |
367 |
* and its name ends with "{@code MXBean}".</p> |
|
368 |
* |
|
369 |
* @param interfaceClass The candidate interface. |
|
370 |
* |
|
18805
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
371 |
* @return true if {@code interfaceClass} is a |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
372 |
* {@link javax.management.MXBean compliant MXBean interface} |
2 | 373 |
* |
374 |
* @throws NullPointerException if {@code interfaceClass} is null. |
|
375 |
*/ |
|
376 |
public static boolean isMXBeanInterface(Class<?> interfaceClass) { |
|
377 |
if (!interfaceClass.isInterface()) |
|
378 |
return false; |
|
18805
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
379 |
if (!Modifier.isPublic(interfaceClass.getModifiers()) && |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
380 |
!Introspector.ALLOW_NONPUBLIC_MBEAN) { |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
381 |
return false; |
b359f8adc8ad
8010285: Enforce the requirement of Management Interfaces being public
jbachorik
parents:
18213
diff
changeset
|
382 |
} |
2 | 383 |
MXBean a = interfaceClass.getAnnotation(MXBean.class); |
384 |
if (a != null) |
|
385 |
return a.value(); |
|
386 |
return interfaceClass.getName().endsWith("MXBean"); |
|
387 |
// We don't bother excluding the case where the name is |
|
388 |
// exactly the string "MXBean" since that would mean there |
|
389 |
// was no package name, which is pretty unlikely in practice. |
|
390 |
} |
|
18213
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
391 |
|
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
392 |
/** |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
393 |
* Centralised M(X)Bean proxy creation code |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
394 |
* @param connection {@linkplain MBeanServerConnection} to use |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
395 |
* @param objectName M(X)Bean object name |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
396 |
* @param interfaceClass M(X)Bean interface class |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
397 |
* @param notificationEmitter Is a notification emitter? |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
398 |
* @param isMXBean Is an MXBean? |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
399 |
* @return Returns an M(X)Bean proxy generated for the provided interface class |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
400 |
* @throws SecurityException |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
401 |
* @throws IllegalArgumentException |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
402 |
*/ |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
403 |
private static <T> T createProxy(MBeanServerConnection connection, |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
404 |
ObjectName objectName, |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
405 |
Class<T> interfaceClass, |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
406 |
boolean notificationEmitter, |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
407 |
boolean isMXBean) { |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
408 |
|
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
409 |
try { |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
410 |
if (isMXBean) { |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
411 |
// Check interface for MXBean compliance |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
412 |
Introspector.testComplianceMXBeanInterface(interfaceClass); |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
413 |
} else { |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
414 |
// Check interface for MBean compliance |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
415 |
Introspector.testComplianceMBeanInterface(interfaceClass); |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
416 |
} |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
417 |
} catch (NotCompliantMBeanException e) { |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
418 |
throw new IllegalArgumentException(e); |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
419 |
} |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
420 |
|
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
421 |
InvocationHandler handler = new MBeanServerInvocationHandler( |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
422 |
connection, objectName, isMXBean); |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
423 |
final Class<?>[] interfaces; |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
424 |
if (notificationEmitter) { |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
425 |
interfaces = |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
426 |
new Class<?>[] {interfaceClass, NotificationEmitter.class}; |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
427 |
} else |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
428 |
interfaces = new Class<?>[] {interfaceClass}; |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
429 |
|
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
430 |
Object proxy = Proxy.newProxyInstance( |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
431 |
interfaceClass.getClassLoader(), |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
432 |
interfaces, |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
433 |
handler); |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
434 |
return interfaceClass.cast(proxy); |
45c8ed869a1b
8008982: Adjust JMX for underlying interface changes
jbachorik
parents:
5506
diff
changeset
|
435 |
} |
2 | 436 |
} |