Package org.glassfish.admin.amx.util.jmx
Class JMXUtil
- java.lang.Object
-
- org.glassfish.admin.amx.util.jmx.JMXUtil
-
public final class JMXUtil extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringGETstatic StringISstatic StringMBEAN_SERVER_DELEGATEstatic StringMBEAN_SERVER_ID_ATTRIBUTE_NAMEstatic StringSETstatic StringWILD_ALLThe wilcard property at the end of an ObjectName which indicates that all properties should be matched.static StringWILD_PROPThe wilcard property at the end of an ObjectName which indicates that it's an ObjectName pattern.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static MBeanInfoaddNotificationInfos(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 NotificationcloneNotification(Notification in, Object source)static StringconcatenateProps(String props1, String props2)static StringconcatenateProps(String props1, String props2, String props3)static booleandomainMatches(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 valuestatic Set<MBeanFeatureInfo>findInfoByName(MBeanFeatureInfo[] infos, String name)Find a feature by name (attribute name, operation name, etc) and return all matches.static StringfindKey(Set<String> candidateKeys, ObjectName objectName)Find the first key that is present in the ObjectNamestatic intfindMBeanOperationInfo(MBeanInfo info, String methodName, String[] parameterTypes)Find the index within the MBeanOperationInfo[] of the specified method with the specified parameter types.static MBeanOperationInfofindOperation(MBeanOperationInfo[] operations, String operationName, String[] types)static Set<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 ObjectgetAttribute(MBeanServerConnection conn, ObjectName o, String attrName)convenience function to avoid try/catch.static MBeanAttributeInfo[]getAttributeInfos(MBeanServerConnection conn, ObjectName objectName)static StringgetAttributeName(Method method)static String[]getAttributeNames(MBeanAttributeInfo[] infos)Get a String[] of Attribute names.static AttributeListgetAttributesRobust(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, Set<ObjectName> objectNameSet)static String[]getKeyProperty(String key, ObjectName[] objectNames)static Set<String>getKeyPropertySet(String key, Set<ObjectName> objectNameSet)static MBeanAttributeInfogetMBeanAttributeInfo(MBeanAttributeInfo[] infos, String attrName)static MBeanAttributeInfogetMBeanAttributeInfo(MBeanInfo mbeanInfo, String attrName)static StringgetMBeanServerDelegateInfo(MBeanServer server)static MBeanServerDelegateMBeangetMBeanServerDelegateMBean(MBeanServerConnection server)static ObjectNamegetMBeanServerDelegateObjectName()static StringgetMBeanServerID(MBeanServerConnection conn)static StringgetProp(ObjectName objectName, String key)static StringgetProps(ObjectName objectName, Set<String> propKeys)static StringgetProps(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 StringimpactStr(int impact)static StringinterfaceName(MBeanInfo info)static MBeanInfointerfaceToMBeanInfo(Class theInterface)static booleanisGetAttribute(Method m)static booleanisGetAttributes(Method m)static booleanisGetter(Method method)Return true if the method is of the form isXyz() or getXyz() (no parameters)static booleanisGetter(MBeanOperationInfo info)static booleanisIs(Method method)static booleanisIsOrGetter(Method method)Return true if the method is of the form isXyz() or getXyz() (no parameters)static booleanisSetAttribute(Method m)static booleanisSetAttributes(Method m)static booleanisSetter(Method method)static voidlistenToMBeanServerDelegate(MBeanServerConnection conn, NotificationListener listener, NotificationFilter filter, Object handback)static StringmakeProp(String name, String value)static AttributeListmapToAttributeList(Map<String,Object> m)Convert an Map to an Attribute list where the keys are the Attribute names, and the values are objects.static StringmapToProps(Map<String,String> propsMap)static booleanmatchesPattern(String defaultDomain, ObjectName pattern, ObjectName candidate)static DescriptorSupportmergeDescriptors(Descriptor src, Descriptor dest)Merge two descriptors.static MBeanAttributeInfo[]mergeMBeanAttributeInfos(MBeanAttributeInfo[] infos1, MBeanAttributeInfo[] infos2)Merge two MBeanAttributeInfo[].static MBeanConstructorInfo[]mergeMBeanConstructorInfos(MBeanConstructorInfo[] infos1, MBeanConstructorInfo[] infos2)Merge two MBeanOperationInfo[].static MBeanNotificationInfo[]mergeMBeanNotificationInfos(MBeanNotificationInfo[] infos1, MBeanNotificationInfo[] infos2)Merge two MBeanNotificationInfo[].static MBeanOperationInfo[]mergeMBeanOperationInfos(MBeanOperationInfo[] infos1, MBeanOperationInfo[] infos2)Merge two MBeanOperationInfo[].static MBeanInfonewMBeanInfo(MBeanInfo origMBeanInfo, MBeanAttributeInfo[] newAttrInfos)Make a new MBeanInfo from an existing one, substituting MBeanAttributeInfo[]static MBeanInfonewMBeanInfo(MBeanInfo origMBeanInfo, MBeanOperationInfo[] newOps)Make a new MBeanInfo from an existing one, substituting MBeanOperationInfo[]static ObjectNamenewObjectName(String name)Create a new ObjectName, caller is guaranteeing that the name is well-formed (a RuntimeException will be thrown if not).static ObjectNamenewObjectName(String domain, String props)static ObjectNamenewObjectName(ObjectName objectName, String props)static ObjectNamenewObjectNamePattern(String domain, String props)Build an ObjectName pattern.static ObjectNamenewObjectNamePattern(String domain, Map<String,String> props)Build an ObjectName pattern.static <T> TnewProxyInstance(MBeanServerConnection conn, ObjectName objectName, Class<T> clazz)Create a new proxy supporting Notificationsstatic <T> TnewProxyInstance(MBeanServerConnection conn, ObjectName objectName, Class<T> clazz, boolean notificationBroadcaster)Type-safe; in JDK 5 generics aren't usedstatic ObjectName[]objectNameSetToArray(Set<ObjectName> objectNameSet)Convert a Set of ObjectName into an arraystatic Set<ObjectName>queryAllInDomain(MBeanServerConnection conn, String domain)static Set<ObjectName>queryAllInDomain(MBeanServer conn, String domain)static Set<ObjectName>queryLocalMBeans(MBeanServer conn, String domain, String server)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 <T extends MBeanFeatureInfo>
Tremove(List<T> infos, String name)static MBeanInforemoveAttributes(MBeanInfo origInfo, String[] attributeNames)static ObjectNameremoveProperty(ObjectName objectName, String key)static ObjectNamesetKeyProperty(ObjectName objectName, String key, String value)Change or add a key property in an ObjectName.static StringtoString(Descriptor d, int indent)static StringtoString(MBeanAttributeInfo info, int indent)static StringtoString(MBeanInfo info)Produce a nice friendly text dump of the MBeanInfo; the standard toString() is unreadable.static StringtoString(MBeanOperationInfo info, int indent)static StringtoString(ObjectName objectName)static voidunregisterAll(MBeanServerConnection conn)static voidunregisterAll(MBeanServerConnection conn, Set<ObjectName> allNames)
-
-
-
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
-
toString
public static String toString(ObjectName objectName)
-
getMBeanServerDelegateMBean
public static MBeanServerDelegateMBean getMBeanServerDelegateMBean(MBeanServerConnection server)
-
newProxyInstance
public static <T> T newProxyInstance(MBeanServerConnection conn, ObjectName objectName, Class<T> clazz)
Create a new proxy supporting NotificationsType-safe; in JDK 5 generics aren't used
-
newProxyInstance
public static <T> T newProxyInstance(MBeanServerConnection conn, ObjectName objectName, Class<T> clazz, boolean notificationBroadcaster)
Type-safe; in JDK 5 generics aren't used
-
getMBeanServerDelegateObjectName
public static ObjectName getMBeanServerDelegateObjectName()
-
getMBeanServerDelegateInfo
public static String getMBeanServerDelegateInfo(MBeanServer server)
-
listenToMBeanServerDelegate
public static void listenToMBeanServerDelegate(MBeanServerConnection conn, NotificationListener listener, NotificationFilter filter, Object handback) throws IOException, InstanceNotFoundException
- Throws:
IOExceptionInstanceNotFoundException
-
getMBeanServerID
public static String getMBeanServerID(MBeanServerConnection conn) 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 domainprops- properties of the ObjectName
-
newObjectNamePattern
public static ObjectName newObjectNamePattern(String domain, Map<String,String> props)
Build an ObjectName pattern.- Parameters:
domain- the JMX domainprops- properties of the ObjectName
-
removeProperty
public static ObjectName removeProperty(ObjectName objectName, String key)
-
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 ObjectNameobjectNames-- 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 ObjectNameobjectNameSet-- Returns:
- values from each ObjectName
-
getKeyPropertySet
public static Set<String> getKeyPropertySet(String key, Set<ObjectName> objectNameSet)
- Parameters:
key- the property name, within the ObjectNameobjectNameSet-- 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
-
unregisterAll
public static void unregisterAll(MBeanServerConnection conn) throws IOException, MalformedObjectNameException, MBeanRegistrationException
-
getAllAttributeNames
public static String[] getAllAttributeNames(MBeanServerConnection conn, ObjectName objectName) 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 infosattrName-
-
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:
IOExceptionReflectionExceptionIntrospectionExceptionInstanceNotFoundException
-
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- infosname- 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-
-
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 connecitonobjectName- name of the object to accessattrNames- attribute namesproblemNames- optional Set to which problem names will be added.- Returns:
- AttributeList
- Throws:
InstanceNotFoundExceptionIOException
-
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 Set<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)
-
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)
-
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-
-
mergeDescriptors
public static DescriptorSupport mergeDescriptors(Descriptor src, Descriptor dest)
Merge two descriptors. Values in 'src' override values in 'dest', but neither is modified, a new one is returned.
-
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-
-
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. IfparameterTypesis 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)
-
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
-
queryAllInDomain
public static Set<ObjectName> queryAllInDomain(MBeanServerConnection conn, String domain) throws IOException
- Throws:
IOException
-
queryAllInDomain
public static Set<ObjectName> queryAllInDomain(MBeanServer conn, String domain)
-
queryLocalMBeans
public static Set<ObjectName> queryLocalMBeans(MBeanServer conn, String domain, String server)
-
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 <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.
-
getAttribute
public static Object getAttribute(MBeanServerConnection conn, ObjectName o, String attrName)
convenience function to avoid try/catch. A RuntimeException is thrown if there is a problem
-
remove
public static <T extends MBeanFeatureInfo> T remove(List<T> infos, String name)
-
toString
public static String toString(Descriptor d, int indent)
-
impactStr
public static String impactStr(int impact)
-
toString
public static String toString(MBeanOperationInfo info, int indent)
-
toString
public static String toString(MBeanAttributeInfo info, int indent)
-
-