patterntesting.runtime.jmx
Class MBeanHelper

Package class diagram package MBeanHelper
java.lang.Object
  extended by patterntesting.runtime.jmx.MBeanHelper

public class MBeanHelper
extends Object

This class simplifies the use of JMX and MBeans a little bit.

Since:
19.02.2009
Version:
$Revision: 1.15 $
Author:
oliver

Method Summary
static TabularDataSupport createTabularDataSupport(CompositeType rowType, String[] itemNames)
          Creates a TabularDataSupport object.
static Object getAttribute(ObjectName mbean, String attributeName)
          Gets the attribute.
static Object getAttribute(String mbeanName, String attributeName)
          Gets the attribute.
static String getMBeanName(Class<?> cl)
          Converts the class name into a MBean name.
static String getMBeanName(Class<?> cl, int level)
          Converts the class name into a MBean name.
static String getMBeanName(Object mbean)
          Gets an MBean name for the given object.
static String getMBeanName(Object mbean, int level)
          Gets an MBean name for the given object.
static ObjectInstance getObjectInstance(ObjectName mbeanName)
          Gets the object instance.
static ObjectInstance getObjectInstance(String name)
          Gets the object instance.
static boolean isRegistered(Object obj)
          Checks if is registered.
static boolean isRegistered(String mbeanName)
          Checks if is registered.
static void registerMBean(Object mbean)
          Register the given object as MBean.
static void registerMBean(ObjectName name, Object mbean)
          Register m bean.
static void registerMBean(String mbeanName, Object mbean)
          Register the given object as MBean.
static void unregisterMBean(String mbeanName)
          Unregister m bean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getMBeanName

public static String getMBeanName(Object mbean)
Gets an MBean name for the given object.

Parameters:
mbean - the mbean
Returns:
the name of the MBean

getMBeanName

public static String getMBeanName(Object mbean,
                                  int level)
Gets an MBean name for the given object.

Parameters:
mbean - the mbean
level - the level
Returns:
the name of the MBean
Since:
1.4.3

getMBeanName

public static String getMBeanName(Class<?> cl)
Converts the class name into a MBean name. For a hierachical structure of the registered MBeans take a look at Java Management Extensions (JMX) - Best Practices.

The default level for an MBean is since 1.4.3 now set to "2" (see getMBeanName(Object, int). This means you will find all MBeans from PatternTesting Runtime under the node "patterntesting.runtime" if you open your JMX console (e.g. the 'jconsole' from the JDK).

Parameters:
cl - e.g. my.good.bye.World
Returns:
a valid MBean name e.g. "my:type=good,good=bye,name=World"
See Also:
getMBeanName(Class, int)

getMBeanName

public static String getMBeanName(Class<?> cl,
                                  int level)
Converts the class name into a MBean name. For a hierachical structure of the registered MBeans take a look at Java Management Extensions (JMX) - Best Practices.

With the 2nd parameter (level) you can control the root element. If you set it i.e. to 2 the result in the jconsole would look like:

 my.good
     bye
         World
 
if the given class is "my.good.by.World".

Parameters:
cl - e.g. my.good.bye.World
level - the level, e.g.
Returns:
a valid MBean name e.g. "my.good:type=bye,name=World"
Since:
1.4.3

registerMBean

public static void registerMBean(Object mbean)
                          throws JMException
Register the given object as MBean.

Parameters:
mbean - the mbean
Throws:
JMException - if registration fails

registerMBean

public static void registerMBean(String mbeanName,
                                 Object mbean)
Register the given object as MBean.

Parameters:
mbeanName - the mbean name
mbean - the mbean

registerMBean

public static void registerMBean(ObjectName name,
                                 Object mbean)
Register m bean.

Parameters:
name - the name
mbean - the mbean

unregisterMBean

public static void unregisterMBean(String mbeanName)
Unregister m bean.

Parameters:
mbeanName - the mbean name

isRegistered

public static boolean isRegistered(String mbeanName)
Checks if is registered.

Parameters:
mbeanName - the mbean name
Returns:
true, if is registered

isRegistered

public static boolean isRegistered(Object obj)
Checks if is registered.

Parameters:
obj - the obj
Returns:
true, if is registered

getObjectInstance

public static ObjectInstance getObjectInstance(String name)
                                        throws InstanceNotFoundException
Gets the object instance.

Parameters:
name - the name
Returns:
the object instance
Throws:
InstanceNotFoundException - the instance not found exception

getObjectInstance

public static ObjectInstance getObjectInstance(ObjectName mbeanName)
                                        throws InstanceNotFoundException
Gets the object instance.

Parameters:
mbeanName - the mbean name
Returns:
the object instance
Throws:
InstanceNotFoundException - the instance not found exception

getAttribute

public static Object getAttribute(String mbeanName,
                                  String attributeName)
                           throws InstanceNotFoundException,
                                  JMException
Gets the attribute.

Parameters:
mbeanName - the mbean name
attributeName - the attribute name
Returns:
the attribute
Throws:
InstanceNotFoundException - the instance not found exception
JMException - the jM exception

getAttribute

public static Object getAttribute(ObjectName mbean,
                                  String attributeName)
                           throws InstanceNotFoundException,
                                  JMException
Gets the attribute.

Parameters:
mbean - the mbean
attributeName - the attribute name
Returns:
the attribute
Throws:
InstanceNotFoundException - the instance not found exception
JMException - the jM exception

createTabularDataSupport

public static TabularDataSupport createTabularDataSupport(CompositeType rowType,
                                                          String[] itemNames)
                                                   throws OpenDataException
Creates a TabularDataSupport object.

Parameters:
rowType - the row type
itemNames - the item names
Returns:
the tabular data support
Throws:
OpenDataException - the open data exception


Copyright © 2002–2014 PatternTesting Team. All rights reserved.