Top Description Fields Constructors Methods
org.springframework.jmx.support

public abstract Class JmxUtils

extends Object
Class Inheritance
Imports
java.beans.PropertyDescriptor, java.lang.management.ManagementFactory, java.lang.reflect.Method, java.util.Hashtable, .List, javax.management.DynamicMBean, .JMX, .MBeanParameterInfo, .MBeanServer, .MBeanServerFactory, .MalformedObjectNameException, .ObjectName, org.apache.commons.logging.Log, .LogFactory, org.springframework.jmx.MBeanServerNotFoundException, org.springframework.lang.Nullable, org.springframework.util.ClassUtils, .CollectionUtils, .ObjectUtils, .StringUtils

Collection of generic utility methods to support Spring JMX. Includes a convenient method to locate an MBeanServer.
Authors
Rob Harrop, Juergen Hoeller
Since
1.2
See Also
locateMBeanServer

Field Summary

Modifier and TypeField and Description
public static final String
IDENTITY_OBJECT_NAME_KEY

The key used when extending an existing ObjectName with the identity hash code of its corresponding managed resource.

private static final Log
private static final String
MBEAN_SUFFIX

Suffix used to identify an MBean interface.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static ObjectName

Returns:

an ObjectName with the MBean identity added
appendIdentityToObjectName
(ObjectName
the original JMX ObjectName
objectName
,
Object
the MBean instance
managedResource
)

Append an additional key/value pair to an existing ObjectName with the key being the static value identity and the value being the identity hash code of the managed resource being exposed on the supplied ObjectName.

public static String

Returns:

the JMX attribute name to use
getAttributeName
(PropertyDescriptor
the JavaBeans property descriptor
property
,
boolean
whether to use strict casing
useStrictCasing
)

Return the JMX attribute name to use for the given JavaBeans property.

public static Class<?>

Returns:

the bean class to expose
getClassToExpose
(Object
the bean instance (might be an AOP proxy)
managedBean
)

Return the class or interface to expose for the given bean.

public static Class<?>

Returns:

the bean class to expose
getClassToExpose
(Class<?>
the bean class (might be an AOP proxy class)
clazz
)

Return the class or interface to expose for the given bean class.

public static Class<?>

Returns:

the Standard MBean interface for the given class
getMBeanInterface
(Class<?>
the class to check
clazz
)

Return the Standard MBean interface for the given class, if any (that is, an interface whose name matches the class name of the given class but with suffix "MBean").

public static String[]

Returns:

the signature as array of argument types
getMethodSignature
(Method
the method to build an argument signature for
method
)

Create a String[] representing the argument signature of a method.

public static Class<?>

Returns:

whether there is an MXBean interface for the given class
getMXBeanInterface
(Class<?>
the class to check
clazz
)

Return the Java MXBean interface for the given class, if any (that is, an interface whose name ends with "MXBean" and/or carries an appropriate MXBean annotation).

public static boolean

Returns:

whether the class qualifies as an MBean
isMBean
(Class<?>
the bean class to analyze
clazz
)

Determine whether the given bean class qualifies as an MBean as-is.

public static MBeanServer

Returns:

the MBeanServer if found
locateMBeanServer
()

Attempt to find a locally running MBeanServer.

public static MBeanServer

Returns:

the MBeanServer if found
locateMBeanServer
(String
the agent identifier of the MBeanServer to retrieve. If this parameter is null, all registered MBeanServers are considered. If the empty String is given, the platform MBeanServer will be returned.
agentId
)

Attempt to find a locally running MBeanServer.

public static Class<?>[]

Returns:

the parameter types as classes
parameterInfoToTypes
(MBeanParameterInfo[]
the JMX parameter info
paramInfo
)

Convert an array of MBeanParameterInfo into an array of Class instances corresponding to the parameters.

public static Class<?>[]

Returns:

the parameter types as classes
parameterInfoToTypes
(MBeanParameterInfo[]
the JMX parameter info
paramInfo
,
ClassLoader
the ClassLoader to use for loading parameter types
classLoader
)

Convert an array of MBeanParameterInfo into an array of Class instances corresponding to the parameters.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

IDENTITY_OBJECT_NAME_KEYback to summary
public static final String IDENTITY_OBJECT_NAME_KEY

The key used when extending an existing ObjectName with the identity hash code of its corresponding managed resource.

loggerback to summary
private static final Log logger
MBEAN_SUFFIXback to summary
private static final String MBEAN_SUFFIX

Suffix used to identify an MBean interface.

Constructor Detail

JmxUtilsback to summary
public JmxUtils()

Method Detail

appendIdentityToObjectNameback to summary
public static ObjectName appendIdentityToObjectName(ObjectName objectName, Object managedResource) throws MalformedObjectNameException

Append an additional key/value pair to an existing ObjectName with the key being the static value identity and the value being the identity hash code of the managed resource being exposed on the supplied ObjectName. This can be used to provide a unique ObjectName for each distinct instance of a particular bean or class. Useful when generating ObjectNames at runtime for a set of managed resources based on the template value supplied by a org.springframework.jmx.export.naming.ObjectNamingStrategy.

Parameters
objectName:ObjectName

the original JMX ObjectName

managedResource:Object

the MBean instance

Returns:ObjectName

an ObjectName with the MBean identity added

