com.sun.appserv.management.util.jmx
Class JMXUtil

java.lang.Object
  extended by com.sun.appserv.management.util.jmx.JMXUtil

public final class JMXUtil
extends Object


Field Summary
static String GET
           
static String IS
           
static String MBEAN_SERVER_DELEGATE
           
static String MBEAN_SERVER_ID_ATTRIBUTE_NAME
           
static String SET
           
static String WILD_ALL
          The wilcard property at the end of an ObjectName which indicates that all properties should be matched.
static String WILD_PROP
          The wilcard property at the end of an ObjectName which indicates that it's an ObjectName pattern.
 
Method Summary
static MBeanInfo addNotificationInfos(MBeanInfo origInfo, MBeanNotificationInfo[] notifs)
          Add MBeanNotificationInfo into the MBeanInfo.
static Map<String,MBeanAttributeInfo> attributeInfosToMap(MBeanAttributeInfo[] attrInfos)
          Convert an MBeanAttributeInfo[] to a Map where the keys are the Attribute names, and the values are MBeanAttributeInfo.
static Map<String,Attribute> attributeListToAttributeMap(AttributeList attrs)
          Convert an AttributeList to a Map where the keys are the Attribute names, and the values are Attribute.
static Map<String,String> attributeListToStringMap(AttributeList attrs)
          Convert an AttributeList to a Map where the keys are the Attribute names, and the values are the Attribute values.
static Map<String,Object> attributeListToValueMap(AttributeList attrs)
          Convert an AttributeList to a Map where the keys are the Attribute names, and the values are the Attribute values.
static Notification cloneNotification(Notification in, Object source)
           
static String concatenateProps(String props1, String props2)
           
static String concatenateProps(String props1, String props2, String props3)
           
static boolean domainMatches(String defaultDomain, ObjectName pattern, ObjectName candidate)
           
static MBeanAttributeInfo[] filterAttributeInfos(MBeanAttributeInfo[] infos, AttributeFilter filter)
           
static Set<ObjectName> findByProperty(Set<ObjectName> objectNames, String propertyKey, String propertyValue)
          Find all ObjectName(s) that contains the associated key and value
static Set<MBeanFeatureInfo> findInfoByName(MBeanFeatureInfo[] infos, String name)
          Find a feature by name (attribute name, operation name, etc) and return all matches.
static String findKey(Set<String> candidateKeys, ObjectName objectName)
          Find the first key that is present in the ObjectName
static int findMBeanOperationInfo(MBeanInfo info, String methodName, String[] parameterTypes)
          Find the index within the MBeanOperationInfo[] of the specified method with the specified parameter types.
static MBeanOperationInfo findOperation(MBeanOperationInfo[] operations, String operationName, String[] types)
           
static MBeanOperationInfo[] findOperations(MBeanOperationInfo[] operations, String operationName)
           
static ArrayList<MBeanAttributeInfo> generateAttributeInfos(Collection<Method> methodSet, boolean read, boolean write)
           
static MBeanAttributeInfo[] generateMBeanAttributeInfos(Collection<Method> getterSetters, Collection<Method> getters, Collection<Method> setters)
           
static MBeanOperationInfo[] generateMBeanOperationInfos(Collection<Method> methodSet)
           
static MBeanParameterInfo[] generateSignature(Class[] sig)
           
static String[] getAllAttributeNames(MBeanServerConnection conn, ObjectName objectName)
           
static MBeanAttributeInfo[] getAttributeInfos(MBeanServerConnection conn, ObjectName objectName)
           
static String getAttributeName(Method method)
           
static String[] getAttributeNames(MBeanAttributeInfo[] infos)
          Get a String[] of Attribute names.
static AttributeList getAttributesRobust(MBeanServerConnection conn, ObjectName objectName, String[] attrNames, Set<String> problemNames)
          Get the Attributes using getAttributes() if possible, but if exceptions are encountered, attempt to get them one-by-one.
static String[] getKeyProperty(String key, ObjectName[] objectNames)
           
static String[] getKeyProperty(String key, Set<ObjectName> objectNameSet)
           
