public class JMX extends Object
- Since:
- 1.6
- 
Field SummaryFields Modifier and Type Field Description static StringDEFAULT_VALUE_FIELDThe name of thedefaultValuefield.static StringIMMUTABLE_INFO_FIELDThe name of theimmutableInfofield.static StringINTERFACE_CLASS_NAME_FIELDThe name of theinterfaceClassNamefield.static StringLEGAL_VALUES_FIELDThe name of thelegalValuesfield.static StringMAX_VALUE_FIELDThe name of themaxValuefield.static StringMIN_VALUE_FIELDThe name of theminValuefield.static StringMXBEAN_FIELDThe name of themxbeanfield.static StringOPEN_TYPE_FIELDThe name of theopenTypefield.static StringORIGINAL_TYPE_FIELDThe name of theoriginalTypefield.
- 
Method SummaryModifier and Type Method Description static booleanisMXBeanInterface(Class<?> interfaceClass)Test whether an interface is an MXBean interface.static <T> TnewMBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass)Make a proxy for a Standard MBean in a local or remote MBean Server.static <T> TnewMBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass, boolean notificationEmitter)Make a proxy for a Standard MBean in a local or remote MBean Server that may also support the methods ofNotificationEmitter.static <T> TnewMXBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass)Make a proxy for an MXBean in a local or remote MBean Server.static <T> TnewMXBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass, boolean notificationEmitter)Make a proxy for an MXBean in a local or remote MBean Server that may also support the methods ofNotificationEmitter.
- 
Field Details- 
DEFAULT_VALUE_FIELDThe name of thedefaultValuefield.- See Also:
- Constant Field Values
 
- 
IMMUTABLE_INFO_FIELDThe name of theimmutableInfofield.- See Also:
- Constant Field Values
 
- 
INTERFACE_CLASS_NAME_FIELDThe name of theinterfaceClassNamefield.- See Also:
- Constant Field Values
 
- 
LEGAL_VALUES_FIELDThe name of thelegalValuesfield.- See Also:
- Constant Field Values
 
- 
MAX_VALUE_FIELDThe name of themaxValuefield.- See Also:
- Constant Field Values
 
- 
MIN_VALUE_FIELDThe name of theminValuefield.- See Also:
- Constant Field Values
 
- 
MXBEAN_FIELDThe name of themxbeanfield.- See Also:
- Constant Field Values
 
- 
OPEN_TYPE_FIELDThe name of theopenTypefield.- See Also:
- Constant Field Values
 
- 
ORIGINAL_TYPE_FIELDThe name of theoriginalTypefield.- See Also:
- Constant Field Values
 
 
- 
- 
Method Details- 
newMBeanProxypublic static <T> T newMBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass)Make a proxy for a Standard MBean in a local or remote MBean Server. If you have an MBean Server mbscontaining an MBean withObjectNamename, 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, MyMBeanlooks 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 to- mbs.- getAttribute- (name, "SomeAttribute").
- proxy.setSomeAttribute("whatever")which will result in a call to- mbs.- setAttribute- (name, new Attribute("SomeAttribute", "whatever")).
- proxy.someOperation("param1", 2)which will be translated into a call to- mbs.- invoke- (name, "someOperation", <etc>).
 The object returned by this method is a ProxywhoseInvocationHandleris anMBeanServerInvocationHandler.This method is equivalent to newMBeanProxy(connection, objectName, interfaceClass, false).- Type Parameters:
- T- allows the compiler to know that if the- interfaceClassparameter is- MyMBean.class, for example, then the return type is- MyMBean.
- Parameters:
- connection- the MBean server to forward to.
- objectName- the name of the MBean within- connectionto 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- if- interfaceClassis not a compliant MBean interface
 
- 
newMBeanProxypublic static <T> T newMBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> 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, ifnotificationEmitteristrue, then the MBean is assumed to be aNotificationBroadcasterorNotificationEmitterand the returned proxy will implementNotificationEmitteras well asinterfaceClass. A call toNotificationBroadcaster.addNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object)on the proxy will result in a call toMBeanServerConnection.addNotificationListener(ObjectName, NotificationListener, NotificationFilter, Object), and likewise for the other methods ofNotificationBroadcasterandNotificationEmitter.- Type Parameters:
- T- allows the compiler to know that if the- interfaceClassparameter is- MyMBean.class, for example, then the return type is- MyMBean.
- Parameters:
- connection- the MBean server to forward to.
- objectName- the name of the MBean within- connectionto 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- NotificationEmitterby forwarding its methods via- connection.
- Returns:
- the new proxy instance.
- Throws:
- IllegalArgumentException- if- interfaceClassis not a compliant MBean interface
 
