207 * <th>ObjectName</th> |
207 * <th>ObjectName</th> |
208 * </tr> |
208 * </tr> |
209 * <tr> |
209 * <tr> |
210 * <td> {@link GarbageCollectorMXBean} </td> |
210 * <td> {@link GarbageCollectorMXBean} </td> |
211 * <td> {@link #GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE |
211 * <td> {@link #GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE |
212 * java.lang:type=GarbageCollector}<tt>,name=</tt><i>collector's name</i></td> |
212 * java.lang:type=GarbageCollector}{@code ,name=}<i>collector's name</i></td> |
213 * </tr> |
213 * </tr> |
214 * <tr> |
214 * <tr> |
215 * <td> {@link MemoryManagerMXBean} </td> |
215 * <td> {@link MemoryManagerMXBean} </td> |
216 * <td> {@link #MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE |
216 * <td> {@link #MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE |
217 * java.lang:type=MemoryManager}<tt>,name=</tt><i>manager's name</i></td> |
217 * java.lang:type=MemoryManager}{@code ,name=}<i>manager's name</i></td> |
218 * </tr> |
218 * </tr> |
219 * <tr> |
219 * <tr> |
220 * <td> {@link MemoryPoolMXBean} </td> |
220 * <td> {@link MemoryPoolMXBean} </td> |
221 * <td> {@link #MEMORY_POOL_MXBEAN_DOMAIN_TYPE |
221 * <td> {@link #MEMORY_POOL_MXBEAN_DOMAIN_TYPE |
222 * java.lang:type=MemoryPool}<tt>,name=</tt><i>pool's name</i></td> |
222 * java.lang:type=MemoryPool}{@code ,name=}<i>pool's name</i></td> |
223 * </tr> |
223 * </tr> |
224 * <tr> |
224 * <tr> |
225 * <td> {@link BufferPoolMXBean} </td> |
225 * <td> {@link BufferPoolMXBean} </td> |
226 * <td> {@code java.nio:type=BufferPool,name=}<i>pool name</i></td> |
226 * <td> {@code java.nio:type=BufferPool,name=}<i>pool name</i></td> |
227 * </tr> |
227 * </tr> |
241 // A class with only static fields and methods. |
241 // A class with only static fields and methods. |
242 private ManagementFactory() {}; |
242 private ManagementFactory() {}; |
243 |
243 |
244 /** |
244 /** |
245 * String representation of the |
245 * String representation of the |
246 * <tt>ObjectName</tt> for the {@link ClassLoadingMXBean}. |
246 * {@code ObjectName} for the {@link ClassLoadingMXBean}. |
247 */ |
247 */ |
248 public final static String CLASS_LOADING_MXBEAN_NAME = |
248 public final static String CLASS_LOADING_MXBEAN_NAME = |
249 "java.lang:type=ClassLoading"; |
249 "java.lang:type=ClassLoading"; |
250 |
250 |
251 /** |
251 /** |
252 * String representation of the |
252 * String representation of the |
253 * <tt>ObjectName</tt> for the {@link CompilationMXBean}. |
253 * {@code ObjectName} for the {@link CompilationMXBean}. |
254 */ |
254 */ |
255 public final static String COMPILATION_MXBEAN_NAME = |
255 public final static String COMPILATION_MXBEAN_NAME = |
256 "java.lang:type=Compilation"; |
256 "java.lang:type=Compilation"; |
257 |
257 |
258 /** |
258 /** |
259 * String representation of the |
259 * String representation of the |
260 * <tt>ObjectName</tt> for the {@link MemoryMXBean}. |
260 * {@code ObjectName} for the {@link MemoryMXBean}. |
261 */ |
261 */ |
262 public final static String MEMORY_MXBEAN_NAME = |
262 public final static String MEMORY_MXBEAN_NAME = |
263 "java.lang:type=Memory"; |
263 "java.lang:type=Memory"; |
264 |
264 |
265 /** |
265 /** |
266 * String representation of the |
266 * String representation of the |
267 * <tt>ObjectName</tt> for the {@link OperatingSystemMXBean}. |
267 * {@code ObjectName} for the {@link OperatingSystemMXBean}. |
268 */ |
268 */ |
269 public final static String OPERATING_SYSTEM_MXBEAN_NAME = |
269 public final static String OPERATING_SYSTEM_MXBEAN_NAME = |
270 "java.lang:type=OperatingSystem"; |
270 "java.lang:type=OperatingSystem"; |
271 |
271 |
272 /** |
272 /** |
273 * String representation of the |
273 * String representation of the |
274 * <tt>ObjectName</tt> for the {@link RuntimeMXBean}. |
274 * {@code ObjectName} for the {@link RuntimeMXBean}. |
275 */ |
275 */ |
276 public final static String RUNTIME_MXBEAN_NAME = |
276 public final static String RUNTIME_MXBEAN_NAME = |
277 "java.lang:type=Runtime"; |
277 "java.lang:type=Runtime"; |
278 |
278 |
279 /** |
279 /** |
280 * String representation of the |
280 * String representation of the |
281 * <tt>ObjectName</tt> for the {@link ThreadMXBean}. |
281 * {@code ObjectName} for the {@link ThreadMXBean}. |
282 */ |
282 */ |
283 public final static String THREAD_MXBEAN_NAME = |
283 public final static String THREAD_MXBEAN_NAME = |
284 "java.lang:type=Threading"; |
284 "java.lang:type=Threading"; |
285 |
285 |
286 /** |
286 /** |
287 * The domain name and the type key property in |
287 * The domain name and the type key property in |
288 * the <tt>ObjectName</tt> for a {@link GarbageCollectorMXBean}. |
288 * the {@code ObjectName} for a {@link GarbageCollectorMXBean}. |
289 * The unique <tt>ObjectName</tt> for a <tt>GarbageCollectorMXBean</tt> |
289 * The unique {@code ObjectName} for a {@code GarbageCollectorMXBean} |
290 * can be formed by appending this string with |
290 * can be formed by appending this string with |
291 * "<tt>,name=</tt><i>collector's name</i>". |
291 * "{@code ,name=}<i>collector's name</i>". |
292 */ |
292 */ |
293 public final static String GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE = |
293 public final static String GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE = |
294 "java.lang:type=GarbageCollector"; |
294 "java.lang:type=GarbageCollector"; |
295 |
295 |
296 /** |
296 /** |
297 * The domain name and the type key property in |
297 * The domain name and the type key property in |
298 * the <tt>ObjectName</tt> for a {@link MemoryManagerMXBean}. |
298 * the {@code ObjectName} for a {@link MemoryManagerMXBean}. |
299 * The unique <tt>ObjectName</tt> for a <tt>MemoryManagerMXBean</tt> |
299 * The unique {@code ObjectName} for a {@code MemoryManagerMXBean} |
300 * can be formed by appending this string with |
300 * can be formed by appending this string with |
301 * "<tt>,name=</tt><i>manager's name</i>". |
301 * "{@code ,name=}<i>manager's name</i>". |
302 */ |
302 */ |
303 public final static String MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE= |
303 public final static String MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE= |
304 "java.lang:type=MemoryManager"; |
304 "java.lang:type=MemoryManager"; |
305 |
305 |
306 /** |
306 /** |
307 * The domain name and the type key property in |
307 * The domain name and the type key property in |
308 * the <tt>ObjectName</tt> for a {@link MemoryPoolMXBean}. |
308 * the {@code ObjectName} for a {@link MemoryPoolMXBean}. |
309 * The unique <tt>ObjectName</tt> for a <tt>MemoryPoolMXBean</tt> |
309 * The unique {@code ObjectName} for a {@code MemoryPoolMXBean} |
310 * can be formed by appending this string with |
310 * can be formed by appending this string with |
311 * <tt>,name=</tt><i>pool's name</i>. |
311 * {@code ,name=}<i>pool's name</i>. |
312 */ |
312 */ |
313 public final static String MEMORY_POOL_MXBEAN_DOMAIN_TYPE= |
313 public final static String MEMORY_POOL_MXBEAN_DOMAIN_TYPE= |
314 "java.lang:type=MemoryPool"; |
314 "java.lang:type=MemoryPool"; |
315 |
315 |
316 /** |
316 /** |
483 |
483 |
484 /** |
484 /** |
485 * Returns a proxy for a platform MXBean interface of a |
485 * Returns a proxy for a platform MXBean interface of a |
486 * given <a href="#MXBeanNames">MXBean name</a> |
486 * given <a href="#MXBeanNames">MXBean name</a> |
487 * that forwards its method calls through the given |
487 * that forwards its method calls through the given |
488 * <tt>MBeanServerConnection</tt>. |
488 * {@code MBeanServerConnection}. |
489 * |
489 * |
490 * <p>This method is equivalent to: |
490 * <p>This method is equivalent to: |
491 * <blockquote> |
491 * <blockquote> |
492 * {@link java.lang.reflect.Proxy#newProxyInstance |
492 * {@link java.lang.reflect.Proxy#newProxyInstance |
493 * Proxy.newProxyInstance}<tt>(mxbeanInterface.getClassLoader(), |
493 * Proxy.newProxyInstance}{@code (mxbeanInterface.getClassLoader(), |
494 * new Class[] { mxbeanInterface }, handler)</tt> |
494 * new Class[] { mxbeanInterface }, handler)} |
495 * </blockquote> |
495 * </blockquote> |
496 * |
496 * |
497 * where <tt>handler</tt> is an {@link java.lang.reflect.InvocationHandler |
497 * where {@code handler} is an {@link java.lang.reflect.InvocationHandler |
498 * InvocationHandler} to which method invocations to the MXBean interface |
498 * InvocationHandler} to which method invocations to the MXBean interface |
499 * are dispatched. This <tt>handler</tt> converts an input parameter |
499 * are dispatched. This {@code handler} converts an input parameter |
500 * from an MXBean data type to its mapped open type before forwarding |
500 * from an MXBean data type to its mapped open type before forwarding |
501 * to the <tt>MBeanServer</tt> and converts a return value from |
501 * to the {@code MBeanServer} and converts a return value from |
502 * an MXBean method call through the <tt>MBeanServer</tt> |
502 * an MXBean method call through the {@code MBeanServer} |
503 * from an open type to the corresponding return type declared in |
503 * from an open type to the corresponding return type declared in |
504 * the MXBean interface. |
504 * the MXBean interface. |
505 * |
505 * |
506 * <p> |
506 * <p> |
507 * If the MXBean is a notification emitter (i.e., |
507 * If the MXBean is a notification emitter (i.e., |
508 * it implements |
508 * it implements |
509 * {@link javax.management.NotificationEmitter NotificationEmitter}), |
509 * {@link javax.management.NotificationEmitter NotificationEmitter}), |
510 * both the <tt>mxbeanInterface</tt> and <tt>NotificationEmitter</tt> |
510 * both the {@code mxbeanInterface} and {@code NotificationEmitter} |
511 * will be implemented by this proxy. |
511 * will be implemented by this proxy. |
512 * |
512 * |
513 * <p> |
513 * <p> |
514 * <b>Notes:</b> |
514 * <b>Notes:</b> |
515 * <ol> |
515 * <ol> |
516 * <li>Using an MXBean proxy is a convenience remote access to |
516 * <li>Using an MXBean proxy is a convenience remote access to |
517 * a platform MXBean of a running virtual machine. All method |
517 * a platform MXBean of a running virtual machine. All method |
518 * calls to the MXBean proxy are forwarded to an |
518 * calls to the MXBean proxy are forwarded to an |
519 * <tt>MBeanServerConnection</tt> where |
519 * {@code MBeanServerConnection} where |
520 * {@link java.io.IOException IOException} may be thrown |
520 * {@link java.io.IOException IOException} may be thrown |
521 * when the communication problem occurs with the connector server. |
521 * when the communication problem occurs with the connector server. |
522 * An application remotely accesses the platform MXBeans using |
522 * An application remotely accesses the platform MXBeans using |
523 * proxy should prepare to catch <tt>IOException</tt> as if |
523 * proxy should prepare to catch {@code IOException} as if |
524 * accessing with the <tt>MBeanServerConnector</tt> interface.</li> |
524 * accessing with the {@code MBeanServerConnector} interface.</li> |
525 * |
525 * |
526 * <li>When a client application is designed to remotely access MXBeans |
526 * <li>When a client application is designed to remotely access MXBeans |
527 * for a running virtual machine whose version is different than |
527 * for a running virtual machine whose version is different than |
528 * the version on which the application is running, |
528 * the version on which the application is running, |
529 * it should prepare to catch |
529 * it should prepare to catch |
535 * <li>{@link javax.management.MBeanServerInvocationHandler |
535 * <li>{@link javax.management.MBeanServerInvocationHandler |
536 * MBeanServerInvocationHandler} or its |
536 * MBeanServerInvocationHandler} or its |
537 * {@link javax.management.MBeanServerInvocationHandler#newProxyInstance |
537 * {@link javax.management.MBeanServerInvocationHandler#newProxyInstance |
538 * newProxyInstance} method cannot be used to create |
538 * newProxyInstance} method cannot be used to create |
539 * a proxy for a platform MXBean. The proxy object created |
539 * a proxy for a platform MXBean. The proxy object created |
540 * by <tt>MBeanServerInvocationHandler</tt> does not handle |
540 * by {@code MBeanServerInvocationHandler} does not handle |
541 * the properties of the platform MXBeans described in |
541 * the properties of the platform MXBeans described in |
542 * the <a href="#MXBean">class specification</a>. |
542 * the <a href="#MXBean">class specification</a>. |
543 *</li> |
543 *</li> |
544 * </ol> |
544 * </ol> |
545 * |
545 * |
546 * @param connection the <tt>MBeanServerConnection</tt> to forward to. |
546 * @param connection the {@code MBeanServerConnection} to forward to. |
547 * @param mxbeanName the name of a platform MXBean within |
547 * @param mxbeanName the name of a platform MXBean within |
548 * <tt>connection</tt> to forward to. <tt>mxbeanName</tt> must be |
548 * {@code connection} to forward to. {@code mxbeanName} must be |
549 * in the format of {@link ObjectName ObjectName}. |
549 * in the format of {@link ObjectName ObjectName}. |
550 * @param mxbeanInterface the MXBean interface to be implemented |
550 * @param mxbeanInterface the MXBean interface to be implemented |
551 * by the proxy. |
551 * by the proxy. |
552 * @param <T> an {@code mxbeanInterface} type parameter |
552 * @param <T> an {@code mxbeanInterface} type parameter |
553 * |
553 * |
554 * @return a proxy for a platform MXBean interface of a |
554 * @return a proxy for a platform MXBean interface of a |
555 * given <a href="#MXBeanNames">MXBean name</a> |
555 * given <a href="#MXBeanNames">MXBean name</a> |
556 * that forwards its method calls through the given |
556 * that forwards its method calls through the given |
557 * <tt>MBeanServerConnection</tt>, or {@code null} if not exist. |
557 * {@code MBeanServerConnection}, or {@code null} if not exist. |
558 * |
558 * |
559 * @throws IllegalArgumentException if |
559 * @throws IllegalArgumentException if |
560 * <ul> |
560 * <ul> |
561 * <li><tt>mxbeanName</tt> is not with a valid |
561 * <li>{@code mxbeanName} is not with a valid |
562 * {@link ObjectName ObjectName} format, or</li> |
562 * {@link ObjectName ObjectName} format, or</li> |
563 * <li>the named MXBean in the <tt>connection</tt> is |
563 * <li>the named MXBean in the {@code connection} is |
564 * not a MXBean provided by the platform, or</li> |
564 * not a MXBean provided by the platform, or</li> |
565 * <li>the named MXBean is not registered in the |
565 * <li>the named MXBean is not registered in the |
566 * <tt>MBeanServerConnection</tt>, or</li> |
566 * {@code MBeanServerConnection}, or</li> |
567 * <li>the named MXBean is not an instance of the given |
567 * <li>the named MXBean is not an instance of the given |
568 * <tt>mxbeanInterface</tt></li> |
568 * {@code mxbeanInterface}</li> |
569 * </ul> |
569 * </ul> |
570 * |
570 * |
571 * @throws java.io.IOException if a communication problem |
571 * @throws java.io.IOException if a communication problem |
572 * occurred when accessing the <tt>MBeanServerConnection</tt>. |
572 * occurred when accessing the {@code MBeanServerConnection}. |
573 */ |
573 */ |
574 public static <T> T |
574 public static <T> T |
575 newPlatformMXBeanProxy(MBeanServerConnection connection, |
575 newPlatformMXBeanProxy(MBeanServerConnection connection, |
576 String mxbeanName, |
576 String mxbeanName, |
577 Class<T> mxbeanInterface) |
577 Class<T> mxbeanInterface) |