- java.lang.Object
-
- javax.management.JMX
-
public class JMX extends Object
Static methods from the JMX API. There are no instances of this class.- Since:
- 1.6
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_VALUE_FIELD
The name of thedefaultValue
field.static String
IMMUTABLE_INFO_FIELD
The name of theimmutableInfo
field.static String
INTERFACE_CLASS_NAME_FIELD
The name of theinterfaceClassName
field.static String
LEGAL_VALUES_FIELD
The name of thelegalValues
field.static String
MAX_VALUE_FIELD
The name of themaxValue
field.static String
MIN_VALUE_FIELD
The name of theminValue
field.static String
MXBEAN_FIELD
The name of themxbean
field.static String
OPEN_TYPE_FIELD
The name of theopenType
field.static String
ORIGINAL_TYPE_FIELD
The name of theoriginalType
field.
-
Method Summary
Modifier and Type Method Description static boolean
isMXBeanInterface(Class<?> interfaceClass)
Test whether an interface is an MXBean interface.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.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 ofNotificationEmitter
.static <T> T
newMXBeanProxy(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass)
Make a proxy for an MXBean in a local or remote MBean Server.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 ofNotificationEmitter
.
-
-
-
Field Detail
-
DEFAULT_VALUE_FIELD
public static final String DEFAULT_VALUE_FIELD
The name of thedefaultValue
field.- See Also:
- Constant Field Values
-
IMMUTABLE_INFO_FIELD
public static final String IMMUTABLE_INFO_FIELD
The name of theimmutableInfo
field.- See Also:
- Constant Field Values
-
INTERFACE_CLASS_NAME_FIELD
public static final String INTERFACE_CLASS_NAME_FIELD
The name of theinterfaceClassName
field.- See Also:
- Constant Field Values
-
LEGAL_VALUES_FIELD
public static final String LEGAL_VALUES_FIELD
The name of thelegalValues
field.- See Also:
- Constant Field Values
-
MAX_VALUE_FIELD
public static final String MAX_VALUE_FIELD
The name of themaxValue
field.- See Also:
- Constant Field Values
-
MIN_VALUE_FIELD
public static final String MIN_VALUE_FIELD
The name of theminValue
field.- See Also:
- Constant Field Values
-
MXBEAN_FIELD
public static final String MXBEAN_FIELD
The name of themxbean
field.- See Also:
- Constant Field Values
-
OPEN_TYPE_FIELD
public static final String OPEN_TYPE_FIELD
The name of theopenType
field.- See Also:
- Constant Field Values
-
ORIGINAL_TYPE_FIELD
public static final String ORIGINAL_TYPE_FIELD
The name of theoriginalType
field.- See Also:
- Constant Field Values
-
-
Method Detail
-
newMBeanProxy
public 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
mbs
containing an MBean withObjectName
name
, 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 a
Proxy
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
- ifinterfaceClass
is not a compliant MBean interface
-
newMBeanProxy
public 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, ifnotificationEmitter
istrue
, then the MBean is assumed to be aNotificationBroadcaster
orNotificationEmitter
and the returned proxy will implementNotificationEmitter
as 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 ofNotificationBroadcaster
andNotificationEmitter
.- 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 implementNotificationEmitter
by forwarding its methods viaconnection
.- Returns:
- the new proxy instance.
- Throws:
IllegalArgumentException
- ifinterfaceClass
is not a compliant MBean interface
-
newMXBeanProxy
public 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
mbs
containing an MXBean withObjectName
name
, 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"))
.Because
String
is a simple type, in the sense ofSimpleType
, 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 beCompositeData
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 a
Proxy
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
- ifinterfaceClass
is not acompliant MXBean interface
-
newMXBeanProxy
public 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, ifnotificationEmitter
istrue
, then the MXBean is assumed to be aNotificationBroadcaster
orNotificationEmitter
and the returned proxy will implementNotificationEmitter
as 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 ofNotificationBroadcaster
andNotificationEmitter
.- 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 implementNotificationEmitter
by forwarding its methods viaconnection
.- Returns:
- the new proxy instance.
- Throws:
IllegalArgumentException
- ifinterfaceClass
is not acompliant MXBean interface
-
isMXBeanInterface
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 if
interfaceClass
is acompliant MXBean interface
- Throws:
NullPointerException
- ifinterfaceClass
is null.
-
-