static Set<String> getKeyPropertySet(String key, Set<ObjectName> objectNameSet)
           
static MBeanAttributeInfo getMBeanAttributeInfo(MBeanAttributeInfo[] infos, String attrName)
           
static MBeanAttributeInfo getMBeanAttributeInfo(MBeanInfo mbeanInfo, String attrName)
           
static ObjectName getMBeanServerDelegateObjectName()
           
static String getMBeanServerID(MBeanServerConnection conn)
           
static String getProp(ObjectName objectName, String key)
           
static String getProps(ObjectName objectName, Set<String> propKeys)
           
static String getProps(ObjectName objectName, Set<String> propKeys, boolean ignoreMissing)
           
static String[] getSignature(MBeanParameterInfo[] infos)
           
static
<T extends Serializable>
Map<String,T>
getUserDataMapString_Serializable(Notification notif)
          Get a Map from the user data field of a Notification.
static MBeanInfo interfaceToMBeanInfo(Class theInterface)
           
static boolean isGetAttribute(Method m)
           
static boolean isGetAttributes(Method m)
           
static boolean isGetter(MBeanOperationInfo info)
           
static boolean isGetter(Method method)
          Return true if the method is of the form isXyz() or getXyz() (no parameters)
static boolean isIs(Method method)
           
static boolean isIsOrGetter(Method method)
          Return true if the method is of the form isXyz() or getXyz() (no parameters)
static boolean isSetAttribute(Method m)
           
static boolean isSetAttributes(Method m)
           
static boolean isSetter(Method method)
           
static void listenToMBeanServerDelegate(MBeanServerConnection conn, NotificationListener listener, NotificationFilter filter, Object handback)
           
static String makeProp(String name, String value)
           
static AttributeList mapToAttributeList(Map<String,Object> m)
          Convert an Map to an Attribute list where the keys are the Attribute names, and the values are objects.
static String mapToProps(Map<String,String> propsMap)
           
static boolean matchesPattern(String defaultDomain, ObjectName pattern, ObjectName candidate)
           
static MBeanAttributeInfo[] mergeMBeanAttributeInfos(MBeanAttributeInfo[] infos1, MBeanAttributeInfo[] infos2)
          Merge two MBeanAttributeInfo[].
static MBeanConstructorInfo[] mergeMBeanConstructorInfos(MBeanConstructorInfo[] infos1, MBeanConstructorInfo[] infos2)
          Merge two MBeanOperationInfo[].
static MBeanInfo mergeMBeanInfos(MBeanInfo info1, MBeanInfo info2)
          Merge two MBeanInfo.
static MBeanNotificationInfo[] mergeMBeanNotificationInfos(MBeanNotificationInfo[] infos1, MBeanNotificationInfo[] infos2)
          Merge two MBeanNotificationInfo[].
static MBeanOperationInfo[] mergeMBeanOperationInfos(MBeanOperationInfo[] infos1, MBeanOperationInfo[] infos2)
          Merge two MBeanOperationInfo[].
static MBeanInfo newMBeanInfo(MBeanInfo origMBeanInfo, MBeanAttributeInfo[] newAttrInfos)
          Make a new MBeanInfo from an existing one, substituting MBeanAttributeInfo[]
static MBeanInfo newMBeanInfo(MBeanInfo origMBeanInfo, MBeanOperationInfo[] newOps)
          Make a new MBeanInfo from an existing one, substituting MBeanOperationInfo[]
static ObjectName newObjectName(ObjectName objectName, String props)
           
static ObjectName newObjectName(String name)
          Create a new ObjectName, caller is guaranteeing that the name is well-formed (a RuntimeException will be thrown if not).
static ObjectName newObjectName(String domain, String props)
           
static ObjectName newObjectNamePattern(String domain, Map<String,String> props)
          Build an ObjectName pattern.
static ObjectName newObjectNamePattern(String domain, String props)
          Build an ObjectName pattern.
static ObjectName[] objectNameSetToArray(Set<ObjectName> objectNameSet)
          Convert a Set of ObjectName into an array
