Package patterntesting.runtime.jmx
Class MBeanHelper
- java.lang.Object
-
- patterntesting.runtime.jmx.MBeanHelper
-
public class MBeanHelper extends java.lang.Object
This class simplifies the use of JMX and MBeans a little bit.- Since:
- 19.02.2009
- Version:
- $Revision: 1.30 $
- Author:
- oliver
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static javax.management.openmbean.TabularDataSupport
createTabularDataSupport(javax.management.openmbean.CompositeType rowType, java.lang.String[] itemNames)
Creates aTabularDataSupport
object.static javax.management.ObjectName
getAsObjectName(java.lang.Class<?> mbeanClass)
Gets a class asObjectName
.static javax.management.ObjectName
getAsObjectName(java.lang.String name)
Gets a class asObjectName
.static java.lang.Object
getAttribute(java.lang.String mbeanName, java.lang.String attributeName)
Gets the attribute.static java.lang.Object
getAttribute(javax.management.ObjectName mbean, java.lang.String attributeName)
Gets the attribute.static java.lang.String
getMBeanName(java.lang.Class<?> cl)
Converts the class name into a MBean name.static java.lang.String
getMBeanName(java.lang.Class<?> cl, int level)
Converts the class name into a MBean name.static java.lang.String
getMBeanName(java.lang.Object mbean)
Gets an MBean name for the given object.static java.lang.String
getMBeanName(java.lang.Object mbean, int level)
Gets an MBean name for the given object.static java.lang.String
getMBeanName(java.lang.String name)
Because it is not so easy to construct a correct MBean name.static javax.management.ObjectInstance
getObjectInstance(java.lang.String name)
Gets the object instance.static javax.management.ObjectInstance
getObjectInstance(javax.management.ObjectName mbeanName)
Gets the object instance.static boolean
isRegistered(java.lang.Object obj)
Checks if is registered.static boolean
isRegistered(java.lang.String mbeanName)
Checks if is registered.static boolean
isRegistered(javax.management.ObjectName name)
Checks if is registered.static void
registerMBean(java.lang.Object mbean)
Register the given object as MBean.static void
registerMBean(java.lang.String mbeanName, java.lang.Object mbean)
Register the given object as MBean.static void
registerMBean(javax.management.ObjectName name, java.lang.Object mbean)
Register m bean.static void
unregisterMBean(java.lang.String mbeanName)
Unregister an MBean.static void
unregisterMBean(javax.management.ObjectName name)
Unregister an MBean.
-
-
-
Method Detail
-
getMBeanName
public static java.lang.String getMBeanName(java.lang.Object mbean)
Gets an MBean name for the given object.- Parameters:
mbean
- the mbean- Returns:
- the name of the MBean
-
getMBeanName
public static java.lang.String getMBeanName(java.lang.Object mbean, int level)
Gets an MBean name for the given object.- Parameters:
mbean
- the mbeanlevel
- the level- Returns:
- the name of the MBean
- Since:
- 1.4.3
-
getMBeanName
public static java.lang.String getMBeanName(java.lang.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 java.lang.String getMBeanName(java.lang.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.Worldlevel
- the level, e.g.- Returns:
- a valid MBean name e.g. "my.good:type=bye,name=World"
- Since:
- 1.4.3
-
getMBeanName
public static java.lang.String getMBeanName(java.lang.String name)
Because it is not so easy to construct a correct MBean name. So this method helps to translate a simple name into an MBean name.If the given name is already a a valid MBean name it will be returned untouched.
- Parameters:
name
- e.g. "one.two.For"- Returns:
- e.g. "one:type=two,name=For"
- Since:
- 1.6
-
getAsObjectName
public static javax.management.ObjectName getAsObjectName(java.lang.String name)
Gets a class asObjectName
.- Parameters:
name
- the name- Returns:
- name as object name
- Since:
- 1.6
-
getAsObjectName
public static javax.management.ObjectName getAsObjectName(java.lang.Class<?> mbeanClass)
Gets a class asObjectName
.- Parameters:
mbeanClass
- the mbean class- Returns:
- class as object name
- Since:
- 1.6
-
registerMBean
public static void registerMBean(java.lang.Object mbean) throws javax.management.JMException
Register the given object as MBean.- Parameters:
mbean
- the mbean- Throws:
javax.management.JMException
- if registration fails
-
registerMBean
public static void registerMBean(java.lang.String mbeanName, java.lang.Object mbean)
Register the given object as MBean.- Parameters:
mbeanName
- the mbean namembean
- the mbean
-
registerMBean
public static void registerMBean(javax.management.ObjectName name, java.lang.Object mbean)
Register m bean.- Parameters:
name
- the namembean
- the mbean
-
unregisterMBean
public static void unregisterMBean(java.lang.String mbeanName)
Unregister an MBean.- Parameters:
mbeanName
- the mbean name
-
unregisterMBean
public static void unregisterMBean(javax.management.ObjectName name)
Unregister an MBean.- Parameters:
name
- the name
-
isRegistered
public static boolean isRegistered(java.lang.String mbeanName)
Checks if is registered.- Parameters:
mbeanName
- the mbean name- Returns:
- true, if is registered
-
isRegistered
public static boolean isRegistered(javax.management.ObjectName name)
Checks if is registered.- Parameters:
name
- the name- Returns:
- true, if is registered
- Since:
- 1.6
-
isRegistered
public static boolean isRegistered(java.lang.Object obj)
Checks if is registered.- Parameters:
obj
- the obj- Returns:
- true, if is registered
-
getObjectInstance
public static javax.management.ObjectInstance getObjectInstance(java.lang.String name) throws javax.management.InstanceNotFoundException
Gets the object instance.- Parameters:
name
- the name- Returns:
- the object instance
- Throws:
javax.management.InstanceNotFoundException
- the instance not found exception
-
getObjectInstance
public static javax.management.ObjectInstance getObjectInstance(javax.management.ObjectName mbeanName) throws javax.management.InstanceNotFoundException
Gets the object instance.- Parameters:
mbeanName
- the mbean name- Returns:
- the object instance
- Throws:
javax.management.InstanceNotFoundException
- the instance not found exception
-
getAttribute
public static java.lang.Object getAttribute(java.lang.String mbeanName, java.lang.String attributeName) throws javax.management.JMException
Gets the attribute.- Parameters:
mbeanName
- the mbean nameattributeName
- the attribute name- Returns:
- the attribute
- Throws:
javax.management.InstanceNotFoundException
- the instance not found exceptionjavax.management.JMException
- the jM exception
-
getAttribute
public static java.lang.Object getAttribute(javax.management.ObjectName mbean, java.lang.String attributeName) throws javax.management.JMException
Gets the attribute.- Parameters:
mbean
- the mbeanattributeName
- the attribute name- Returns:
- the attribute
- Throws:
javax.management.InstanceNotFoundException
- the instance not found exceptionjavax.management.JMException
- the jM exception
-
createTabularDataSupport
public static javax.management.openmbean.TabularDataSupport createTabularDataSupport(javax.management.openmbean.CompositeType rowType, java.lang.String[] itemNames) throws javax.management.openmbean.OpenDataException
Creates aTabularDataSupport
object.- Parameters:
rowType
- the row typeitemNames
- the item names- Returns:
- the tabular data support
- Throws:
javax.management.openmbean.OpenDataException
- the open data exception
-
-