4904N/A * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 3887N/A * The {@code ManagementFactory} class is a factory class for getting 0N/A * managed beans for the Java platform. 0N/A * This class consists of static methods each of which returns 3887N/A * one or more <i>platform MXBeans</i> representing 0N/A * the management interface of a component of the Java virtual 3887N/A * <h4><a name="MXBean">Platform MXBeans</a></h4> 3887N/A * A platform MXBean is a <i>managed bean</i> that 3887N/A * Instrumentation Specification and only uses a set of basic data types. 3887N/A * A JMX management application and the {@linkplain 3887N/A * #getPlatformMBeanServer platform MBeanServer} 3887N/A * can interoperate without requiring classes for MXBean specific 3887N/A * The data types being transmitted between the JMX connector 3887N/A * server and the connector client are 3887N/A * {@linkplain javax.management.openmbean.OpenType open types} 3887N/A * and this allows interoperation across versions. 3887N/A * the specification of MXBeans</a> for details. 3887N/A * <a name="MXBeanNames"></a> 3887N/A * <p>Each platform MXBean is a {@link PlatformManagedObject} 3887N/A * {@link javax.management.ObjectName ObjectName} for 3887N/A * registration in the platform {@code MBeanServer} as returned by 3887N/A * by the {@link PlatformManagedObject#getObjectName getObjectName} 0N/A * An application can access a platform MXBean in the following ways: 3887N/A * <h5>1. Direct access to an MXBean interface</h5> 3887N/A * <li>Get an MXBean instance by calling the 3887N/A * {@link #getPlatformMXBean(Class) getPlatformMXBean} or 3887N/A * {@link #getPlatformMXBeans(Class) getPlatformMXBeans} method 3887N/A * and access the MXBean locally in the running 0N/A * <li>Construct an MXBean proxy instance that forwards the 0N/A * method calls to a given {@link MBeanServer MBeanServer} by calling 3887N/A * the {@link #getPlatformMXBean(MBeanServerConnection, Class)} or 3887N/A * {@link #getPlatformMXBeans(MBeanServerConnection, Class)} method. 3887N/A * The {@link #newPlatformMXBeanProxy newPlatformMXBeanProxy} method 3887N/A * can also be used to construct an MXBean proxy instance of 3887N/A * a given {@code ObjectName}. 0N/A * A proxy is typically constructed to remotely access 0N/A * an MXBean of another running virtual machine. 3887N/A * <h5>2. Indirect access to an MXBean interface via MBeanServer</h5> 3887N/A * <li>Go through the platform {@code MBeanServer} to access MXBeans 3887N/A * locally or a specific <tt>MBeanServerConnection</tt> to access 0N/A * The attributes and operations of an MXBean use only 0N/A * <em>JMX open types</em> which include basic data types, 0N/A * {@link javax.management.openmbean.CompositeData CompositeData}, 0N/A * and {@link javax.management.openmbean.TabularData TabularData} 0N/A * {@link javax.management.openmbean.OpenType OpenType}. 3887N/A * The mapping is specified in 3887N/A * the {@linkplain javax.management.MXBean MXBean} specification 3887N/A * The {@link #getPlatformManagementInterfaces getPlatformManagementInterfaces} 3887N/A * method returns all management interfaces supported in the Java virtual machine 3887N/A * including the standard management interfaces listed in the tables 3887N/A * below as well as the management interfaces extended by the JDK implementation. 0N/A * A Java virtual machine has a single instance of the following management 0N/A * <th>Management Interface</th> 0N/A * <th>ObjectName</th> 0N/A * <td> {@link ClassLoadingMXBean} </td> 0N/A * <td> {@link #CLASS_LOADING_MXBEAN_NAME 3887N/A * java.lang:type=ClassLoading}</td> 0N/A * <td> {@link MemoryMXBean} </td> 0N/A * <td> {@link #MEMORY_MXBEAN_NAME 3887N/A * java.lang:type=Memory}</td> 0N/A * <td> {@link ThreadMXBean} </td> 0N/A * <td> {@link #THREAD_MXBEAN_NAME 3887N/A * java.lang:type=Threading}</td> 0N/A * <td> {@link RuntimeMXBean} </td> 0N/A * <td> {@link #RUNTIME_MXBEAN_NAME 3887N/A * java.lang:type=Runtime}</td> 0N/A * <td> {@link OperatingSystemMXBean} </td> 0N/A * <td> {@link #OPERATING_SYSTEM_MXBEAN_NAME 3887N/A * java.lang:type=OperatingSystem}</td> 3887N/A * <td> {@link PlatformLoggingMXBean} </td> 3887N/A * <td> {@link java.util.logging.LogManager#LOGGING_MXBEAN_NAME 3887N/A * java.util.logging:type=Logging}</td> 0N/A * A Java virtual machine has zero or a single instance of 0N/A * the following management interfaces. 0N/A * <th>Management Interface</th> 0N/A * <th>ObjectName</th> 0N/A * <td> {@link CompilationMXBean} </td> 0N/A * <td> {@link #COMPILATION_MXBEAN_NAME 3887N/A * java.lang:type=Compilation}</td> 0N/A * A Java virtual machine may have one or more instances of the following 0N/A * management interfaces. 0N/A * <th>Management Interface</th> 0N/A * <th>ObjectName</th> 0N/A * <td> {@link GarbageCollectorMXBean} </td> 0N/A * <td> {@link #GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE 3887N/A * java.lang:type=GarbageCollector}<tt>,name=</tt><i>collector's name</i></td> 0N/A * <td> {@link MemoryManagerMXBean} </td> 0N/A * <td> {@link #MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE 3887N/A * java.lang:type=MemoryManager}<tt>,name=</tt><i>manager's name</i></td> 0N/A * <td> {@link MemoryPoolMXBean} </td> 0N/A * <td> {@link #MEMORY_POOL_MXBEAN_DOMAIN_TYPE 3887N/A * java.lang:type=MemoryPool}<tt>,name=</tt><i>pool's name</i></td> 3887N/A * <td> {@link BufferPoolMXBean} </td> 3887N/A * <td> {@code java.nio:type=BufferPool,name=}<i>pool name</i></td> 178N/A * JMX Specification</a> 0N/A * Ways to Access Management Metrics</a> 0N/A * @see javax.management.MXBean 0N/A * @author Mandy Chung 0N/A // A class with only static fields and methods. 0N/A * String representation of the 0N/A * <tt>ObjectName</tt> for the {@link ClassLoadingMXBean}. 0N/A "java.lang:type=ClassLoading";
0N/A * String representation of the 0N/A * <tt>ObjectName</tt> for the {@link CompilationMXBean}. 0N/A "java.lang:type=Compilation";
0N/A * String representation of the 0N/A * <tt>ObjectName</tt> for the {@link MemoryMXBean}. 0N/A "java.lang:type=Memory";
0N/A * String representation of the 0N/A * <tt>ObjectName</tt> for the {@link OperatingSystemMXBean}. 0N/A "java.lang:type=OperatingSystem";
0N/A * String representation of the 0N/A * <tt>ObjectName</tt> for the {@link RuntimeMXBean}. 0N/A "java.lang:type=Runtime";
0N/A * String representation of the 0N/A * <tt>ObjectName</tt> for the {@link ThreadMXBean}. 0N/A "java.lang:type=Threading";
0N/A * The domain name and the type key property in 0N/A * the <tt>ObjectName</tt> for a {@link GarbageCollectorMXBean}. 0N/A * The unique <tt>ObjectName</tt> for a <tt>GarbageCollectorMXBean</tt> 0N/A * can be formed by appending this string with 0N/A * "<tt>,name=</tt><i>collector's name</i>". 0N/A "java.lang:type=GarbageCollector";
0N/A * The domain name and the type key property in 0N/A * the <tt>ObjectName</tt> for a {@link MemoryManagerMXBean}. 0N/A * The unique <tt>ObjectName</tt> for a <tt>MemoryManagerMXBean</tt> 0N/A * can be formed by appending this string with 0N/A * "<tt>,name=</tt><i>manager's name</i>". 0N/A "java.lang:type=MemoryManager";
0N/A * The domain name and the type key property in 0N/A * the <tt>ObjectName</tt> for a {@link MemoryPoolMXBean}. 0N/A * The unique <tt>ObjectName</tt> for a <tt>MemoryPoolMXBean</tt> 0N/A * can be formed by appending this string with 0N/A * <tt>,name=</tt><i>pool's name</i>. 0N/A "java.lang:type=MemoryPool";
0N/A * Returns the managed bean for the class loading system of 0N/A * the Java virtual machine. 0N/A * @return a {@link ClassLoadingMXBean} object for 0N/A * the Java virtual machine. 0N/A * Returns the managed bean for the memory system of 0N/A * the Java virtual machine. 0N/A * @return a {@link MemoryMXBean} object for the Java virtual machine. 0N/A * Returns the managed bean for the thread system of 0N/A * the Java virtual machine. 0N/A * @return a {@link ThreadMXBean} object for the Java virtual machine. 0N/A * Returns the managed bean for the runtime system of 0N/A * the Java virtual machine. 0N/A * @return a {@link RuntimeMXBean} object for the Java virtual machine. 0N/A * Returns the managed bean for the compilation system of 0N/A * the Java virtual machine. This method returns <tt>null</tt> 0N/A * if the Java virtual machine has no compilation system. 0N/A * @return a {@link CompilationMXBean} object for the Java virtual 0N/A * machine or <tt>null</tt> if the Java virtual machine has 0N/A * no compilation system. 0N/A * Returns the managed bean for the operating system on which 0N/A * the Java virtual machine is running. 0N/A * @return an {@link OperatingSystemMXBean} object for 0N/A * the Java virtual machine. 0N/A * Returns a list of {@link MemoryPoolMXBean} objects in the 0N/A * Java virtual machine. 0N/A * The Java virtual machine can have one or more memory pools. 0N/A * It may add or remove memory pools during execution. 0N/A * @return a list of <tt>MemoryPoolMXBean</tt> objects. 0N/A * Returns a list of {@link MemoryManagerMXBean} objects 0N/A * in the Java virtual machine. 0N/A * The Java virtual machine can have one or more memory managers. 0N/A * It may add or remove memory managers during execution. 0N/A * @return a list of <tt>MemoryManagerMXBean</tt> objects. 0N/A * Returns a list of {@link GarbageCollectorMXBean} objects 0N/A * in the Java virtual machine. 0N/A * The Java virtual machine may have one or more 0N/A * <tt>GarbageCollectorMXBean</tt> objects. 0N/A * It may add or remove <tt>GarbageCollectorMXBean</tt> 0N/A * @return a list of <tt>GarbageCollectorMXBean</tt> objects. 0N/A * Returns the platform {@link javax.management.MBeanServer MBeanServer}. 0N/A * On the first call to this method, it first creates the platform 3887N/A * {@code MBeanServer} by calling the 0N/A * {@link javax.management.MBeanServerFactory#createMBeanServer 0N/A * MBeanServerFactory.createMBeanServer} 3887N/A * method and registers each platform MXBean in this platform 3887N/A * {@code MBeanServer} with its 3887N/A * {@link PlatformManagedObject#getObjectName ObjectName}. 0N/A * This method, in subsequent calls, will simply return the 3887N/A * initially created platform {@code MBeanServer}. 0N/A * MXBeans that get created and destroyed dynamically, for example, 0N/A * memory {@link MemoryPoolMXBean pools} and 0N/A * {@link MemoryManagerMXBean managers}, 0N/A * will automatically be registered and deregistered into the platform 3887N/A * is set, the platform {@code MBeanServer} creation will be done 0N/A * by the specified {@link javax.management.MBeanServerBuilder}. 0N/A * It is recommended that this platform MBeanServer also be used 0N/A * to register other application managed beans 0N/A * besides the platform MXBeans. 0N/A * This will allow all MBeans to be published through the same 3887N/A * {@code MBeanServer} and hence allow for easier network publishing 0N/A * Name conflicts with the platform MXBeans should be avoided. 3887N/A * @return the platform {@code MBeanServer}; the platform 3887N/A * MXBeans are registered into the platform {@code MBeanServer} 0N/A * at the first time this method is called. 0N/A * @exception SecurityException if there is a security manager 0N/A * and the caller does not have the permission required by 0N/A * {@link javax.management.MBeanServerFactory#createMBeanServer}. 0N/A * @see javax.management.MBeanServerFactory 0N/A * @see javax.management.MBeanServerFactory#createMBeanServer 178N/A // Each PlatformComponent represents one management 178N/A // interface. Some MXBean may extend another one. 178N/A // The MXBean instances for one platform component 178N/A // (returned by pc.getMXBeans()) might be also 178N/A // the MXBean instances for another platform component. 178N/A // e.g. com.sun.management.GarbageCollectorMXBean 178N/A // So need to check if an MXBean instance is registered 178N/A // before registering into the platform MBeanServer 0N/A * Returns a proxy for a platform MXBean interface of a 0N/A * given <a href="#MXBeanNames">MXBean name</a> 0N/A * that forwards its method calls through the given 0N/A * <tt>MBeanServerConnection</tt>. 0N/A * <p>This method is equivalent to: 0N/A * {@link java.lang.reflect.Proxy#newProxyInstance 0N/A * Proxy.newProxyInstance}<tt>(mxbeanInterface.getClassLoader(), 0N/A * new Class[] { mxbeanInterface }, handler)</tt> 0N/A * where <tt>handler</tt> is an {@link java.lang.reflect.InvocationHandler 0N/A * InvocationHandler} to which method invocations to the MXBean interface 0N/A * are dispatched. This <tt>handler</tt> converts an input parameter 0N/A * from an MXBean data type to its mapped open type before forwarding 0N/A * to the <tt>MBeanServer</tt> and converts a return value from 0N/A * an MXBean method call through the <tt>MBeanServer</tt> 0N/A * from an open type to the corresponding return type declared in 0N/A * the MXBean interface. 0N/A * If the MXBean is a notification emitter (i.e., 0N/A * {@link javax.management.NotificationEmitter NotificationEmitter}), 0N/A * both the <tt>mxbeanInterface</tt> and <tt>NotificationEmitter</tt> 0N/A * will be implemented by this proxy. 0N/A * <li>Using an MXBean proxy is a convenience remote access to 0N/A * a platform MXBean of a running virtual machine. All method 0N/A * calls to the MXBean proxy are forwarded to an 0N/A * <tt>MBeanServerConnection</tt> where 0N/A * {@link java.io.IOException IOException} may be thrown 0N/A * when the communication problem occurs with the connector server. 0N/A * An application remotely accesses the platform MXBeans using 0N/A * proxy should prepare to catch <tt>IOException</tt> as if 0N/A * accessing with the <tt>MBeanServerConnector</tt> interface.</li> 0N/A * <li>When a client application is designed to remotely access MXBeans 0N/A * for a running virtual machine whose version is different than 0N/A * the version on which the application is running, 0N/A * it should prepare to catch 0N/A * {@link java.io.InvalidObjectException InvalidObjectException} 0N/A * which is thrown when an MXBean proxy receives a name of an 0N/A * enum constant which is missing in the enum class loaded in 0N/A * the client application. </li> 0N/A * <li>{@link javax.management.MBeanServerInvocationHandler 0N/A * MBeanServerInvocationHandler} or its 0N/A * {@link javax.management.MBeanServerInvocationHandler#newProxyInstance 0N/A * newProxyInstance} method cannot be used to create 0N/A * a proxy for a platform MXBean. The proxy object created 0N/A * by <tt>MBeanServerInvocationHandler</tt> does not handle 0N/A * the properties of the platform MXBeans described in 0N/A * the <a href="#MXBean">class specification</a>. 0N/A * @param connection the <tt>MBeanServerConnection</tt> to forward to. 0N/A * @param mxbeanName the name of a platform MXBean within 0N/A * <tt>connection</tt> to forward to. <tt>mxbeanName</tt> must be 0N/A * in the format of {@link ObjectName ObjectName}. 0N/A * @param mxbeanInterface the MXBean interface to be implemented 0N/A * @throws IllegalArgumentException if 0N/A * <li><tt>mxbeanName</tt> is not with a valid 0N/A * {@link ObjectName ObjectName} format, or</li> 0N/A * <li>the named MXBean in the <tt>connection</tt> is 0N/A * not a MXBean provided by the platform, or</li> 0N/A * <li>the named MXBean is not registered in the 0N/A * <tt>MBeanServerConnection</tt>, or</li> 0N/A * <li>the named MXBean is not an instance of the given 0N/A * <tt>mxbeanInterface</tt></li> 0N/A * @throws java.io.IOException if a communication problem 0N/A * occurred when accessing the <tt>MBeanServerConnection</tt>. 0N/A // Only allow MXBean interfaces from rt.jar loaded by the 0N/A // bootstrap class loader 0N/A " is not a platform MXBean");
3887N/A // skip the isInstanceOf check for LoggingMXBean 0N/A // check if the registered MBean is a notification emitter 0N/A // create an MXBean proxy 3887N/A * Returns the platform MXBean implementing 3887N/A * the given {@code mxbeanInterface} which is specified 3887N/A * to have one single instance in the Java virtual machine. 3887N/A * This method may return {@code null} if the management interface 3887N/A * is not implemented in the Java virtual machine (for example, 3887N/A * a Java virtual machine with no compilation system does not 3887N/A * implement {@link CompilationMXBean}); 3887N/A * otherwise, this method is equivalent to calling: 3887N/A * {@link #getPlatformMXBeans(Class) 3887N/A * getPlatformMXBeans(mxbeanInterface)}.get(0); 3887N/A * @param mxbeanInterface a management interface for a platform 3887N/A * MXBean with one single instance in the Java virtual machine 3887N/A * @return the platform MXBean that implements 3887N/A * {@code mxbeanInterface}, or {@code null} if not exist. 3887N/A * @throws IllegalArgumentException if {@code mxbeanInterface} 3887N/A * is not a platform management interface or 3887N/A * not a singleton platform MXBean. 3887N/A " is not a platform management interface");
3887N/A " can have zero or more than one instances");
3887N/A * Returns the list of platform MXBeans implementing 3887N/A * the given {@code mxbeanInterface} in the Java 178N/A * The returned list may contain zero, one, or more instances. 178N/A * The number of instances in the returned list is defined 178N/A * in the specification of the given management interface. 3887N/A * The order is undefined and there is no guarantee that 3887N/A * the list returned is in the same order as previous invocations. 178N/A * @param mxbeanInterface a management interface for a platform 3887N/A * @return the list of platform MXBeans that implement 178N/A * {@code mxbeanInterface}. 178N/A * @throws IllegalArgumentException if {@code mxbeanInterface} 3887N/A * is not a platform management interface. 3887N/A " is not a platform management interface");
3887N/A * Returns the platform MXBean proxy for 3887N/A * {@code mxbeanInterface} which is specified to have one single 3887N/A * instance in a Java virtual machine and the proxy will 3887N/A * forward the method calls through the given {@code MBeanServerConnection}. 3887N/A * This method may return {@code null} if the management interface 3887N/A * is not implemented in the Java virtual machine being monitored 3887N/A * (for example, a Java virtual machine with no compilation system 3887N/A * does not implement {@link CompilationMXBean}); 3887N/A * otherwise, this method is equivalent to calling: 3887N/A * {@link #getPlatformMXBeans(MBeanServerConnection, Class) 3887N/A * getPlatformMXBeans(connection, mxbeanInterface)}.get(0); 3887N/A * @param connection the {@code MBeanServerConnection} to forward to. 3887N/A * @param mxbeanInterface a management interface for a platform 3887N/A * MXBean with one single instance in the Java virtual machine 3887N/A * being monitored, if implemented. 3887N/A * @return the platform MXBean proxy for 3887N/A * forwarding the method calls of the {@code mxbeanInterface} 3887N/A * through the given {@code MBeanServerConnection}, 3887N/A * or {@code null} if not exist. 3887N/A * @throws IllegalArgumentException if {@code mxbeanInterface} 3887N/A * is not a platform management interface or 3887N/A * not a singleton platform MXBean. 3887N/A * @throws java.io.IOException if a communication problem 3887N/A * occurred when accessing the {@code MBeanServerConnection}. 3887N/A * @see #newPlatformMXBeanProxy 3887N/A " is not a platform management interface");
3887N/A " can have zero or more than one instances");
178N/A * Returns the list of the platform MXBean proxies for 178N/A * forwarding the method calls of the {@code mxbeanInterface} 178N/A * through the given {@code MBeanServerConnection}. 178N/A * The returned list may contain zero, one, or more instances. 178N/A * The number of instances in the returned list is defined 178N/A * in the specification of the given management interface. 3887N/A * The order is undefined and there is no guarantee that 3887N/A * the list returned is in the same order as previous invocations. 178N/A * @param connection the {@code MBeanServerConnection} to forward to. 178N/A * @param mxbeanInterface a management interface for a platform 178N/A * @return the list of platform MXBean proxies for 178N/A * forwarding the method calls of the {@code mxbeanInterface} 178N/A * through the given {@code MBeanServerConnection}. 178N/A * @throws IllegalArgumentException if {@code mxbeanInterface} 3887N/A * is not a platform management interface. 178N/A * @throws java.io.IOException if a communication problem 178N/A * occurred when accessing the {@code MBeanServerConnection}. 3887N/A * @see #newPlatformMXBeanProxy 3887N/A " is not a platform management interface");
3887N/A * Returns the set of {@code Class} objects, subinterface of 178N/A * {@link PlatformManagedObject}, representing 178N/A * all management interfaces for 178N/A * monitoring and managing the Java platform. 3887N/A * @return the set of {@code Class} objects, subinterface of 178N/A * {@link PlatformManagedObject} representing 178N/A * the management interfaces for 178N/A * monitoring and managing the Java platform. 0N/A "javax.management.NotificationEmitter";
178N/A // Make DynamicMBean out of MXBean by wrapping it with a StandardMBean