static List<String> objectNamesToStrings(Collection<ObjectName> objectNames)
          Convert ObjectName into a Set of String.
static String[] objectNamesToStrings(ObjectName[] objectNames)
          Convert a Set of ObjectName into a Set of String
static Set<ObjectName> queryNames(MBeanServerConnection conn, ObjectName pattern, QueryExp exp)
          The sole purpose of this method is to move compiler warnings here, thus eliminating them from other call sites.
static Set<ObjectName> queryNames(MBeanServer server, ObjectName pattern, QueryExp exp)
          The sole purpose of this method is to move compiler warnings here, thus eliminating them from other call sites.
static MBeanInfo removeAttributes(MBeanInfo origInfo, String[] attributeNames)
           
static ObjectName removeProperty(ObjectName objectName, String key)
           
static ObjectName setKeyProperty(ObjectName objectName, String key, String value)
          Change or add a key property in an ObjectName.
static String toString(ObjectName objectName)
           
static void unregisterAll(MBeanServerConnection conn)
           
static void unregisterAll(MBeanServerConnection conn, Set<ObjectName> allNames)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MBEAN_SERVER_DELEGATE

public static final String MBEAN_SERVER_DELEGATE
See Also:
Constant Field Values

MBEAN_SERVER_ID_ATTRIBUTE_NAME

public static final String MBEAN_SERVER_ID_ATTRIBUTE_NAME
See Also:
Constant Field Values

WILD_PROP

public static final String WILD_PROP
The wilcard property at the end of an ObjectName which indicates that it's an ObjectName pattern.

See Also:
Constant Field Values

WILD_ALL

public static final String WILD_ALL
The wilcard property at the end of an ObjectName which indicates that all properties should be matched.

See Also:
Constant Field Values

GET

public static final String GET
See Also:
Constant Field Values

SET

public static final String SET
See Also:
Constant Field Values

IS

public static final String IS
See Also:
Constant Field Values
Method Detail

getMBeanServerDelegateObjectName

public static ObjectName getMBeanServerDelegateObjectName()

listenToMBeanServerDelegate

public static void listenToMBeanServerDelegate(MBeanServerConnection conn,
                                               NotificationListener listener,
                                               NotificationFilter filter,
                                               Object handback)
                                        throws IOException,
                                               InstanceNotFoundException
Throws:
IOException
InstanceNotFoundException

getMBeanServerID

public static String getMBeanServerID(MBeanServerConnection conn)
                               throws IOException,
                                      ReflectionException,
                                      InstanceNotFoundException,
                                      AttributeNotFoundException,
                                      MBeanException
Throws:
IOException
ReflectionException
InstanceNotFoundException
AttributeNotFoundException
MBeanException

newObjectName

public static ObjectName newObjectName(String name)
Create a new ObjectName, caller is guaranteeing that the name is well-formed (a RuntimeException will be thrown if not). This avoids having to catch all sorts of JMX exceptions.

Do not call this method if there is not 100% certainty of a well-formed name.


newObjectName

public static ObjectName newObjectName(ObjectName objectName,
                                       String props)

newObjectName

public static ObjectName newObjectName(String domain,
                                       String props)

newObjectNamePattern

public static ObjectName newObjectNamePattern(String domain,
                                              String props)
Build an ObjectName pattern.

Parameters:
domain - the JMX domain
props - properties of the ObjectName

newObjectNamePattern

public static ObjectName newObjectNamePattern(String domain,
                                              Map<String,String> props)
Build an ObjectName pattern.

Parameters:
domain - the JMX domain
props - properties of the ObjectName

mapToProps

public static String mapToProps(Map<String,String> propsMap)

removeProperty

public static ObjectName removeProperty(ObjectName objectName,
                                        String key)

makeProp

public static String makeProp(String name,
                              String value)

concatenateProps

public static String concatenateProps(String props1,
                                      String props2)

concatenateProps

public static String concatenateProps(String props1,
                                      String props2,
                                      String props3)

objectNameSetToArray

public static ObjectName[] objectNameSetToArray(Set<ObjectName> objectNameSet)
Convert a Set of ObjectName into an array

