Package org.springframework.jmx.support
Class JmxUtils
java.lang.Object
org.springframework.jmx.support.JmxUtils
Collection of generic utility methods to support Spring JMX.
Includes a convenient method to locate an MBeanServer.
- Since:
- 1.2
- Author:
- Rob Harrop, Juergen Hoeller
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The key used when extending an existingObjectName
with the identity hash code of its corresponding managed resource. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectName
appendIdentityToObjectName
(ObjectName objectName, Object managedResource) Append an additional key/value pair to an existingObjectName
with the key being the static valueidentity
and the value being the identity hash code of the managed resource being exposed on the suppliedObjectName
.static String
getAttributeName
(PropertyDescriptor property, boolean useStrictCasing) Return the JMX attribute name to use for the given JavaBeans property.static Class<?>
getClassToExpose
(Class<?> clazz) Return the class or interface to expose for the given bean class.static Class<?>
getClassToExpose
(Object managedBean) Return the class or interface to expose for the given bean.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").static String[]
getMethodSignature
(Method method) Create aString[]
representing the argument signature of a method.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).static boolean
Determine whether the given bean class qualifies as an MBean as-is.static MBeanServer
Attempt to find a locally runningMBeanServer
.static MBeanServer
locateMBeanServer
(String agentId) Attempt to find a locally runningMBeanServer
.static Class<?>[]
parameterInfoToTypes
(MBeanParameterInfo[] paramInfo) Convert an array ofMBeanParameterInfo
into an array ofClass
instances corresponding to the parameters.static Class<?>[]
parameterInfoToTypes
(MBeanParameterInfo[] paramInfo, ClassLoader classLoader) Convert an array ofMBeanParameterInfo
into an array ofClass
instances corresponding to the parameters.
-
Field Details
-
IDENTITY_OBJECT_NAME_KEY
The key used when extending an existingObjectName
with the identity hash code of its corresponding managed resource.- See Also:
-
-
Constructor Details
-
JmxUtils
public JmxUtils()
-
-
Method Details
-
locateMBeanServer
Attempt to find a locally runningMBeanServer
. Fails if noMBeanServer
can be found. Logs a warning if more than oneMBeanServer
found, returning the first one from the list.- Returns:
- the
MBeanServer
if found - Throws:
MBeanServerNotFoundException
- if noMBeanServer
could be found- See Also:
-
locateMBeanServer
public static MBeanServer locateMBeanServer(@Nullable String agentId) throws MBeanServerNotFoundException Attempt to find a locally runningMBeanServer
. Fails if noMBeanServer
can be found. Logs a warning if more than oneMBeanServer
found, returning the first one from the list.- Parameters:
agentId
- the agent identifier of the MBeanServer to retrieve. If this parameter isnull
, all registered MBeanServers are considered. If the empty String is given, the platform MBeanServer will be returned.- Returns:
- the
MBeanServer
if found - Throws:
MBeanServerNotFoundException
- if noMBeanServer
could be found- See Also:
-
parameterInfoToTypes
@Nullable public static Class<?>[] parameterInfoToTypes(@Nullable MBeanParameterInfo[] paramInfo) throws ClassNotFoundException Convert an array ofMBeanParameterInfo
into an array ofClass
instances corresponding to the parameters.- Parameters:
paramInfo
- the JMX parameter info- Returns:
- the parameter types as classes
- Throws:
ClassNotFoundException
- if a parameter type could not be resolved
-
parameterInfoToTypes
@Nullable public static Class<?>[] parameterInfoToTypes(@Nullable MBeanParameterInfo[] paramInfo, @Nullable ClassLoader classLoader) throws ClassNotFoundException Convert an array ofMBeanParameterInfo
into an array ofClass
instances corresponding to the parameters.- Parameters:
paramInfo
- the JMX parameter infoclassLoader
- the ClassLoader to use for loading parameter types- Returns:
- the parameter types as classes
- Throws:
ClassNotFoundException
- if a parameter type could not be resolved
-
getMethodSignature
Create aString[]
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
- the method to build an argument signature for- Returns:
- the signature as array of argument types
-
getAttributeName
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 calledFoo
. With strict casing disabled,getFoo()
would translate to justfoo
.- Parameters:
property
- the JavaBeans property descriptoruseStrictCasing
- whether to use strict casing- Returns:
- the JMX attribute name to use
-
appendIdentityToObjectName
public static ObjectName appendIdentityToObjectName(ObjectName objectName, Object managedResource) throws MalformedObjectNameException Append an additional key/value pair to an existingObjectName
with the key being the static valueidentity
and the value being the identity hash code of the managed resource being exposed on the suppliedObjectName
. This can be used to provide a uniqueObjectName
for each distinct instance of a particular bean or class. Useful when generatingObjectNames
at runtime for a set of managed resources based on the template value supplied by aObjectNamingStrategy
.- Parameters:
objectName
- the original JMX ObjectNamemanagedResource
- the MBean instance- Returns:
- an ObjectName with the MBean identity added
- Throws:
MalformedObjectNameException
- in case of an invalid object name specification- See Also:
-
getClassToExpose
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
- the bean instance (might be an AOP proxy)- Returns:
- the bean class to expose
- See Also:
-
getClassToExpose
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
- the bean class (might be an AOP proxy class)- Returns:
- the bean class to expose
- See Also:
-
isMBean
Determine whether the given bean class qualifies as an MBean as-is.This implementation checks for
DynamicMBean
classes as well as classes with corresponding "*MBean" interface (Standard MBeans) or corresponding "*MXBean" interface (Java MXBeans).- Parameters:
clazz
- the bean class to analyze- Returns:
- whether the class qualifies as an MBean
- See Also:
-
getMBeanInterface
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
- the class to check- Returns:
- the Standard MBean interface for the given class
-
getMXBeanInterface
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
- the class to check- Returns:
- whether there is an MXBean interface for the given class
-