javax.management

Class JMX


public class JMX
extends Object

Common static methods pertaining to the management API. There are no instances of this class.
Since:
1.6

Field Summary

static String
DEFAULT_VALUE_FIELD
The name of the defaultValue field.
static String
IMMUTABLE_INFO_FIELD
The name of the immutableInfo field.
static String
INTERFACE_CLASS_NAME_FIELD
The name of the interfaceClassName field.
static String
LEGAL_VALUES_FIELD
The name of the legalValues field.
static String
MAX_VALUE_FIELD
The name of the maxValue field.
static String
MIN_VALUE_FIELD
The name of the minValue field.
static String
MXBEAN_FIELD
The name of the mxbean field.
static String
OPEN_TYPE_FIELD
The name of the openType field.
static String
ORIGINAL_TYPE_FIELD
The name of the originalType field.

Method Summary

static
T newMBeanProxy(MBeanServerConnection conn, ObjectName name, Class iface)
Returns a proxy for a standard management bean, using the specified connection to access the named implementation.
static
T newMBeanProxy(MBeanServerConnection conn, ObjectName name, Class iface, boolean bcast)
Returns a proxy for a standard management bean, using the specified connection to access the named implementation, as with newMBeanProxy(MBeanServerConnection, ObjectName, Class).
static
T newMXBeanProxy(MBeanServerConnection conn, ObjectName name, Class iface)
Returns a proxy for a MXBean, using the specified connection to access the named implementation.
static boolean
isMXBeanInterface(Class iface)
Returns true if the given class represents an MXBean interface.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

DEFAULT_VALUE_FIELD

public static final String DEFAULT_VALUE_FIELD
The name of the defaultValue field.
Field Value:
"defaultValue"

IMMUTABLE_INFO_FIELD

public static final String IMMUTABLE_INFO_FIELD
The name of the immutableInfo field.
Field Value:
"immutableInfo"

INTERFACE_CLASS_NAME_FIELD

public static final String INTERFACE_CLASS_NAME_FIELD
The name of the interfaceClassName field.
Field Value:
"interfaceClassName"

LEGAL_VALUES_FIELD

public static final String LEGAL_VALUES_FIELD
The name of the legalValues field.
Field Value:
"legalValues"

MAX_VALUE_FIELD

public static final String MAX_VALUE_FIELD
The name of the maxValue field.
Field Value:
"maxValue"

MIN_VALUE_FIELD

public static final String MIN_VALUE_FIELD
The name of the minValue field.
Field Value:
"minValue"

MXBEAN_FIELD

public static final String MXBEAN_FIELD
The name of the mxbean field.
Field Value:
"mxbean"

OPEN_TYPE_FIELD

public static final String OPEN_TYPE_FIELD
The name of the openType field.
Field Value:
"openType"

ORIGINAL_TYPE_FIELD

public static final String ORIGINAL_TYPE_FIELD
The name of the originalType field.
Field Value:
"originalType"

Method Details

T newMBeanProxy

public static  T newMBeanProxy(MBeanServerConnection conn,
                                  ObjectName name,
                                  Class iface)
Returns a proxy for a standard management bean, using the specified connection to access the named implementation. To create a proxy for the bean, SomethingMBean, a call to JMX.newMBeanProxy(server, name, SomethingMBean.class) is made, where server is a local or remote management server, and name is the registered ObjectName of the implementation of SomethingMBean to use.

The proxy redirects calls to the methods of the interface, SomethingMBean, to the appropriate methods of the management server. If SomethingMBean is specified as follows:

 public interface SomethingMBean
 {
   String getName();
   void setName(String name);
   void doStuff();
 }
 

The proxy created above will provide these three methods using an instance of MBeanServerInvocationHandler. The two methods, getName and setName define an attribute, Name, so a call to getName() will return the value of server.getAttribute(name, "Name"), while setName(newName) will result in a call to server.setAttribute(name, new Attribute("Name", newName)). Finally, doStuff(), as an operation, will cause the proxy to call MBeanServer.invoke(ObjectName,String,Object[],String[]) as server.invoke(name, "doStuff", null, null).

Calling this method is equivalent to calling newMBeanProxy(MBeanServerConnection, ObjectName, Class, boolean).