Parameters:
objectNameSet - a Set of ObjectName
Returns:
an ObjectName[]

getKeyProperty

public static String[] getKeyProperty(String key,
                                      ObjectName[] objectNames)
Parameters:
key - the property name, within the ObjectName
objectNames -
Returns:
values from each ObjectName

getProp

public static String getProp(ObjectName objectName,
                             String key)
Parameters:
objectName -
key -
Returns:
an ObjectName property with the specified key

getProps

public static String getProps(ObjectName objectName,
                              Set<String> propKeys)

getProps

public static String getProps(ObjectName objectName,
                              Set<String> propKeys,
                              boolean ignoreMissing)

getKeyProperty

public static String[] getKeyProperty(String key,
                                      Set<ObjectName> objectNameSet)
Parameters:
key - the property name, within the ObjectName
objectNameSet -
Returns:
values from each ObjectName

getKeyPropertySet

public static Set<String> getKeyPropertySet(String key,
                                            Set<ObjectName> objectNameSet)
Parameters:
key - the property name, within the ObjectName
objectNameSet -
Returns:
values from each ObjectName

findKey

public static String findKey(Set<String> candidateKeys,
                             ObjectName objectName)
Find the first key that is present in the ObjectName

Parameters:
candidateKeys -
objectName -
Returns:
first key present in the ObjectName

findByProperty

public static Set<ObjectName> findByProperty(Set<ObjectName> objectNames,
                                             String propertyKey,
                                             String propertyValue)
Find all ObjectName(s) that contains the associated key and value

Parameters:
objectNames -
propertyKey -
propertyValue -
Returns:
Set of all ObjectName that match

setKeyProperty

public static ObjectName setKeyProperty(ObjectName objectName,
                                        String key,
                                        String value)
Change or add a key property in an ObjectName.


unregisterAll

public static void unregisterAll(MBeanServerConnection conn,
                                 Set<ObjectName> allNames)
                          throws IOException,
                                 MalformedObjectNameException,
                                 MBeanRegistrationException
Throws:
IOException
MalformedObjectNameException
MBeanRegistrationException

unregisterAll

public static void unregisterAll(MBeanServerConnection conn)
                          throws IOException,
                                 MalformedObjectNameException,
                                 MBeanRegistrationException
Throws:
IOException
MalformedObjectNameException
MBeanRegistrationException

getAllAttributeNames

public static String[] getAllAttributeNames(MBeanServerConnection conn,
                                            ObjectName objectName)
                                     throws IOException,
                                            ReflectionException,
                                            IntrospectionException,
                                            InstanceNotFoundException
Throws:
IOException
ReflectionException
IntrospectionException
InstanceNotFoundException

filterAttributeInfos

public static MBeanAttributeInfo[] filterAttributeInfos(MBeanAttributeInfo[] infos,
                                                        AttributeFilter filter)

getAttributeNames

public static String[] getAttributeNames(MBeanAttributeInfo[] infos)
Get a String[] of Attribute names.

Parameters:
infos - array of infos

getMBeanAttributeInfo

public static MBeanAttributeInfo getMBeanAttributeInfo(MBeanAttributeInfo[] infos,
                                                       String attrName)
Parameters:
infos - array of infos
attrName -

getMBeanAttributeInfo

public static MBeanAttributeInfo getMBeanAttributeInfo(MBeanInfo mbeanInfo,
                                                       String attrName)
Parameters:
mbeanInfo -
attrName -

getAttributeInfos

public static MBeanAttributeInfo[] getAttributeInfos(MBeanServerConnection conn,
                                                     ObjectName objectName)
                                              throws IOException,
                                                     ReflectionException,
                                                     IntrospectionException,
                                                     InstanceNotFoundException
Parameters:
conn -
objectName -
Throws:
IOException
ReflectionException
IntrospectionException
InstanceNotFoundException

attributeListToAttributeMap

public static Map<String,Attribute> attributeListToAttributeMap(AttributeList attrs)
Convert an AttributeList to a Map where the keys are the Attribute names, and the values are Attribute.

Parameters:
attrs - the AttributeList

attributeListToValueMap

