com.sun.appserv.management.base
Class Util

java.lang.Object
  extended by com.sun.appserv.management.base.Util

public final class Util
extends Object

Utility routines pertinent to the MBean API.


Method Summary
static AMX asAMX(Object o)
          A safe way to cast to AMX.
static String concatenateProps(String props1, String props2)
           
static String concatenateProps(String props1, String props2, String props3)
           
static
<T extends AMX>
Map<String,T>
createNameMap(Set<T> amxs)
          Create a Map keyed by the value of the AMX.NAME_KEY with value the AMX item.
static Map<String,ObjectName> createObjectNameMap(Set<ObjectName> objectNames)
          Create a Map keyed by the value of the AMX.NAME_KEY with value the ObjectName.
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 Class is preferred.
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.
static Extra getExtra(AMX proxy)
          Get extra information about this AMX.
static String getFullTypeProps(ObjectName objectName, String fullType)
          Get properties corresponding to the FullType of this ObjectName.
static String getJ2EEType(ObjectName objectName)
           
static String getName(ObjectName objectName)
          Get the value of the AMX.NAME_KEY property within the ObjectName or AMX.NO_NAME if not present.
static Set<String> getNames(Set<? extends AMX> amxs)
          Extract the names from all ObjectNames.
static String[] getNamesArray(Set<ObjectName> objectNames)
          Extract the names from all ObjectNames.
static Set<String> getNamesSet(Set<ObjectName> objectNames)
          Extract the names from all ObjectNames.
static ObjectName getObjectName(Map<String,ObjectName> candidates, String name)
          Get an ObjectName from a Map of ObjectName where the values are keyed by name.
static
<T extends AMX>
ObjectName
getObjectName(T proxy)
          Get the ObjectName targeted by this AMX.
static Set<String> getPatternKeys(String fullType)
          Get all keys required for an ObjectName pattern which uniquely identifies the MBean.
static String getSelfProp(ObjectName objectName)
          Extract the j2eeType and name properties and return it as a single property j2eeType=name
static String[] getTypeArray(String fullType)
          Get the FullType as a String[], last element being the j2eeType.
static String makeJ2EETypeProp(String value)
          Make an ObjectName property of the form j2eeType=value.
static String makeNameProp(String value)
          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 j2eeType, String name)
           
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(ObjectName objectName)
          Build an ObjectName pattern.
static ObjectName newObjectNamePattern(String domain, String props)
          Build an ObjectName pattern.
static void sleep(long millis)
           
static ObjectName[] toObjectNames(AMX[] amx)
           
static Map<String,ObjectName> toObjectNames(Map<String,? extends AMX> amxMap)
           
static Set<ObjectName> toObjectNames(Set<? extends AMX> amxs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 domain
props - properties of the ObjectName

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(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 -

makeJ2EETypeProp

public static String makeJ2EETypeProp(String value)
Make an ObjectName property of the form j2eeType=value.

Parameters:
value -

makeNameProp

public static String makeNameProp(String value)
Make an ObjectName property of the form name=value.

Parameters:
value -

makeRequiredProps

public static String makeRequiredProps(String j2eeType,
                                       String name)
Parameters:
j2eeType -
name -

getSelfProp

public static String getSelfProp(ObjectName objectName)
Extract the j2eeType and name properties and return it as a single property j2eeType=name

Parameters:
objectName -

getFullTypeProps

public static String getFullTypeProps(ObjectName objectName,
                                      String fullType)
Get properties corresponding to the FullType of this ObjectName. Its j2eeType/name are included as j2eeType=name, not as j2eeType=j2eeType,name=name.

Parameters:
objectName -
fullType -
Returns:
String of relevant ObjectName properties

getName

public static String getName(ObjectName objectName)
Get the value of the AMX.NAME_KEY property within the ObjectName or AMX.NO_NAME if not present.

Returns:
the name

getJ2EEType

public static String getJ2EEType(ObjectName objectName)

getTypeArray

public static String[] getTypeArray(String fullType)
Get the FullType as a String[], last element being the j2eeType.

Parameters:
fullType - as returned from AMX.getFullType()

getPatternKeys

public static Set<String> getPatternKeys(String fullType)
Get all keys required for an ObjectName pattern which uniquely identifies the MBean.


concatenateProps

public static String concatenateProps(String props1,
                                      String props2)

concatenateProps

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

toObjectNames

public static Set<ObjectName> toObjectNames(Set<? extends AMX> amxs)
Returns:
a Set of ObjectNames from a Set of AMX.

toObjectNames

public static Map<String,ObjectName> toObjectNames(Map<String,? extends AMX> amxMap)
Returns:
a Map of ObjectNames from a Map whose values are AMX.

toObjectNames

public static ObjectName[] toObjectNames(AMX[] amx)
Returns:
an ObjectName[] from an AMX[]

getNames

public static Set<String> getNames(Set<? extends AMX> amxs)
Extract the names from all ObjectNames. The name is the value of the property NAME_KEY (See AMX). Note that if two or more ObjectNames share the same name, the resulting Set will be of smaller size() than the original.

Returns:
Set

getNamesSet

public static Set<String> getNamesSet(Set<ObjectName> objectNames)
Extract the names from all ObjectNames. The name is the value of the property NAME_KEY (See AMX). Note that if two or more ObjectNames share the same name, the resulting Set will be of smaller size() than the original.

Returns:
Set

getNamesArray

public static String[] getNamesArray(Set<ObjectName> objectNames)
Extract the names from all ObjectNames.

Returns:
String[] of names from the ObjectNames

createObjectNameMap

public static final Map<String,ObjectName> createObjectNameMap(Set<ObjectName> objectNames)
Create a Map keyed by the value of the AMX.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

createNameMap

public static <T extends AMX> Map<String,T> createNameMap(Set<T> amxs)
Create a Map keyed by the value of the AMX.NAME_KEY with value the AMX item.

Parameters:
amxs - Set of AMX

getExtra

public static Extra getExtra(AMX proxy)
Get extra information about this AMX. 'Extra' is not an MBean Attribute; it exists only in the AMX.

Parameters:
proxy - an AMX

getObjectName

public static <T extends AMX> ObjectName getObjectName(T proxy)
Get the ObjectName targeted by this AMX.

Parameters:
proxy - an AMX

getObjectName

public static ObjectName getObjectName(Map<String,ObjectName> candidates,
                                       String name)
Get an ObjectName from a Map of ObjectName where the values are keyed by name.

Parameters:
candidates -
name -
Returns:
ObjectName
Throws:
IllegalArgumentException - if not found

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 Class is 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.

See Also:
getAMXNotificationData(javax.management.Notification)

sleep

public static void sleep(long millis)

asAMX

public static AMX asAMX(Object o)
A safe way to cast to AMX.