- 
newMXBeanProxypublic static <T> T newMXBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass)Make a proxy for an MXBean in a local or remote MBean Server.If you have an MBean Server mbscontaining an MXBean withObjectNamename, 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, MyMXBeanlooks like this:public interface MyMXBean { public String getSimpleAttribute(); public void setSimpleAttribute(String value); publicMemoryUsagegetMappedAttribute(); public void setMappedAttribute(MemoryUsage memoryUsage); public MemoryUsage someOperation(String param1, MemoryUsage param2); }Then: - proxy.getSimpleAttribute()will result in a call to- mbs.- getAttribute- (name, "SimpleAttribute").
- proxy.setSimpleAttribute("whatever")will result in a call to- mbs.- setAttribute- (name, new Attribute("SimpleAttribute", "whatever")).- Because - Stringis 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 (see- newMBeanProxy) for the attribute- SimpleAttribute.
- proxy.getMappedAttribute()will result in a call to- mbs.getAttribute("MappedAttribute"). The MXBean mapping rules mean that the actual type of the attribute- MappedAttributewill be- CompositeDataand that is what the- mbs.getAttributecall will return. The proxy will then convert the- CompositeDataback into the expected type- MemoryUsageusing the MXBean mapping rules.
- Similarly, - proxy.setMappedAttribute(memoryUsage)will convert the- MemoryUsageargument into a- CompositeDatabefore calling- mbs.setAttribute.
- proxy.someOperation("whatever", memoryUsage)will convert the- MemoryUsageargument into a- CompositeDataand call- mbs.invoke. The value returned by- mbs.invokewill be also be a- CompositeData, and the proxy will convert this into the expected type- MemoryUsageusing the MXBean mapping rules.
 The object returned by this method is a ProxywhoseInvocationHandleris anMBeanServerInvocationHandler.This method is equivalent to newMXBeanProxy(connection, objectName, interfaceClass, false).- Type Parameters:
- T- allows the compiler to know that if the- interfaceClassparameter is- MyMXBean.class, for example, then the return type is- MyMXBean.
- Parameters:
- connection- the MBean server to forward to.
- objectName- the name of the MBean within- connectionto forward to.
- interfaceClass- the MXBean interface, which will also be implemented by the returned proxy.
- Returns:
- the new proxy instance.
- Throws:
- IllegalArgumentException- if- interfaceClassis not a- compliant MXBean interface
 
- 
newMXBeanProxypublic static <T> T newMXBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> 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, ifnotificationEmitteristrue, then the MXBean is assumed to be aNotificationBroadcasterorNotificationEmitterand the returned proxy will implementNotificationEmitteras well asinterfaceClass. A call toNotificationBroadcaster.addNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object)on the proxy will result in a call toMBeanServerConnection.addNotificationListener(ObjectName, NotificationListener, NotificationFilter, Object), and likewise for the other methods ofNotificationBroadcasterandNotificationEmitter.- Type Parameters:
- T- allows the compiler to know that if the- interfaceClassparameter is- MyMXBean.class, for example, then the return type is- MyMXBean.
- Parameters:
- connection- the MBean server to forward to.
- objectName- the name of the MBean within- connectionto forward to.
- interfaceClass- the MXBean interface, which will also be implemented by the returned proxy.
- notificationEmitter- make the returned proxy implement- NotificationEmitterby forwarding its methods via- connection.
- Returns:
- the new proxy instance.
- Throws:
- IllegalArgumentException- if- interfaceClassis not a- compliant MXBean interface
 
- 
isMXBeanInterfaceTest whether an interface is an MXBean interface. An interface is an MXBean interface if it is public, annotated @MXBeanor@MXBean(true)or if it does not have an@MXBeanannotation and its name ends with "MXBean".- Parameters:
- interfaceClass- The candidate interface.
- Returns:
- true if interfaceClassis acompliant MXBean interface
- Throws:
- NullPointerException- if- interfaceClassis null.
 
 
-