public class ManagementFactory extends Object
ManagementFactory class is a factory class for getting managed beans for the Java platform. This class consists of static methods each of which returns one or more
platform MXBeans representing the management interface of a component of the Java virtual machine.
A platform MXBean is a managed bean that conforms to the JMX Instrumentation Specification and only uses a set of basic data types. A JMX management application and the platform MBeanServer can interoperate without requiring classes for MXBean specific data types. The data types being transmitted between the JMX connector server and the connector client are open types and this allows interoperation across versions. See the specification of MXBeans for details.
Each platform MXBean is a PlatformManagedObject and it has a unique ObjectName for registration in the platform MBeanServer as returned by by the getObjectName method.
An application can access a platform MXBean in the following ways:
- Get an MXBean instance by calling the
getPlatformMXBeanorgetPlatformMXBeansmethod and access the MXBean locally in the running virtual machine.- Construct an MXBean proxy instance that forwards the method calls to a given
MBeanServerby calling thegetPlatformMXBean(MBeanServerConnection, Class)orgetPlatformMXBeans(MBeanServerConnection, Class)method. ThenewPlatformMXBeanProxymethod can also be used to construct an MXBean proxy instance of a givenObjectName. A proxy is typically constructed to remotely access an MXBean of another running virtual machine.2. Indirect access to an MXBean interface via MBeanServer
- Go through the platform
MBeanServerto access MXBeans locally or a specific MBeanServerConnection to access MXBeans remotely. The attributes and operations of an MXBean use only JMX open types which include basic data types,CompositeData, andTabularDatadefined inOpenType. The mapping is specified in the MXBean specification for details.
The getPlatformManagementInterfaces method returns all management interfaces supported in the Java virtual machine including the standard management interfaces listed in the tables below as well as the management interfaces extended by the JDK implementation.
A Java virtual machine has a single instance of the following management interfaces:
A Java virtual machine has zero or a single instance of the following management interfaces.
Management Interface ObjectName CompilationMXBeanjava.lang:type=Compilation
A Java virtual machine may have one or more instances of the following management interfaces.
Management Interface ObjectName GarbageCollectorMXBeanjava.lang:type=GarbageCollector,name=collector's nameMemoryManagerMXBeanjava.lang:type=MemoryManager,name=manager's nameMemoryPoolMXBeanjava.lang:type=MemoryPool,name=pool's nameBufferPoolMXBeanjava.nio:type=BufferPool,name=pool name
MXBean
| Modifier and Type | Field and Description |
|---|---|
static String |
CLASS_LOADING_MXBEAN_NAME
String representation of the
ObjectName for the
ClassLoadingMXBean.
|
static String |
COMPILATION_MXBEAN_NAME
String representation of the
ObjectName for the
CompilationMXBean.
|
static String |
GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
The domain name and the type key property in the
ObjectName for a
GarbageCollectorMXBean.
|
static String |
MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
The domain name and the type key property in the
ObjectName for a
MemoryManagerMXBean.
|
static String |
MEMORY_MXBEAN_NAME
String representation of the
ObjectName for the
MemoryMXBean.
|
static String |
MEMORY_POOL_MXBEAN_DOMAIN_TYPE
The domain name and the type key property in the
ObjectName for a
MemoryPoolMXBean.
|
static String |
OPERATING_SYSTEM_MXBEAN_NAME
String representation of the
ObjectName for the
OperatingSystemMXBean.
|
static String |
RUNTIME_MXBEAN_NAME
String representation of the
ObjectName for the
RuntimeMXBean.
|
static String |
THREAD_MXBEAN_NAME
String representation of the
ObjectName for the
ThreadMXBean.
|
| Modifier and Type | Method and Description |
|---|---|
static ClassLoadingMXBean |
getClassLoadingMXBean()
Returns the managed bean for the class loading system of the Java virtual machine.
|
static CompilationMXBean |
getCompilationMXBean()
Returns the managed bean for the compilation system of the Java virtual machine.
|
static List |
getGarbageCollectorMXBeans()
Returns a list of
GarbageCollectorMXBean objects in the Java virtual machine.
|
static List |
getMemoryManagerMXBeans()
Returns a list of
MemoryManagerMXBean objects in the Java virtual machine.
|
static MemoryMXBean |
getMemoryMXBean()
Returns the managed bean for the memory system of the Java virtual machine.
|
static List |
getMemoryPoolMXBeans()
Returns a list of
MemoryPoolMXBean objects in the Java virtual machine.
|
static OperatingSystemMXBean |
getOperatingSystemMXBean()
Returns the managed bean for the operating system on which the Java virtual machine is running.
|
static Set |
getPlatformManagementInterfaces()
Returns the set of
Class objects, subinterface of
PlatformManagedObject, representing all management interfaces for monitoring and managing the Java platform.
|
static MBeanServer |
getPlatformMBeanServer()
Returns the platform
MBeanServer.
|
static <T extends PlatformManagedObject |
getPlatformMXBean(Class
Returns the platform MXBean implementing the given
mxbeanInterface which is specified to have one single instance in the Java virtual machine.
|
static <T extends PlatformManagedObject |
getPlatformMXBean(MBeanServerConnection
Returns the platform MXBean proxy for
mxbeanInterface which is specified to have one single instance in a Java virtual machine and the proxy will forward the method calls through the given
MBeanServerConnection.
|
static <T extends PlatformManagedObject |
getPlatformMXBeans(Class
Returns the list of platform MXBeans implementing the given
mxbeanInterface in the Java virtual machine.
|
static <T extends PlatformManagedObject |
getPlatformMXBeans(MBeanServerConnection
Returns the list of the platform MXBean proxies for forwarding the method calls of the
mxbeanInterface through the given
MBeanServerConnection.
|
static RuntimeMXBean |
getRuntimeMXBean()
Returns the managed bean for the runtime system of the Java virtual machine.
|
static ThreadMXBean |
getThreadMXBean()
Returns the managed bean for the thread system of the Java virtual machine.
|
static <T> T |
newPlatformMXBeanProxy(MBeanServerConnection
Returns a proxy for a platform MXBean interface of a given
MXBean name that forwards its method calls through the given
MBeanServerConnection.
|
public static final StringCLASS_LOADING_MXBEAN_NAME
ClassLoadingMXBean.
public static final StringCOMPILATION_MXBEAN_NAME
CompilationMXBean.
public static final StringMEMORY_MXBEAN_NAME
MemoryMXBean.
public static final StringOPERATING_SYSTEM_MXBEAN_NAME
OperatingSystemMXBean.
public static final StringRUNTIME_MXBEAN_NAME
RuntimeMXBean.
public static final StringTHREAD_MXBEAN_NAME
ThreadMXBean.
public static final StringGARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
GarbageCollectorMXBean. The unique
ObjectName for a
GarbageCollectorMXBean can be formed by appending this string with "
,name=
collector's name".
public static final StringMEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
MemoryManagerMXBean. The unique
ObjectName for a
MemoryManagerMXBean can be formed by appending this string with "
,name=
manager's name".
public static final StringMEMORY_POOL_MXBEAN_DOMAIN_TYPE
MemoryPoolMXBean. The unique
ObjectName for a
MemoryPoolMXBean can be formed by appending this string with
,name=
pool's name.
public static ClassLoadingMXBeangetClassLoadingMXBean()
ClassLoadingMXBean object for the Java virtual machine.
public static MemoryMXBeangetMemoryMXBean()
MemoryMXBean object for the Java virtual machine.
public static ThreadMXBeangetThreadMXBean()
ThreadMXBean object for the Java virtual machine.
public static RuntimeMXBeangetRuntimeMXBean()
RuntimeMXBean object for the Java virtual machine.
public static CompilationMXBeangetCompilationMXBean()
CompilationMXBean object for the Java virtual machine or
null if the Java virtual machine has no compilation system.
public static OperatingSystemMXBeangetOperatingSystemMXBean()
OperatingSystemMXBean object for the Java virtual machine.
public static List<MemoryPoolMXBean > getMemoryPoolMXBeans()
MemoryPoolMXBean objects in the Java virtual machine. The Java virtual machine can have one or more memory pools. It may add or remove memory pools during execution.
public static List<MemoryManagerMXBean > getMemoryManagerMXBeans()
MemoryManagerMXBean objects in the Java virtual machine. The Java virtual machine can have one or more memory managers. It may add or remove memory managers during execution.
public static List<GarbageCollectorMXBean > getGarbageCollectorMXBeans()
GarbageCollectorMXBean objects in the Java virtual machine. The Java virtual machine may have one or more
GarbageCollectorMXBean objects. It may add or remove
GarbageCollectorMXBean during execution.
public static MBeanServergetPlatformMBeanServer()
MBeanServer. On the first call to this method, it first creates the platform
MBeanServer by calling the
MBeanServerFactory.createMBeanServer method and registers each platform MXBean in this platform
MBeanServer with its
ObjectName. This method, in subsequent calls, will simply return the initially created platform
MBeanServer.
MXBeans that get created and destroyed dynamically, for example, memory pools and managers, will automatically be registered and deregistered into the platform MBeanServer.
If the system property javax.management.builder.initial is set, the platform MBeanServer creation will be done by the specified MBeanServerBuilder.
It is recommended that this platform MBeanServer also be used to register other application managed beans besides the platform MXBeans. This will allow all MBeans to be published through the same MBeanServer and hence allow for easier network publishing and discovery. Name conflicts with the platform MXBeans should be avoided.
MBeanServer; the platform MXBeans are registered into the platform
MBeanServer at the first time this method is called.
SecurityException - if there is a security manager and the caller does not have the permission required by
MBeanServerFactory.createMBeanServer() .
MBeanServerFactory,
MBeanServerFactory.createMBeanServer()
public static <T> T newPlatformMXBeanProxy(MBeanServerConnectionconnection, String mxbeanName, Class <T> mxbeanInterface) throws IOException
This method is equivalent to:
Proxy.newProxyInstance
(mxbeanInterface.getClassLoader(), new Class[] { mxbeanInterface }, handler)
where
handler is an
InvocationHandler to which method invocations to the MXBean interface are dispatched. This
handler converts an input parameter from an MXBean data type to its mapped open type before forwarding to the
MBeanServer and converts a return value from an MXBean method call through the
MBeanServer from an open type to the corresponding return type declared in the MXBean interface.
If the MXBean is a notification emitter (i.e., it implements NotificationEmitter), both the mxbeanInterface and NotificationEmitter will be implemented by this proxy.
Notes:
IOException may be thrown when the communication problem occurs with the connector server. An application remotely accesses the platform MXBeans using proxy should prepare to catch IOException as if accessing with the MBeanServerConnector interface.InvalidObjectException which is thrown when an MXBean proxy receives a name of an enum constant which is missing in the enum class loaded in the client application. MBeanServerInvocationHandler or its newProxyInstance method cannot be used to create a proxy for a platform MXBean. The proxy object created by MBeanServerInvocationHandler does not handle the properties of the platform MXBeans described in the class specification. T - an
mxbeanInterface type parameter
connection - the
MBeanServerConnection to forward to.
mxbeanName - the name of a platform MXBean within
connection to forward to.
mxbeanName must be in the format of
ObjectName.
mxbeanInterface - the MXBean interface to be implemented by the proxy.
null if not exist.
IllegalArgumentException - if
ObjectName format, orIOException - if a communication problem occurred when accessing the
MBeanServerConnection.
public static <T extends PlatformManagedObject> T getPlatformMXBean(Class <T> mxbeanInterface)
mxbeanInterface which is specified to have one single instance in the Java virtual machine. This method may return
null if the management interface is not implemented in the Java virtual machine (for example, a Java virtual machine with no compilation system does not implement
CompilationMXBean); otherwise, this method is equivalent to calling:
getPlatformMXBeans(mxbeanInterface).get(0);
T - an
mxbeanInterface type parameter
mxbeanInterface - a management interface for a platform MXBean with one single instance in the Java virtual machine if implemented.
mxbeanInterface, or
null if not exist.
IllegalArgumentException - if
mxbeanInterface is not a platform management interface or not a singleton platform MXBean.
public static <T extends PlatformManagedObject> List <T> getPlatformMXBeans(Class <T> mxbeanInterface)
mxbeanInterface in the Java virtual machine. The returned list may contain zero, one, or more instances. The number of instances in the returned list is defined in the specification of the given management interface. The order is undefined and there is no guarantee that the list returned is in the same order as previous invocations.
T - an
mxbeanInterface type parameter
mxbeanInterface - a management interface for a platform MXBean
mxbeanInterface.
IllegalArgumentException - if
mxbeanInterface is not a platform management interface.
public static <T extends PlatformManagedObject> T getPlatformMXBean(MBeanServerConnection connection, Class <T> mxbeanInterface) throws IOException
mxbeanInterface which is specified to have one single instance in a Java virtual machine and the proxy will forward the method calls through the given
MBeanServerConnection. This method may return
null if the management interface is not implemented in the Java virtual machine being monitored (for example, a Java virtual machine with no compilation system does not implement
CompilationMXBean); otherwise, this method is equivalent to calling:
getPlatformMXBeans(connection, mxbeanInterface).get(0);
T - an
mxbeanInterface type parameter
connection - the
MBeanServerConnection to forward to.
mxbeanInterface - a management interface for a platform MXBean with one single instance in the Java virtual machine being monitored, if implemented.
mxbeanInterface through the given
MBeanServerConnection, or
null if not exist.
IllegalArgumentException - if
mxbeanInterface is not a platform management interface or not a singleton platform MXBean.
IOException - if a communication problem occurred when accessing the
MBeanServerConnection.
newPlatformMXBeanProxy(javax.management.MBeanServerConnection, java.lang.String, java.lang.Class<T>)
public static <T extends PlatformManagedObject> List <T> getPlatformMXBeans(MBeanServerConnection connection, Class <T> mxbeanInterface) throws IOException
mxbeanInterface through the given
MBeanServerConnection. The returned list may contain zero, one, or more instances. The number of instances in the returned list is defined in the specification of the given management interface. The order is undefined and there is no guarantee that the list returned is in the same order as previous invocations.
T - an
mxbeanInterface type parameter
connection - the
MBeanServerConnection to forward to.
mxbeanInterface - a management interface for a platform MXBean
mxbeanInterface through the given
MBeanServerConnection.
IllegalArgumentException - if
mxbeanInterface is not a platform management interface.
IOException - if a communication problem occurred when accessing the
MBeanServerConnection.
newPlatformMXBeanProxy(javax.management.MBeanServerConnection, java.lang.String, java.lang.Class<T>)
public static Set<Class <? extends PlatformManagedObject >> getPlatformManagementInterfaces()
Class objects, subinterface of
PlatformManagedObject, representing all management interfaces for monitoring and managing the Java platform.
Class objects, subinterface of
PlatformManagedObject representing the management interfaces for monitoring and managing the Java platform.