org.ow2.jasmine.probe.collectors.jmx.internal
Class JmxUtil

java.lang.Object
  extended by org.ow2.jasmine.probe.collectors.jmx.internal.JmxUtil

public class JmxUtil
extends Object

Support for access to MBean attributes and attribute fragments.

Author:
danesa

Constructor Summary
JmxUtil()
           
 
Method Summary
static Attribute createNewIndexedAttribute(String contName, String index, Object elemValue)
          Create a new Attribute instance for an indexed element.
static Attribute createNewItemAttribute(String contName, String key, Object itemValue)
          Create a new Attribute instance for a keyed item.
static Attribute getAttributeFragment(String name, Attribute att)
          Return an Attribute object corresponding to the given attribute fragment name.
static List<Attribute> getAttributeFragments(Attribute att)
          Decompose a JMX Attribute having a complex type into a list of Attributes having simple types (the fragments).
protected static AttributeList getAttributes(MBeanServerConnection cnx, ObjectName objname)
          Get an AttributeList corresponding to all the attribute names of a given MBean
protected static AttributeList getAttributes(MBeanServerConnection cnx, ObjectName objname, List<String> attNames)
          Get an AttributeList corresponding to a list of attribute names of a given MBean
protected static AttributeList getAttributesForProvidedNames(MBeanServerConnection cnx, ObjectName objname, Collection<String> names, String indicName)
          Get Attribute instances for all attribute names and/or attribute fragment names.
static List<String> getMBeanAttNames(MBeanServerConnection cnx, ObjectName on)
          Return a list of attribute names of a given MBean.
static Set<ObjectName> getMBeans(MBeanServerConnection cnx, ObjectName on)
          Get all the MBeans corresponding to an ObjectName pattern.
static ObjectName getObjectName(String pattern)
           
protected static boolean hasAttributes(List<String> attrlist)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JmxUtil

public JmxUtil()
Method Detail

getMBeans

public static Set<ObjectName> getMBeans(MBeanServerConnection cnx,
                                        ObjectName on)
                                 throws IOException
Get all the MBeans corresponding to an ObjectName pattern. When the pattern is null or no domain and key properties are specified, all objects are selected (and filtered if a query is specified). It returns the set of ObjectNames for the MBeans selected.

Parameters:
cnx - Connection to the MBean server
on - ObjectName pattern
Returns:
the set of ObjectNames corresponding to the pattern
Throws:
IOException - A communication problem occurred when talking to the MBean server.

getMBeanAttNames

public static List<String> getMBeanAttNames(MBeanServerConnection cnx,
                                            ObjectName on)
                                     throws IOException,
                                            JMException
Return a list of attribute names of a given MBean.

Parameters:
cnx - MBeanServer connection
on - The MBean's name.
Throws:
IOException - A communication problem occurred when talking to the MBean server.
JMException - A JMX exception occurred when using the MBean.

getObjectName

public static ObjectName getObjectName(String pattern)
                                throws JasmineCollectorException
Returns:
The ObjectName instance corresponding to the mbean pattern provided in the indicator definition.
Throws:
JasmineCollectorException - an ObjectName could not be obtained as the pattern in not well formed given the JMX naming conventions.

createNewIndexedAttribute

public static Attribute createNewIndexedAttribute(String contName,
                                                  String index,
                                                  Object elemValue)
Create a new Attribute instance for an indexed element. The attribute's value is the value of the element having the given index. The atrtibute's name is generated from the container's name (the name associated to the indexed object) and the index value.

Parameters:
contName - the name associated to the indexed object
index - the element's index
elemValue - the value of the element having the given index
Returns:
the created Attribute instance

createNewItemAttribute

public static Attribute createNewItemAttribute(String contName,
                                               String key,
                                               Object itemValue)
Create a new Attribute instance for a keyed item. The attribute's value is the value of the item having the given key. The atrtibute's name is generated from the container's name and the key value.

Parameters:
contName - the name associated to the composite object (the container)
key - the item's key
itemValue - the value of the item having the given key
Returns:
the created Attribute instance

getAttributeFragment

public static Attribute getAttributeFragment(String name,
                                             Attribute att)
                                      throws FragmentNameException
Return an Attribute object corresponding to the given attribute fragment name.

Parameters:
cnx - Connection to the MBean server
objname - MBean to poll
name - attribute fragment name
rootAtt - the MBean attribute containing this fragment
Returns:
the Attribute object containing the fragment's value. The returned Attribute object's name, is the given name.
Throws:
IOException - A communication problem occurred when talking to the MBean server.
JMException - Problem with the JMX code.
FragmentNameException - exception related to the fragment naming policy

getAttributeFragments

public static List<Attribute> getAttributeFragments(Attribute att)
                                             throws ComplexValuesException
Decompose a JMX Attribute having a complex type into a list of Attributes having simple types (the fragments). The supported complex types are: The supported simple types are:

Parameters:
att - The initial attribute which may have a complex or a simple type. It its value has a simple type, the attribute is returned as it is. If it has a complex type, its value is decomposed in simple elements, the fragments.
Returns:
A list of fragments. A fragment is contained in an Attribute instance. A fragment's value is a simple value obtained by a complex value decomposition. A fragment's name is a name is based on the fragments naming policy. It starts with the initial attribute's name and contains a representation of the path followed by the decomposition process.
Throws:
ComplexValuesException

getAttributes

protected static AttributeList getAttributes(MBeanServerConnection cnx,
                                             ObjectName objname,
                                             List<String> attNames)
                                      throws IOException,
                                             JMException
Get an AttributeList corresponding to a list of attribute names of a given MBean

Parameters:
cnx - Connection to the MBean server
objname - name of the MBean to poll
attNames - list of attribute names
Returns:
an AttributeList
Throws:
IOException
JMException

getAttributes

protected static AttributeList getAttributes(MBeanServerConnection cnx,
                                             ObjectName objname)
                                      throws IOException,
                                             JMException
Get an AttributeList corresponding to all the attribute names of a given MBean

Parameters:
cnx - Connection to the MBean server
objname - name of the MBean to poll
Returns:
an AttributeList
Throws:
IOException
JMException

getAttributesForProvidedNames

protected static AttributeList getAttributesForProvidedNames(MBeanServerConnection cnx,
                                                             ObjectName objname,
                                                             Collection<String> names,
                                                             String indicName)
                                                      throws IOException,
                                                             JMException
Get Attribute instances for all attribute names and/or attribute fragment names.

Parameters:
cnx - Connection to the MBean server
objname - name of the MBean to poll
names - provided names (attribute or fragment names to poll)
Returns:
AttributeList corresponding to the given names and to the given MBean
Throws:
IOException
JMException

hasAttributes

protected static boolean hasAttributes(List<String> attrlist)
Parameters:
attrlist - list of attribute/fragment names from the indicator's definition (atts property)
Returns:
true if attributes and or fragments are provided by the indicator definition.


Copyright © 2012 OW2 Consortium. All Rights Reserved.