voldemort.utils
Class JmxUtils

java.lang.Object
  extended by voldemort.utils.JmxUtils

public class JmxUtils
extends java.lang.Object

JMX helper functions These rely on annotations to create MBeans. Would be easier to just use the annotations in Java 6, but we don't want to require Java 6 just for our own convenience. Hence reinventing the wheel.


Field Summary
static java.lang.String MBEAN_NAME_SEPARATOR
           
 
Constructor Summary
JmxUtils()
           
 
Method Summary
static javax.management.modelmbean.ModelMBean createModelMBean(java.lang.Object o)
          Create a model mbean from an object using the description given in the Jmx annotation if present.
static javax.management.ObjectName createObjectName(java.lang.Class<?> c)
          Create an ObjectName from a class
static javax.management.ObjectName createObjectName(java.lang.String domain, java.lang.String type)
          Create a JMX ObjectName
static javax.management.modelmbean.ModelMBeanAttributeInfo[] extractAttributeInfo(java.lang.Object object)
          Extract all operations from the given object that have been annotated with the Jmx annotation.
static javax.management.modelmbean.ModelMBeanOperationInfo[] extractOperationInfo(java.lang.Object object)
          Extract all operations and attributes from the given object that have been annotated with the Jmx annotation.
static javax.management.MBeanParameterInfo[] extractParameterInfo(java.lang.reflect.Method m)
          Extract the parameters from a method using the Jmx annotation if present, or just the raw types otherwise
static java.lang.String getClassName(java.lang.Class<?> c)
          Get the class name without the package
static java.lang.String getJmxId(int jmxId)
          Return the string representation of jmxId
static java.lang.String getPackageName(java.lang.Class<?> c)
          Get the package for this class
static void registerMbean(javax.management.MBeanServer server, javax.management.modelmbean.ModelMBean mbean, javax.management.ObjectName name)
          Register the given mbean with the server
static void registerMbean(java.lang.Object mbean, javax.management.ObjectName name)
          Register the given mbean with the platform mbean server
static javax.management.ObjectName registerMbean(java.lang.String typeName, java.lang.Object obj)
          Register the given object under the package name of the object's class with the given type name.
static void unregisterMbean(javax.management.MBeanServer server, javax.management.ObjectName name)
          Unregister the mbean with the given name
static void unregisterMbean(javax.management.ObjectName name)
          Unregister the mbean with the given name from the platform mbean server
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MBEAN_NAME_SEPARATOR

public static final java.lang.String MBEAN_NAME_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

JmxUtils

public JmxUtils()
Method Detail

createModelMBean

public static javax.management.modelmbean.ModelMBean createModelMBean(java.lang.Object o)
Create a model mbean from an object using the description given in the Jmx annotation if present. Only operations are supported so far, no attributes, constructors, or notifications

Parameters:
o - The object to create an MBean for
Returns:
The ModelMBean for the given object

extractOperationInfo

public static javax.management.modelmbean.ModelMBeanOperationInfo[] extractOperationInfo(java.lang.Object object)
Extract all operations and attributes from the given object that have been annotated with the Jmx annotation. Operations are all methods that are marked with the JmxOperation annotation.

Parameters:
object - The object to process
Returns:
An array of operations taken from the object

extractAttributeInfo

public static javax.management.modelmbean.ModelMBeanAttributeInfo[] extractAttributeInfo(java.lang.Object object)
Extract all operations from the given object that have been annotated with the Jmx annotation. Operations are all methods that are marked with the JMX annotation and are not getters and setters (which are extracted as attributes).

Parameters:
object - The object to process
Returns:
An array of attributes taken from the object

extractParameterInfo

public static javax.management.MBeanParameterInfo[] extractParameterInfo(java.lang.reflect.Method m)
Extract the parameters from a method using the Jmx annotation if present, or just the raw types otherwise

Parameters:
m - The method to extract parameters from
Returns:
An array of parameter infos

createObjectName

public static javax.management.ObjectName createObjectName(java.lang.String domain,
                                                           java.lang.String type)
Create a JMX ObjectName

Parameters:
domain - The domain of the object
type - The type of the object
Returns:
An ObjectName representing the name

createObjectName

public static javax.management.ObjectName createObjectName(java.lang.Class<?> c)
Create an ObjectName from a class

Parameters:
c - The class
Returns:
The created object name

getPackageName

public static java.lang.String getPackageName(java.lang.Class<?> c)
Get the package for this class

Parameters:
c - The class
Returns:
The package name as a String

getClassName

public static java.lang.String getClassName(java.lang.Class<?> c)
Get the class name without the package

Parameters:
c - The class name with package
Returns:
the class name without the package

registerMbean

public static void registerMbean(java.lang.Object mbean,
                                 javax.management.ObjectName name)
Register the given mbean with the platform mbean server

Parameters:
mbean - The mbean to register
name - The name to register under

registerMbean

public static javax.management.ObjectName registerMbean(java.lang.String typeName,
                                                        java.lang.Object obj)
Register the given object under the package name of the object's class with the given type name. this method using the platform mbean server as returned by ManagementFactory.getPlatformMBeanServer()

Parameters:
typeName - The name of the type to register
obj - The object to register as an mbean

registerMbean

public static void registerMbean(javax.management.MBeanServer server,
                                 javax.management.modelmbean.ModelMBean mbean,
                                 javax.management.ObjectName name)
Register the given mbean with the server

Parameters:
server - The server to register with
mbean - The mbean to register
name - The name to register under

unregisterMbean

public static void unregisterMbean(javax.management.MBeanServer server,
                                   javax.management.ObjectName name)
Unregister the mbean with the given name

Parameters:
server - The server to unregister from
name - The name of the mbean to unregister

unregisterMbean

public static void unregisterMbean(javax.management.ObjectName name)
Unregister the mbean with the given name from the platform mbean server

Parameters:
name - The name of the mbean to unregister

getJmxId

public static java.lang.String getJmxId(int jmxId)
Return the string representation of jmxId

Parameters:
jmxId -
Returns:
string representation of jmx id


Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao, Chinmay Soman, Vinoth Chandar, Zhongjie Wu