public static Map<String,Object> attributeListToValueMap(AttributeList attrs)
Convert an AttributeList to a Map where the keys are the Attribute names, and the values are the Attribute values.

Parameters:
attrs - the AttributeList

attributeListToStringMap

public static Map<String,String> attributeListToStringMap(AttributeList attrs)
Convert an AttributeList to a Map where the keys are the Attribute names, and the values are the Attribute values.

Parameters:
attrs - the AttributeList

attributeInfosToMap

public static Map<String,MBeanAttributeInfo> attributeInfosToMap(MBeanAttributeInfo[] attrInfos)
Convert an MBeanAttributeInfo[] to a Map where the keys are the Attribute names, and the values are MBeanAttributeInfo.

Parameters:
attrInfos - the AttributeList

removeAttributes

public static MBeanInfo removeAttributes(MBeanInfo origInfo,
                                         String[] attributeNames)

findInfoByName

public static Set<MBeanFeatureInfo> findInfoByName(MBeanFeatureInfo[] infos,
                                                   String name)
Find a feature by name (attribute name, operation name, etc) and return all matches. The feature is matched by calling MBeanFeatureInfo.getName().

Parameters:
infos - infos
name - name
Returns:
Set of the matching items

mapToAttributeList

public static AttributeList mapToAttributeList(Map<String,Object> m)
Convert an Map to an Attribute list where the keys are the Attribute names, and the values are objects.

Parameters:
m -

objectNamesToStrings

public static List<String> objectNamesToStrings(Collection<ObjectName> objectNames)
Convert ObjectName into a Set of String. The resulting strings are more readable than just a simple toString() on the ObjectName; they are sorted and output in preferential order.


objectNamesToStrings

public static String[] objectNamesToStrings(ObjectName[] objectNames)
Convert a Set of ObjectName into a Set of String


getAttributesRobust

public static AttributeList getAttributesRobust(MBeanServerConnection conn,
                                                ObjectName objectName,
                                                String[] attrNames,
                                                Set<String> problemNames)
                                         throws InstanceNotFoundException,
                                                IOException
Get the Attributes using getAttributes() if possible, but if exceptions are encountered, attempt to get them one-by-one.

Parameters:
conn - the conneciton
objectName - name of the object to access
attrNames - attribute names
problemNames - optional Set to which problem names will be added.
Returns:
AttributeList
Throws:
InstanceNotFoundException
IOException

isIs

public static boolean isIs(Method method)

isGetter

public static boolean isGetter(Method method)
Return true if the method is of the form isXyz() or getXyz() (no parameters)


isGetter

public static boolean isGetter(MBeanOperationInfo info)

findOperations

public static MBeanOperationInfo[] findOperations(MBeanOperationInfo[] operations,
                                                  String operationName)

findOperation

public static MBeanOperationInfo findOperation(MBeanOperationInfo[] operations,
                                               String operationName,
                                               String[] types)

isIsOrGetter

public static boolean isIsOrGetter(Method method)
Return true if the method is of the form isXyz() or getXyz() (no parameters)


getAttributeName

public static String getAttributeName(Method method)

isSetter

public static boolean isSetter(Method method)

isGetAttribute

public static boolean isGetAttribute(Method m)

isGetAttributes

public static boolean isGetAttributes(Method m)

isSetAttribute

public static boolean isSetAttribute(Method m)

isSetAttributes

public static boolean isSetAttributes(Method m)

generateAttributeInfos

public static ArrayList<MBeanAttributeInfo> generateAttributeInfos(Collection<Method> methodSet,
                                                                   boolean read,
                                                                   boolean write)

generateMBeanAttributeInfos

public static MBeanAttributeInfo[] generateMBeanAttributeInfos(Collection<Method> getterSetters,
                                                               Collection<Method> getters,
                                                               Collection<Method> setters)

getSignature

public static String[] getSignature(MBeanParameterInfo[] infos)

generateSignature

public static MBeanParameterInfo[] generateSignature(Class[] sig)

generateMBeanOperationInfos

public static MBeanOperationInfo[] generateMBeanOperationInfos(Collection<Method> methodSet)

