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.
Platform MXBeans
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:
1. Direct access to an MXBean interface
- 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 specificMBeanServerConnectionto 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 |
|---|---|
CompilationMXBean |
java.lang:type=Compilation |
A Java virtual machine may have one or more instances of the following management interfaces.
| Management Interface | ObjectName |
|---|---|
GarbageCollectorMXBean |
java.lang:type=GarbageCollector,name=collector's name |
MemoryManagerMXBean |
java.lang:type=MemoryManager,name=manager's name |
MemoryPoolMXBean |
java.lang:type=MemoryPool,name=pool's name |
BufferPoolMXBean |
java.nio:type=BufferPool,name=pool name |
- Since:
- 1.5
- See Also:
-
JMX Specification,
Ways to Access Management Metrics,
MXBean
-
Field Summary
Fields Modifier and Type Field Description static StringCLASS_LOADING_MXBEAN_NAMEString representation of theObjectNamefor theClassLoadingMXBean.static StringCOMPILATION_MXBEAN_NAMEString representation of theObjectNamefor theCompilationMXBean.static StringGARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPEThe domain name and the type key property in theObjectNamefor aGarbageCollectorMXBean.static StringMEMORY_MANAGER_MXBEAN_DOMAIN_TYPEThe domain name and the type key property in theObjectNamefor aMemoryManagerMXBean.static StringMEMORY_MXBEAN_NAMEString representation of theObjectNamefor theMemoryMXBean.static StringMEMORY_POOL_MXBEAN_DOMAIN_TYPEThe domain name and the type key property in theObjectNamefor aMemoryPoolMXBean.static StringOPERATING_SYSTEM_MXBEAN_NAMEString representation of theObjectNamefor theOperatingSystemMXBean.static StringRUNTIME_MXBEAN_NAMEString representation of theObjectNamefor theRuntimeMXBean.static StringTHREAD_MXBEAN_NAMEString representation of theObjectNamefor theThreadMXBean. -
Method Summary
Modifier and Type Method Description static ClassLoadingMXBeangetClassLoadingMXBean()Returns the managed bean for the class loading system of the Java virtual machine.static CompilationMXBeangetCompilationMXBean()Returns the managed bean for the compilation system of the Java virtual machine.static List<GarbageCollectorMXBean>getGarbageCollectorMXBeans()Returns a list ofGarbageCollectorMXBeanobjects in the Java virtual machine.static List<MemoryManagerMXBean>getMemoryManagerMXBeans()Returns a list ofMemoryManagerMXBeanobjects in the Java virtual machine.static MemoryMXBeangetMemoryMXBean()Returns the managed bean for the memory system of the Java virtual machine.static List<MemoryPoolMXBean>getMemoryPoolMXBeans()Returns a list ofMemoryPoolMXBeanobjects in the Java virtual machine.static OperatingSystemMXBeangetOperatingSystemMXBean()Returns the managed bean for the operating system on which the Java virtual machine is running.static Set<Class<? extends PlatformManagedObject>>getPlatformManagementInterfaces()Returns the set ofClassobjects, subinterface ofPlatformManagedObject, representing all management interfaces for monitoring and managing the Java platform.static MBeanServergetPlatformMBeanServer()Returns the platformMBeanServer.static <T extends PlatformManagedObject>
TgetPlatformMXBean(Class<T> mxbeanInterface)Returns the platform MXBean implementing the givenmxbeanInterfacewhich is specified to have one single instance in the Java virtual machine.static <T extends PlatformManagedObject>
TgetPlatformMXBean(MBeanServerConnection connection, Class<T> mxbeanInterface)Returns the platform MXBean proxy formxbeanInterfacewhich is specified to have one single instance in a Java virtual machine and the proxy will forward the method calls through the givenMBeanServerConnection.static <T extends PlatformManagedObject>
List<T>getPlatformMXBeans(Class<T> mxbeanInterface)Returns the list of platform MXBeans implementing the givenmxbeanInterfacein the Java virtual machine.static <T extends PlatformManagedObject>
List<T>getPlatformMXBeans(MBeanServerConnection connection, Class<T> mxbeanInterface)Returns the list of the platform MXBean proxies for forwarding the method calls of themxbeanInterfacethrough the givenMBeanServerConnection.static RuntimeMXBeangetRuntimeMXBean()Returns the managed bean for the runtime system of the Java virtual machine.static ThreadMXBeangetThreadMXBean()Returns the managed bean for the thread system of the Java virtual machine.static <T> TnewPlatformMXBeanProxy(MBeanServerConnection connection, String mxbeanName, Class<T> mxbeanInterface)Returns a proxy for a platform MXBean interface of a given MXBean name that forwards its method calls through the givenMBeanServerConnection.
-
Field Details
-
CLASS_LOADING_MXBEAN_NAME
String representation of theObjectNamefor theClassLoadingMXBean.- See Also:
- Constant Field Values
-
COMPILATION_MXBEAN_NAME
String representation of theObjectNamefor theCompilationMXBean.- See Also:
- Constant Field Values
-
MEMORY_MXBEAN_NAME
String representation of theObjectNamefor theMemoryMXBean.- See Also:
- Constant Field Values
-
OPERATING_SYSTEM_MXBEAN_NAME
String representation of theObjectNamefor theOperatingSystemMXBean.- See Also:
- Constant Field Values
-
RUNTIME_MXBEAN_NAME
String representation of theObjectNamefor theRuntimeMXBean.- See Also:
- Constant Field Values
-
THREAD_MXBEAN_NAME
String representation of theObjectNamefor theThreadMXBean.- See Also:
- Constant Field Values
-
GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
The domain name and the type key property in theObjectNamefor aGarbageCollectorMXBean. The uniqueObjectNamefor aGarbageCollectorMXBeancan be formed by appending this string with ",name=collector's name".- See Also:
- Constant Field Values
-
MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
The domain name and the type key property in theObjectNamefor aMemoryManagerMXBean. The uniqueObjectNamefor aMemoryManagerMXBeancan be formed by appending this string with ",name=manager's name".- See Also:
- Constant Field Values
-
MEMORY_POOL_MXBEAN_DOMAIN_TYPE
The domain name and the type key property in theObjectNamefor aMemoryPoolMXBean. The uniqueObjectNamefor aMemoryPoolMXBeancan be formed by appending this string with,name=pool's name.- See Also:
- Constant Field Values
-
-
Method Details
-
getClassLoadingMXBean
Returns the managed bean for the class loading system of the Java virtual machine.- Returns:
- a
ClassLoadingMXBeanobject for the Java virtual machine.
-
getMemoryMXBean
Returns the managed bean for the memory system of the Java virtual machine.- Returns:
- a
MemoryMXBeanobject for the Java virtual machine.
-
getThreadMXBean
Returns the managed bean for the thread system of the Java virtual machine.- Returns:
- a
ThreadMXBeanobject for the Java virtual machine.
-
getRuntimeMXBean
Returns the managed bean for the runtime system of the Java virtual machine.- Returns:
- a
RuntimeMXBeanobject for the Java virtual machine.
-
getCompilationMXBean
Returns the managed bean for the compilation system of the Java virtual machine. This method returnsnullif the Java virtual machine has no compilation system.- Returns:
- a
CompilationMXBeanobject for the Java virtual machine ornullif the Java virtual machine has no compilation system.
-
getOperatingSystemMXBean
Returns the managed bean for the operating system on which the Java virtual machine is running.- Returns:
- an
OperatingSystemMXBeanobject for the Java virtual machine.
-
getMemoryPoolMXBeans
Returns a list ofMemoryPoolMXBeanobjects 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.- Returns:
- a list of
MemoryPoolMXBeanobjects.
-
getMemoryManagerMXBeans
Returns a list ofMemoryManagerMXBeanobjects 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.- Returns:
- a list of
MemoryManagerMXBeanobjects.
-
getGarbageCollectorMXBeans
Returns a list ofGarbageCollectorMXBeanobjects in the Java virtual machine. The Java virtual machine may have one or moreGarbageCollectorMXBeanobjects. It may add or removeGarbageCollectorMXBeanduring execution.- Returns:
- a list of
GarbageCollectorMXBeanobjects.
-
getPlatformMBeanServer
Returns the platformMBeanServer. On the first call to this method, it first creates the platformMBeanServerby calling theMBeanServerFactory.createMBeanServermethod and registers each platform MXBean in this platformMBeanServerwith itsObjectName. This method, in subsequent calls, will simply return the initially created platformMBeanServer.MXBeans that get created and destroyed dynamically, for example, memory
poolsandmanagers, will automatically be registered and deregistered into the platformMBeanServer.If the system property
javax.management.builder.initialis set, the platformMBeanServercreation will be done by the specifiedMBeanServerBuilder.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
MBeanServerand hence allow for easier network publishing and discovery. Name conflicts with the platform MXBeans should be avoided.- Returns:
- the platform
MBeanServer; the platform MXBeans are registered into the platformMBeanServerat the first time this method is called. - Throws:
SecurityException- if there is a security manager and the caller does not have the permission required byMBeanServerFactory.createMBeanServer().- See Also:
MBeanServerFactory,MBeanServerFactory.createMBeanServer()
-
newPlatformMXBeanProxy
public static <T> T newPlatformMXBeanProxy(MBeanServerConnection connection, String mxbeanName, Class<T> mxbeanInterface) throws IOExceptionReturns a proxy for a platform MXBean interface of a given MXBean name that forwards its method calls through the givenMBeanServerConnection.This method is equivalent to:
whereProxy.newProxyInstance(mxbeanInterface.getClassLoader(), new Class[] { mxbeanInterface }, handler)handleris anInvocationHandlerto which method invocations to the MXBean interface are dispatched. Thishandlerconverts an input parameter from an MXBean data type to its mapped open type before forwarding to theMBeanServerand converts a return value from an MXBean method call through theMBeanServerfrom 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 themxbeanInterfaceandNotificationEmitterwill be implemented by this proxy.Notes:
- Using an MXBean proxy is a convenience remote access to
a platform MXBean of a running virtual machine. All method
calls to the MXBean proxy are forwarded to an
MBeanServerConnectionwhereIOExceptionmay be thrown when the communication problem occurs with the connector server. If thrown,IOExceptionwill be wrappped inUndeclaredThrowableException. An application remotely accessing the platform MXBeans using proxy should prepare to catchUndeclaredThrowableExceptionand handle its cause as if that cause had been thrown by theMBeanServerConnectioninterface. - When a client application is designed to remotely access MXBeans
for a running virtual machine whose version is different than
the version on which the application is running,
it should prepare to catch
InvalidObjectExceptionwhich 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. If thrown,InvalidObjectExceptionwill be wrappped inUndeclaredThrowableException. MBeanServerInvocationHandleror itsnewProxyInstancemethod cannot be used to create a proxy for a platform MXBean. The proxy object created byMBeanServerInvocationHandlerdoes not handle the properties of the platform MXBeans described in the class specification.
- Type Parameters:
T- anmxbeanInterfacetype parameter- Parameters:
connection- theMBeanServerConnectionto forward to.mxbeanName- the name of a platform MXBean withinconnectionto forward to.mxbeanNamemust be in the format ofObjectName.mxbeanInterface- the MXBean interface to be implemented by the proxy.- Returns:
- a proxy for a platform MXBean interface of a
given MXBean name
that forwards its method calls through the given
MBeanServerConnection, ornullif not exist. - Throws:
IllegalArgumentException- ifmxbeanNameis not with a validObjectNameformat, or- the named MXBean in the
connectionis not a MXBean provided by the platform, or - the named MXBean is not registered in the
MBeanServerConnection, or - the named MXBean is not an instance of the given
mxbeanInterface
IOException- if a communication problem occurred when accessing theMBeanServerConnection.
- Using an MXBean proxy is a convenience remote access to
a platform MXBean of a running virtual machine. All method
calls to the MXBean proxy are forwarded to an
-
getPlatformMXBean
Returns the platform MXBean implementing the givenmxbeanInterfacewhich is specified to have one single instance in the Java virtual machine. This method may returnnullif the management interface is not implemented in the Java virtual machine (for example, a Java virtual machine with no compilation system does not implementCompilationMXBean); otherwise, this method is equivalent to calling:getPlatformMXBeans(mxbeanInterface).get(0);- Type Parameters:
T- anmxbeanInterfacetype parameter- Parameters:
mxbeanInterface- a management interface for a platform MXBean with one single instance in the Java virtual machine if implemented.- Returns:
- the platform MXBean that implements
mxbeanInterface, ornullif not exist. - Throws:
IllegalArgumentException- ifmxbeanInterfaceis not a platform management interface or not a singleton platform MXBean.- Since:
- 1.7
-
getPlatformMXBeans
public static <T extends PlatformManagedObject> List<T> getPlatformMXBeans(Class<T> mxbeanInterface)Returns the list of platform MXBeans implementing the givenmxbeanInterfacein 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.- Type Parameters:
T- anmxbeanInterfacetype parameter- Parameters:
mxbeanInterface- a management interface for a platform MXBean- Returns:
- the list of platform MXBeans that implement
mxbeanInterface. - Throws:
IllegalArgumentException- ifmxbeanInterfaceis not a platform management interface.- Since:
- 1.7
-
getPlatformMXBean
public static <T extends PlatformManagedObject> T getPlatformMXBean(MBeanServerConnection connection, Class<T> mxbeanInterface) throws IOExceptionReturns the platform MXBean proxy formxbeanInterfacewhich is specified to have one single instance in a Java virtual machine and the proxy will forward the method calls through the givenMBeanServerConnection. This method may returnnullif 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 implementCompilationMXBean); otherwise, this method is equivalent to calling:getPlatformMXBeans(connection, mxbeanInterface).get(0);- Type Parameters:
T- anmxbeanInterfacetype parameter- Parameters:
connection- theMBeanServerConnectionto forward to.mxbeanInterface- a management interface for a platform MXBean with one single instance in the Java virtual machine being monitored, if implemented.- Returns:
- the platform MXBean proxy for
forwarding the method calls of the
mxbeanInterfacethrough the givenMBeanServerConnection, ornullif not exist. - Throws:
IllegalArgumentException- ifmxbeanInterfaceis not a platform management interface or not a singleton platform MXBean.IOException- if a communication problem occurred when accessing theMBeanServerConnection.- Since:
- 1.7
- See Also:
newPlatformMXBeanProxy(javax.management.MBeanServerConnection, java.lang.String, java.lang.Class<T>)
-
getPlatformMXBeans
public static <T extends PlatformManagedObject> List<T> getPlatformMXBeans(MBeanServerConnection connection, Class<T> mxbeanInterface) throws IOExceptionReturns the list of the platform MXBean proxies for forwarding the method calls of themxbeanInterfacethrough the givenMBeanServerConnection. 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.- Type Parameters:
T- anmxbeanInterfacetype parameter- Parameters:
connection- theMBeanServerConnectionto forward to.mxbeanInterface- a management interface for a platform MXBean- Returns:
- the list of platform MXBean proxies for
forwarding the method calls of the
mxbeanInterfacethrough the givenMBeanServerConnection. - Throws:
IllegalArgumentException- ifmxbeanInterfaceis not a platform management interface.IOException- if a communication problem occurred when accessing theMBeanServerConnection.- Since:
- 1.7
- See Also:
newPlatformMXBeanProxy(javax.management.MBeanServerConnection, java.lang.String, java.lang.Class<T>)
-
getPlatformManagementInterfaces
Returns the set ofClassobjects, subinterface ofPlatformManagedObject, representing all management interfaces for monitoring and managing the Java platform.- Returns:
- the set of
Classobjects, subinterface ofPlatformManagedObjectrepresenting the management interfaces for monitoring and managing the Java platform. - Since:
- 1.7
-