org.springframework.jmx.support
Class JmxUtils

java.lang.Object
  extended by org.springframework.jmx.support.JmxUtils

public class JmxUtils
extends Object

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

Constructor Summary
JmxUtils()
           
 
Method Summary
static ObjectName convertToObjectName(Object value)
          Attempts to covert the supplied Object to an instance ObjectName.
static String getAttributeName(PropertyDescriptor property, boolean useStrictCasing)
          Return the JMX attribute name to use for the given JavaBeans property.
static Class getClassToExpose(Class beanClass)
          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 String[] getMethodSignature(Method method)
          Create a String[] representing the signature of a method.
static boolean isMBean(Class beanClass)
          Check whether the supplied Class is a valid MBean resource.
static MBeanServer locateMBeanServer()
          Attempt to find a locally running MBeanServer.
static MBeanServer locateMBeanServer(String agentId)
          Attempt to find a locally running MBeanServer.
static Class[] parameterInfoToTypes(MBeanParameterInfo[] paramInfo)
          Convert an array of MBeanParameterInfo into an array of Class instances corresponding to the parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JmxUtils

public JmxUtils()
Method Detail

locateMBeanServer

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:
the MBeanServer if found
Throws:
MBeanServerNotFoundException - if no MBeanServer could be found
See Also:
MBeanServerFactory.findMBeanServer(java.lang.String)

locateMBeanServer

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 - the agent identifier of the MBeanServer to retrieve. If this parameter is null, all registered MBeanServers are considered.
Returns:
the MBeanServer if found
Throws:
MBeanServerNotFoundException - if no MBeanServer could be found
See Also:
MBeanServerFactory.findMBeanServer(String)

parameterInfoToTypes

public static Class[] parameterInfoToTypes(MBeanParameterInfo[] paramInfo)
                                    throws ClassNotFoundException
Convert an array of MBeanParameterInfo into an array of Class instances corresponding to the parameters.

Throws:
ClassNotFoundException

getMethodSignature

public static String[] getMethodSignature(Method method)
Create a String[] representing the signature of a method. Each element in the array is the fully qualified class name of the corresponding argument in the methods signature.


getAttributeName

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 - the JavaBeans property descriptor
useStrictCasing - whether to use strict casing
Returns:
the JMX attribute name to use

isMBean

public static boolean isMBean(Class beanClass)
Check whether the supplied Class is a valid MBean resource.

Parameters:
beanClass - the class of the bean to test

getClassToExpose

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).

Default implementation returns the target class 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:
AopUtils.isCglibProxy(Object), Advised.getTargetSource(), TargetSource.getTargetClass()

getClassToExpose

public static Class getClassToExpose(Class beanClass)
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).

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

Parameters:
beanClass - the bean class (might be an AOP proxy class)
Returns:
the bean class to expose
See Also:
AopUtils.isCglibProxyClass(Class)

convertToObjectName

public static ObjectName convertToObjectName(Object value)
                                      throws MalformedObjectNameException
Attempts to covert the supplied Object to an instance ObjectName. If the supplied Object is already an instance of ObjectName then it is returned as is. If the Object is an instance of String it is treated as the String form the ObjectName. Any other type results in an IllegalArgumentException.

Parameters:
value - the value to convert to a JMX ObjectName
Returns:
the resolved JMX ObjectName
Throws:
MalformedObjectNameException - in case of an invalid object name specification


Copyright (c) 2002-2007 The Spring Framework Project.