Parameters:
conn - the server connection over which to forward calls to the bean.
name - the registered name of the bean to use to implement the given interface.
iface - the interface to provide a proxy for.
Returns:
a proxy implementing the specified interface using calls to the methods of the bean registered with the supplied server using the given name.
See Also:
newMBeanProxy(MBeanServerConnection, ObjectName, Class, boolean)

T newMBeanProxy

public static  T newMBeanProxy(MBeanServerConnection conn,
                                  ObjectName name,
                                  Class iface,
                                  boolean bcast)
Returns a proxy for a standard management bean, using the specified connection to access the named implementation, as with newMBeanProxy(MBeanServerConnection, ObjectName, Class). In addition, the proxy returned by this method will also implement NotificationEmitter if bcast is true, under the assumption that the implementation referenced by name implements this interface. Calls to the methods of NotificationEmitter will be forwarded to the bean implementation via the appropriate server methods.
Parameters:
conn - the server connection over which to forward calls to the bean.
name - the registered name of the bean to use to implement the given interface.
iface - the interface to provide a proxy for.
bcast - true if the proxy should implement NotificationEmitter.
Returns:
a proxy implementing the specified interface using calls to the methods of the bean registered with the supplied server using the given name.
See Also:
newMBeanProxy(MBeanServerConnection, ObjectName, Class)

T newMXBeanProxy

public static  T newMXBeanProxy(MBeanServerConnection conn,
                                   ObjectName name,
                                   Class iface)
Returns a proxy for a MXBean, using the specified connection to access the named implementation. To create a proxy for the bean, SomethingMXBean, a call to JMX.newMXBeanProxy(server, name, SomethingMXBean.class) is made, where server is a local or remote management server, and name is the registered ObjectName of the implementation of SomethingMBean to use.

The proxy redirects calls to the methods of the interface, SomethingMXBean, to the appropriate methods of the management server with appropriate conversion between Java and open types, according to the MXBean rules. If SomethingMXBean is specified as follows:

 public interface SomethingMXBean
 {
   String getName();
   void setName(String name);
   List getStatistics();
   void setStatistics(List statistics);
   List getNamedStatistics(String, Map);
 }
 

The proxy created above will provide these five methods using an instance of MBeanServerInvocationHandler. The two methods, getName and setName define an attribute, Name, so a call to getName() will return the value of server.getAttribute(name, "Name"), while setName(newName) will result in a call to server.setAttribute(name, new Attribute("Name", newName)). As this uses a simple type, String, no conversion is necessary.

The two methods, getStatistics and setStatistics similarly define another attribute, Statistics. Calling getStatistics() will cause a call to the server to be made as before, server.getAttribute(name, "Statistics"). However, the type of the return value from this call will be an array of Double objects, as per the MXBean rules. The proxy converts this back in to a List of Double objects before returning it.

The same process is applied in reverse for setStatistics(newStats). The list is converted into an appropriate array before the call to MBeanServerConnection.setAttribute(ObjectName,Attribute) is made. Finally, a call to getNamedStatistics will require both a Java to open type conversion on the arguments, and then an open type to Java conversion of the return value. Thus, a proxy enables an MXBean to be used in cases where the appropriate Java types are available and the user wishes to access the bean using the types directly defined in its interface, just as with standard management beans.

Calling this method is equivalent to calling newMXBeanProxy(MBeanServerConnection, ObjectName, Class, boolean).

Parameters:
conn - the server connection over which to forward calls to the bean.
name - the registered name of the bean to use to implement the given interface.
iface - the interface to provide a proxy for.
Returns:
a proxy implementing the specified interface using calls to the methods of the bean registered with the supplied server using the given name.
See Also:
newMXBeanProxy(MBeanServerConnection, ObjectName, Class, boolean)

isMXBeanInterface

public static boolean isMXBeanInterface(Class iface)
Returns true if the given class represents an MXBean interface. An interface is an interface if:
  • It is annotated with @MXBean or @MXBean(true)
  • Its name ends in "MXBean" and it does not have an MXBean annotation.
Parameters:
iface - the interface class that is to be checked for MXBean status.
Returns:
true if the interface represents an MXBean.
Throws:
NullPointerException - if iface is null.

JMX.java -- Static methods pertaining to the management API. Copyright (C) 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.