interfaceToMBeanInfo

public static MBeanInfo interfaceToMBeanInfo(Class theInterface)

mergeMBeanAttributeInfos

public static MBeanAttributeInfo[] mergeMBeanAttributeInfos(MBeanAttributeInfo[] infos1,
                                                            MBeanAttributeInfo[] infos2)
Merge two MBeanAttributeInfo[]. info1 overrides any duplication in info2.

Parameters:
infos1 -
infos2 -

mergeMBeanNotificationInfos

public static MBeanNotificationInfo[] mergeMBeanNotificationInfos(MBeanNotificationInfo[] infos1,
                                                                  MBeanNotificationInfo[] infos2)
Merge two MBeanNotificationInfo[].

Parameters:
infos1 -
infos2 -

addNotificationInfos

public static MBeanInfo addNotificationInfos(MBeanInfo origInfo,
                                             MBeanNotificationInfo[] notifs)
Add MBeanNotificationInfo into the MBeanInfo.

Parameters:
origInfo -
notifs -

mergeMBeanOperationInfos

public static MBeanOperationInfo[] mergeMBeanOperationInfos(MBeanOperationInfo[] infos1,
                                                            MBeanOperationInfo[] infos2)
Merge two MBeanOperationInfo[].

Parameters:
infos1 -
infos2 -

mergeMBeanConstructorInfos

public static MBeanConstructorInfo[] mergeMBeanConstructorInfos(MBeanConstructorInfo[] infos1,
                                                                MBeanConstructorInfo[] infos2)
Merge two MBeanOperationInfo[].

Parameters:
infos1 -
infos2 -

mergeMBeanInfos

public static MBeanInfo mergeMBeanInfos(MBeanInfo info1,
                                        MBeanInfo info2)
Merge two MBeanInfo. 'info1' takes priority in conflicts, name, etc.

Parameters:
info1 -
info2 -

newMBeanInfo

public static MBeanInfo newMBeanInfo(MBeanInfo origMBeanInfo,
                                     MBeanAttributeInfo[] newAttrInfos)
Make a new MBeanInfo from an existing one, substituting MBeanAttributeInfo[]

Parameters:
origMBeanInfo -
newAttrInfos -

newMBeanInfo

public static MBeanInfo newMBeanInfo(MBeanInfo origMBeanInfo,
                                     MBeanOperationInfo[] newOps)
Make a new MBeanInfo from an existing one, substituting MBeanOperationInfo[]

Parameters:
origMBeanInfo -
newOps -

findMBeanOperationInfo

public static int findMBeanOperationInfo(MBeanInfo info,
                                         String methodName,
                                         String[] parameterTypes)
Find the index within the MBeanOperationInfo[] of the specified method with the specified parameter types. If parameterTypes is null, then the first operation whose name matches is returned.

Parameters:
info -
methodName -
parameterTypes -
Returns:
the index of the MBeanOperationInfo, or -1 if not found

domainMatches

public static boolean domainMatches(String defaultDomain,
                                    ObjectName pattern,
                                    ObjectName candidate)

matchesPattern

public static boolean matchesPattern(String defaultDomain,
                                     ObjectName pattern,
                                     ObjectName candidate)

toString

public static String toString(ObjectName objectName)

cloneNotification

public static Notification cloneNotification(Notification in,
                                             Object source)

queryNames

public static Set<ObjectName> queryNames(MBeanServerConnection conn,
                                         ObjectName pattern,
                                         QueryExp exp)
                                  throws IOException
The sole purpose of this method is to move compiler warnings here, thus eliminating them from other call sites. May be removed when JMX becomes generified.

Throws:
IOException

queryNames

public static Set<ObjectName> queryNames(MBeanServer server,
                                         ObjectName pattern,
                                         QueryExp exp)
The sole purpose of this method is to move compiler warnings here, thus eliminating them from other call sites. May be removed when JMX becomes generified.


getUserDataMapString_Serializable

public static final <T extends Serializable> Map<String,T> getUserDataMapString_Serializable(Notification notif)
Get a Map from the user data field of a Notification. This variant requires Map.