Package org.glassfish.admin.amx.core
Class Util
- java.lang.Object
-
- org.glassfish.admin.amx.core.Util
-
@Taxonomy(stability=UNCOMMITTED) public final class Util extends Object
Utility routines pertinent to the MBean API.
-
-
Field Summary
Fields Modifier and Type Field Description static String
TYPE_FIELD
Proxy interfaces may contain a type field denoting the type to be used in the ObjectName; this is an alternative to an annotation that may be desirable to avoid a dependency on the amx-core module.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AMXProxy
asAMX(Object o)
A safe way to cast to AMX.static <T extends AMXProxy>
List<T>asProxyList(Collection<? extends AMXProxy> c, Class<T> intf)
static String
concatenateProps(String props1, String props2)
static String
concatenateProps(String props1, String props2, String props3)
static <T extends AMXProxy>
Map<String,T>createNameMap(Set<T> amxs)
Create a Map keyed by the value of the NAME_KEY with value the AMX item.static Map<String,ObjectName>
createObjectNameMap(Set<ObjectName> objectNames)
Create a Map keyed by the value of the NAME_KEY with value the ObjectName.static String
deduceType(Class<?> intf)
Deduce the type to be used in the path.static <T extends AMXProxy>
Map<String,T>filterAMX(Map<String,T> candidates, Class<?> desired)
Filter the AMX dynamic proxies to those that implement the specified interface, and return a new Map with the matching items.static <T extends AMXProxy>
Set<T>filterAMX(Set<T> candidates, Class<?> desired)
Filter the AMX dynamic proxies to those that implement the specified interface, and return a new Set with the matching items.static Map<String,ObjectName>
filterByType(ObjectName[] objectNames, String type)
static String
getAdditionalProps(ObjectName objectName)
Extract all properties other than type=,name= . static Map<String,Serializable>
getAMXNotificationData(Notification notif)
All Notifications emitted by AMX MBeans which are not standard types defined by JMX place a Map into the userData field of the Notification.static Serializable
getAMXNotificationValue(Notification notif, String key)
Use of generic type form taking Classis preferred. static <T extends Serializable>
TgetAMXNotificationValue(Notification notif, String key, Class<T> theClass)
Retrieve a particular value associated with the specified key from an AMX Notification.static ObjectName
getAncestorByType(MBeanServer mbeanServer, ObjectName child, String type)
static String
getNameProp(ObjectName objectName)
Get the value of the NAME_KEY property within the ObjectName, or null if not present.static ObjectName
getParent(MBeanServer server, ObjectName objectName)
static String
getParentPathProp(ObjectName objectName)
static String
getParentPathProp(AMXProxy amx)
static String
getSelfProp(ObjectName objectName)
Extract the type and name properties and return it as a single property type=namestatic String
getTypeProp(ObjectName objectName)
static String
makeNameProp(String name)
Make an ObjectName property of the form name=value.static String
makeProp(String name, String value)
Make an ObjectName property of the form name=value.static String
makeRequiredProps(String type, String name)
static String
makeTypeProp(String value)
Make an ObjectName property of the form type=value.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)
Build an ObjectName.static ObjectName
newObjectNamePattern(String domain, String props)
Build an ObjectName pattern.static ObjectName
newObjectNamePattern(ObjectName objectName)
Build an ObjectName pattern.static String
quoteIfNeeded(String name)
static List<ObjectName>
toObjectNameList(Collection<? extends AMXProxy> amxs)
static Map<String,ObjectName>
toObjectNameMap(Map<String,? extends AMXProxy> amxMap)
static ObjectName[]
toObjectNamesArray(Collection<? extends AMXProxy> amxs)
static ObjectName[]
toObjectNamesArray(AMXProxy[] amx)
static String
typeFromName(String s)
Generate the default MBean type from a String, eg from a classname.static String
unquoteIfNeeded(String name)
-
-
-
Field Detail
-
TYPE_FIELD
public static final String TYPE_FIELD
Proxy interfaces may contain a type field denoting the type to be used in the ObjectName; this is an alternative to an annotation that may be desirable to avoid a dependency on the amx-core module. Some proxy interfaces also represent MBeans whose type and other metadata is derived not from the proxy interface, but from another authoritative source; this allows an explicit linkage that allows the AMXProxyHandler to deduce the correct type, given the interface (and avoids any further complexity, the KISS principle). eg public static final String AMX_TYPE = "MyType";A good example of this is the config MBeans which use lower case types with dashes. Other types may use classnames, or other variants; the proxy code can't assume any particular mapping from a proxy interface to the actual MBean type.
- See Also:
- Constant Field Values
-
-
Method Detail
-
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.
NOTE: Do not call this method if there is not certainty of a well-formed name.- Parameters:
name
-
-
newObjectName
public static ObjectName newObjectName(String domain, String props)
Build an ObjectName. Calls newObjectName( domain + ":" + props )- Parameters:
domain
- the JMX domainprops
- properties of the ObjectName
-
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(ObjectName objectName)
Build an ObjectName pattern.- Parameters:
objectName
-
-
makeProp
public static String makeProp(String name, String value)
Make an ObjectName property of the form name=value.- Parameters:
name
-value
-
-
makeTypeProp
public static String makeTypeProp(String value)
Make an ObjectName property of the form type=value.- Parameters:
value
-
-
makeNameProp
public static String makeNameProp(String name)
Make an ObjectName property of the form name=value.
-
makeRequiredProps
public static String makeRequiredProps(String type, String name)
- Parameters:
type
-name
-
-
getSelfProp
public static String getSelfProp(ObjectName objectName)
Extract the type and name properties and return it as a single property type=name- Parameters:
objectName
-
-
getAdditionalProps
public static String getAdditionalProps(ObjectName objectName)
Extract all properties other than type=,name= . - Parameters:
objectName
-
-
concatenateProps
public static String concatenateProps(String props1, String props2, String props3)
-
toObjectNameList
public static List<ObjectName> toObjectNameList(Collection<? extends AMXProxy> amxs)
- Returns:
- a List of ObjectNames from a Set of AMX.
-
toObjectNameMap
public static Map<String,ObjectName> toObjectNameMap(Map<String,? extends AMXProxy> amxMap)
- Returns:
- a Map of ObjectNames from a Map whose values are AMX.
-
toObjectNamesArray
public static ObjectName[] toObjectNamesArray(AMXProxy[] amx)
- Returns:
- an ObjectName[] from an AMX[]
-
toObjectNamesArray
public static ObjectName[] toObjectNamesArray(Collection<? extends AMXProxy> amxs)
-
createNameMap
public static <T extends AMXProxy> Map<String,T> createNameMap(Set<T> amxs)
Create a Map keyed by the value of the NAME_KEY with value the AMX item.- Parameters:
amxs
- Set of AMX
-
createObjectNameMap
public static final Map<String,ObjectName> createObjectNameMap(Set<ObjectName> objectNames)
Create a Map keyed by the value of the NAME_KEY with value the ObjectName. Note that if two or more ObjectNames share the same name, the resulting Map will contain only one of the original ObjectNames.- Parameters:
objectNames
- Set of ObjectName
-
asProxyList
public static <T extends AMXProxy> List<T> asProxyList(Collection<? extends AMXProxy> c, Class<T> intf)
-
getAMXNotificationData
public static Map<String,Serializable> getAMXNotificationData(Notification notif)
All Notifications emitted by AMX MBeans which are not standard types defined by JMX place a Map into the userData field of the Notification. This call retrieves that Map, which may be null if no additional data is included.
-
getAMXNotificationValue
public static Serializable getAMXNotificationValue(Notification notif, String key)
Use of generic type form taking Classis preferred.
-
getAMXNotificationValue
public static <T extends Serializable> T getAMXNotificationValue(Notification notif, String key, Class<T> theClass)
Retrieve a particular value associated with the specified key from an AMX Notification.
-
filterAMX
public static <T extends AMXProxy> Set<T> filterAMX(Set<T> candidates, Class<?> desired)
Filter the AMX dynamic proxies to those that implement the specified interface, and return a new Set with the matching items. The 'desired' interface can be any AMX-defined class, including the mixin ones.- Parameters:
candidates
- the Set to be filtereddesired
- the interface to filter by
-
filterByType
public static Map<String,ObjectName> filterByType(ObjectName[] objectNames, String type)
-
filterAMX
public static <T extends AMXProxy> Map<String,T> filterAMX(Map<String,T> candidates, Class<?> desired)
Filter the AMX dynamic proxies to those that implement the specified interface, and return a new Map with the matching items. The 'desired' interface can be any AMX-defined class, including the mixin ones.- Parameters:
candidates
- the Map to be filtereddesired
- the interface to filter by
-
getTypeProp
public static String getTypeProp(ObjectName objectName)
-
getNameProp
public static String getNameProp(ObjectName objectName)
Get the value of the NAME_KEY property within the ObjectName, or null if not present.- Returns:
- the name
-
getParentPathProp
public static String getParentPathProp(ObjectName objectName)
-
getParent
public static ObjectName getParent(MBeanServer server, ObjectName objectName)
-
typeFromName
public static String typeFromName(String s)
Generate the default MBean type from a String, eg from a classname.
-
deduceType
public static String deduceType(Class<?> intf)
Deduce the type to be used in the path. Presence of a TYPE_FIELD field always take precedence, then the AMXMBeanMetadata.
-
getAncestorByType
public static ObjectName getAncestorByType(MBeanServer mbeanServer, ObjectName child, String type)
-
-