JMX (Java SE 15 & JDK 15) (original) (raw)
public class JMX extends Object
Static methods from the JMX API. There are no instances of this class.
Since:
1.6
Field Summary
Method Summary
Modifier and Type | Method | Description |
---|---|---|
static boolean | isMXBeanInterface(Class<?> interfaceClass) | Test whether an interface is an MXBean interface. |
static T | newMBeanProxy(MBeanServerConnection connection,ObjectName objectName,Class interfaceClass) | Make a proxy for a Standard MBean in a local or remote MBean Server. |
static T | newMBeanProxy(MBeanServerConnection connection,ObjectName objectName,Class interfaceClass, boolean notificationEmitter) | Make a proxy for a Standard MBean in a local or remote MBean Server that may also support the methods of NotificationEmitter. |
static T | newMXBeanProxy(MBeanServerConnection connection,ObjectName objectName,Class interfaceClass) | Make a proxy for an MXBean in a local or remote MBean Server. |
static T | newMXBeanProxy(MBeanServerConnection connection,ObjectName objectName,Class interfaceClass, boolean notificationEmitter) | Make a proxy for an MXBean in a local or remote MBean Server that may also support the methods of NotificationEmitter. |
Methods declared in class java.lang.Object
[clone](../../../java.base/java/lang/Object.html#clone%28%29), [equals](../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../../java.base/java/lang/Object.html#finalize%28%29), [getClass](../../../java.base/java/lang/Object.html#getClass%28%29), [hashCode](../../../java.base/java/lang/Object.html#hashCode%28%29), [notify](../../../java.base/java/lang/Object.html#notify%28%29), [notifyAll](../../../java.base/java/lang/Object.html#notifyAll%28%29), [toString](../../../java.base/java/lang/Object.html#toString%28%29), [wait](../../../java.base/java/lang/Object.html#wait%28%29), [wait](../../../java.base/java/lang/Object.html#wait%28long%29), [wait](../../../java.base/java/lang/Object.html#wait%28long,int%29)
Field Details
DEFAULT_VALUE_FIELD
public static final String DEFAULT_VALUE_FIELD
See Also:
Constant Field ValuesIMMUTABLE_INFO_FIELD
public static final String IMMUTABLE_INFO_FIELD
See Also:
Constant Field ValuesINTERFACE_CLASS_NAME_FIELD
public static final String INTERFACE_CLASS_NAME_FIELD
See Also:
Constant Field ValuesLEGAL_VALUES_FIELD
public static final String LEGAL_VALUES_FIELD
See Also:
Constant Field ValuesMAX_VALUE_FIELD
public static final String MAX_VALUE_FIELD
See Also:
Constant Field ValuesMIN_VALUE_FIELD
public static final String MIN_VALUE_FIELD
See Also:
Constant Field ValuesMXBEAN_FIELD
public static final String MXBEAN_FIELD
The name of the mxbean field.
See Also:
Constant Field ValuesOPEN_TYPE_FIELD
public static final String OPEN_TYPE_FIELD
See Also:
Constant Field ValuesORIGINAL_TYPE_FIELD
public static final String ORIGINAL_TYPE_FIELD
See Also:
Constant Field ValuesMethod Details
newMBeanProxy
Make a proxy for a Standard MBean in a local or remote MBean Server.
If you have an MBean Servermbs
containing an MBean with ObjectNamename
, and if the MBean's management interface is described by the Java interfaceMyMBean
, you can construct a proxy for the MBean like this:
MyMBean proxy = JMX.newMBeanProxy(mbs, name, MyMBean.class);Suppose, for example,
MyMBean
looks like this:
public interface MyMBean {
public String getSomeAttribute();
public void setSomeAttribute(String value);
public void someOperation(String param1, int param2);
}Then you can execute:
*proxy.getSomeAttribute()
which will result in a call tombs.
getAttribute(name, "SomeAttribute")
.
*proxy.setSomeAttribute("whatever")
which will result in a call tombs.
setAttribute(name, new Attribute("SomeAttribute", "whatever"))
.
*proxy.someOperation("param1", 2)
which will be translated into a call tombs.
invoke(name, "someOperation", <etc>)
.
The object returned by this method is aProxy whoseInvocationHandler
is anMBeanServerInvocationHandler.
This method is equivalent to newMBeanProxy(connection, objectName, interfaceClass, false).
Type Parameters:
T
- allows the compiler to know that if theinterfaceClass
parameter isMyMBean.class
, for example, then the return type isMyMBean
.
Parameters:
connection
- the MBean server to forward to.
objectName
- the name of the MBean withinconnection
to forward to.
interfaceClass
- the management interface that the MBean exports, which will also be implemented by the returned proxy.
Returns:
the new proxy instance.
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifinterfaceClass
is not a compliant MBean interfacenewMBeanProxy
public static T newMBeanProxy(MBeanServerConnection connection,ObjectName objectName,Class interfaceClass, boolean notificationEmitter)
Make a proxy for a Standard MBean in a local or remote MBean Server that may also support the methods of NotificationEmitter.
This method behaves the same as newMBeanProxy(MBeanServerConnection, ObjectName, Class), but additionally, ifnotificationEmitter
istrue
, then the MBean is assumed to be a NotificationBroadcaster or NotificationEmitter and the returned proxy will implement NotificationEmitter as well asinterfaceClass
. A call to NotificationBroadcaster.addNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object) on the proxy will result in a call to MBeanServerConnection.addNotificationListener(ObjectName, NotificationListener, NotificationFilter, Object), and likewise for the other methods of NotificationBroadcaster and NotificationEmitter.
Type Parameters:
T
- allows the compiler to know that if theinterfaceClass
parameter isMyMBean.class
, for example, then the return type isMyMBean
.
Parameters:
connection
- the MBean server to forward to.
objectName
- the name of the MBean withinconnection
to forward to.
interfaceClass
- the management interface that the MBean exports, which will also be implemented by the returned proxy.
notificationEmitter
- make the returned proxy implement NotificationEmitter by forwarding its methods viaconnection
.
Returns:
the new proxy instance.
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifinterfaceClass
is not a compliant MBean interfacenewMXBeanProxy
Make a proxy for an MXBean in a local or remote MBean Server.
If you have an MBean Servermbs
containing an MXBean with ObjectNamename
, and if the MXBean's management interface is described by the Java interfaceMyMXBean
, you can construct a proxy for the MXBean like this:
MyMXBean proxy = JMX.newMXBeanProxy(mbs, name, MyMXBean.class);Suppose, for example,
MyMXBean
looks like this:
public interface MyMXBean {
public String getSimpleAttribute();
public void setSimpleAttribute(String value);
public MemoryUsage getMappedAttribute();
public void setMappedAttribute(MemoryUsage memoryUsage);
public MemoryUsage someOperation(String param1, MemoryUsage param2);
}Then:
*proxy.getSimpleAttribute()
will result in a call tombs.
getAttribute(name, "SimpleAttribute")
.
*proxy.setSimpleAttribute("whatever")
will result in a call tombs.
setAttribute(name, new Attribute("SimpleAttribute", "whatever"))
.
BecauseString
is a simple type, in the sense of SimpleType, it is not changed in the context of an MXBean. The MXBean proxy behaves the same as a Standard MBean proxy (seenewMBeanProxy) for the attributeSimpleAttribute
.
*proxy.getMappedAttribute()
will result in a call tombs.getAttribute("MappedAttribute")
. The MXBean mapping rules mean that the actual type of the attributeMappedAttribute
will be CompositeData and that is what thembs.getAttribute
call will return. The proxy will then convert theCompositeData
back into the expected typeMemoryUsage
using the MXBean mapping rules.
* Similarly,proxy.setMappedAttribute(memoryUsage)
will convert theMemoryUsage
argument into aCompositeData
before callingmbs.setAttribute
.
*proxy.someOperation("whatever", memoryUsage)
will convert theMemoryUsage
argument into aCompositeData
and callmbs.invoke
. The value returned bymbs.invoke
will be also be aCompositeData
, and the proxy will convert this into the expected typeMemoryUsage
using the MXBean mapping rules.
The object returned by this method is aProxy whoseInvocationHandler
is anMBeanServerInvocationHandler.
This method is equivalent to newMXBeanProxy(connection, objectName, interfaceClass, false).
Type Parameters:
T
- allows the compiler to know that if theinterfaceClass
parameter isMyMXBean.class
, for example, then the return type isMyMXBean
.
Parameters:
connection
- the MBean server to forward to.
objectName
- the name of the MBean withinconnection
to forward to.
interfaceClass
- the MXBean interface, which will also be implemented by the returned proxy.
Returns:
the new proxy instance.
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifinterfaceClass
is not a compliant MXBean interfacenewMXBeanProxy
public static T newMXBeanProxy(MBeanServerConnection connection,ObjectName objectName,Class interfaceClass, boolean notificationEmitter)
Make a proxy for an MXBean in a local or remote MBean Server that may also support the methods of NotificationEmitter.
This method behaves the same as newMXBeanProxy(MBeanServerConnection, ObjectName, Class), but additionally, ifnotificationEmitter
istrue
, then the MXBean is assumed to be a NotificationBroadcaster or NotificationEmitter and the returned proxy will implement NotificationEmitter as well asinterfaceClass
. A call to NotificationBroadcaster.addNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object) on the proxy will result in a call to MBeanServerConnection.addNotificationListener(ObjectName, NotificationListener, NotificationFilter, Object), and likewise for the other methods of NotificationBroadcaster and NotificationEmitter.
Type Parameters:
T
- allows the compiler to know that if theinterfaceClass
parameter isMyMXBean.class
, for example, then the return type isMyMXBean
.
Parameters:
connection
- the MBean server to forward to.
objectName
- the name of the MBean withinconnection
to forward to.
interfaceClass
- the MXBean interface, which will also be implemented by the returned proxy.
notificationEmitter
- make the returned proxy implement NotificationEmitter by forwarding its methods viaconnection
.
Returns:
the new proxy instance.
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifinterfaceClass
is not a compliant MXBean interfaceisMXBeanInterface
public static boolean isMXBeanInterface(Class<?> interfaceClass)
Test whether an interface is an MXBean interface. An interface is an MXBean interface if it is public, annotated @MXBean or@MXBean(true)
or if it does not have an@MXBean
annotation and its name ends with "MXBean
".
Parameters:
interfaceClass
- The candidate interface.
Returns:
true ifinterfaceClass
is acompliant MXBean interface
Throws:
[NullPointerException](../../../java.base/java/lang/NullPointerException.html "class in java.lang")
- ifinterfaceClass
is null.