Exceptions
MalformedObjectNameException:
in case of an invalid object name specification
See Also
org.springframework.util.ObjectUtils#getIdentityHexString(Object)
getAttributeNameback to summary
public static String getAttributeName(PropertyDescriptor property, boolean useStrictCasing)

Return the JMX attribute name to use for the given JavaBeans property.

When using strict casing, a JavaBean property with a getter method such as getFoo() translates to an attribute called Foo. With strict casing disabled, getFoo() would translate to just foo.

Parameters
property:PropertyDescriptor

the JavaBeans property descriptor

useStrictCasing:boolean

whether to use strict casing

Returns:String

the JMX attribute name to use

getClassToExposeback to summary
public static Class<?> getClassToExpose(Object managedBean)

Return the class or interface to expose for the given bean. This is the class that will be searched for attributes and operations (for example, checked for annotations).

This implementation returns the superclass for a CGLIB proxy and the class of the given bean else (for a JDK proxy or a plain bean class).

Parameters
managedBean:Object

the bean instance (might be an AOP proxy)

Returns:Class<?>

the bean class to expose

See Also
org.springframework.util.ClassUtils#getUserClass(Object)
getClassToExposeback to summary
public static Class<?> getClassToExpose(Class<?> clazz)

Return the class or interface to expose for the given bean class. This is the class that will be searched for attributes and operations (for example, checked for annotations).

This implementation returns the superclass for a CGLIB proxy and the class of the given bean else (for a JDK proxy or a plain bean class).

Parameters
clazz:Class<?>

the bean class (might be an AOP proxy class)

Returns:Class<?>

the bean class to expose

See Also
org.springframework.util.ClassUtils#getUserClass(Class)
getMBeanInterfaceback to summary
public static Class<?> getMBeanInterface(Class<?> clazz)

Return the Standard MBean interface for the given class, if any (that is, an interface whose name matches the class name of the given class but with suffix "MBean").

Parameters
clazz:Class<?>

the class to check

Returns:Class<?>

the Standard MBean interface for the given class

Annotations
@Nullable
getMethodSignatureback to summary
public static String[] getMethodSignature(Method method)

Create a String[] representing the argument signature of a method. Each element in the array is the fully qualified class name of the corresponding argument in the method's signature.

Parameters
method:Method

the method to build an argument signature for

Returns:String[]

the signature as array of argument types

getMXBeanInterfaceback to summary
public static Class<?> getMXBeanInterface(Class<?> clazz)

Return the Java MXBean interface for the given class, if any (that is, an interface whose name ends with "MXBean" and/or carries an appropriate MXBean annotation).

Parameters
clazz:Class<?>

the class to check

Returns:Class<?>

whether there is an MXBean interface for the given class

Annotations
@Nullable
isMBeanback to summary
public static boolean isMBean(Class<?> clazz)

Determine whether the given bean class qualifies as an MBean as-is.

This implementation checks for javax.management.DynamicMBean classes as well as classes with corresponding "*MBean" interface (Standard MBeans) or corresponding "*MXBean" interface (Java MXBeans).

Parameters
clazz:Class<?>

the bean class to analyze

Returns:boolean

whether the class qualifies as an MBean

See Also
org.springframework.jmx.export.MBeanExporter#isMBean(Class)
locateMBeanServerback to summary
public static MBeanServer locateMBeanServer() throws MBeanServerNotFoundException

Attempt to find a locally running MBeanServer. Fails if no MBeanServer can be found. Logs a warning if more than one MBeanServer found, returning the first one from the list.

Returns:MBeanServer

the MBeanServer if found

Exceptions
MBeanServerNotFoundException:
if no MBeanServer could be found
See Also
javax.management.MBeanServerFactory#findMBeanServer
locateMBeanServerback to summary
public static MBeanServer locateMBeanServer(String agentId) throws MBeanServerNotFoundException

Attempt to find a locally running MBeanServer. Fails if no MBeanServer can be found. Logs a warning if more than one MBeanServer found, returning the first one from the list.

Parameters
agentId:String

the agent identifier of the MBeanServer to retrieve. If this parameter is null, all registered MBeanServers are considered. If the empty String is given, the platform MBeanServer will be returned.

Returns:MBeanServer

the MBeanServer if found

Exceptions
MBeanServerNotFoundException:
if no MBeanServer could be found
See Also
javax.management.MBeanServerFactory#findMBeanServer(String)
parameterInfoToTypesback to summary
public static Class<?>[] parameterInfoToTypes(MBeanParameterInfo[] paramInfo) throws ClassNotFoundException

Convert an array of MBeanParameterInfo into an array of Class instances corresponding to the parameters.

Parameters
paramInfo:MBeanParameterInfo[]

the JMX parameter info

Returns:Class<?>[]

the parameter types as classes

Annotations
@Nullable
Exceptions
ClassNotFoundException:
if a parameter type could not be resolved
parameterInfoToTypesback to summary
public static Class<?>[] parameterInfoToTypes(MBeanParameterInfo[] paramInfo, ClassLoader classLoader) throws ClassNotFoundException

Convert an array of MBeanParameterInfo into an array of Class instances corresponding to the parameters.

Parameters
paramInfo:MBeanParameterInfo[]

the JMX parameter info

classLoader:ClassLoader

the ClassLoader to use for loading parameter types

Returns:Class<?>[]

the parameter types as classes

Annotations
@Nullable
Exceptions
ClassNotFoundException:
if a parameter type could not be resolved