FileDocCategorySizeDatePackage
Util.javaAPI DocGlassfish v2 API14556Fri May 04 22:30:30 BST 2007com.sun.appserv.management.base

Util

public final class Util extends Object
Utility routines pertinent to the MBean API.

Fields Summary
private static final Set
PATTERN_PROPS
Minimal ObjectName properties required for an ObjectName pattern to uniquely identify an MBean. See {@link #getObjectNamePattern}.
Constructors Summary
private Util()

Methods Summary
public static com.sun.appserv.management.base.AMXasAMX(java.lang.Object o)
A safe way to cast to AMX.

        return AMX.class.cast( o );
    
public static java.lang.StringconcatenateProps(java.lang.String props1, java.lang.String props2)

		return( JMXUtil.concatenateProps( props1, props2 ) );
	
public static java.lang.StringconcatenateProps(java.lang.String props1, java.lang.String props2, java.lang.String props3)

		return( concatenateProps( concatenateProps( props1, props2), props3) );
	
public static java.util.MapcreateNameMap(java.util.Set amxs)
Create a Map keyed by the value of the AMX.NAME_KEY with value the AMX item.

param
amxs Set of AMX

		final Map<String,T>	m	= new HashMap<String,T>();
		
		for( final T amx : amxs )
		{
			final String	name	= amx.getName();
			m.put( name, amx );
		}
		
		return( m );
	
public static final java.util.MapcreateObjectNameMap(java.util.Set 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.

param
objectNames Set of ObjectName

		final Map<String,ObjectName>	m	= new HashMap<String,ObjectName>();
		
		for( final ObjectName objectName : objectNames )
		{
			final String		name	= getName( objectName );
			
			assert( ! m.containsKey( name ) ) :
				"createObjectNameMap: key already present: " + name + " in " + objectName;
			m.put( name, objectName );
		}
		
		assert( m.keySet().size() == objectNames.size() );
		
		return( Collections.checkedMap(m, String.class, ObjectName.class) );
	
public static java.util.MapgetAMXNotificationData(javax.management.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.

	    return Collections.unmodifiableMap(
	            JMXUtil.getUserDataMapString_Serializable( notif ) );
	
public static java.io.SerializablegetAMXNotificationValue(javax.management.Notification notif, java.lang.String key)
Use of generic type form taking Class is preferred.

		final Map<String,Serializable> data	=
		    getAMXNotificationData( notif );
		
		if ( data == null )
		{
			throw new IllegalArgumentException( notif.toString() );
		}
		
		if ( ! data.containsKey( key ) )
		{
			throw new IllegalArgumentException( "Value not found for " + key +
				" in " + notif );
		}
		
		return data.get( key );
	
public static TgetAMXNotificationValue(javax.management.Notification notif, java.lang.String key, java.lang.Class theClass)
Retrieve a particular value associated with the specified key from an AMX Notification.

see
#getAMXNotificationData

	    final Serializable value    = getAMXNotificationValue( notif, key );
		
		return theClass.cast( value );
	
public static ExtragetExtra(com.sun.appserv.management.base.AMX proxy)
Get extra information about this {@link AMX}. 'Extra' is not an MBean Attribute; it exists only in the {@link AMX}.

param
proxy an AMX

		return( (Extra)Proxy.getInvocationHandler( proxy ) );
	
public static java.lang.StringgetFullTypeProps(javax.management.ObjectName objectName, java.lang.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.

param
objectName
param
fullType
return
String of relevant ObjectName properties

		final String selfProp	= Util.getSelfProp( objectName );
			
		// now add properties for ancestors; skip the last type; it's
		// present in the j2eeType/name properties (selfProp)
		String	ancestorProps	= "";
		final String[]	types	= Util.getTypeArray( fullType );
		for( int i = 0; i < types.length - 1; ++i )
		{
			final String	key		= types[ i ];
			final String	value	= objectName.getKeyProperty( key );
			final String	prop	= Util.makeProp( key, value );
			
			ancestorProps	= Util.concatenateProps( ancestorProps, prop );
		}
		
		final String	props	= Util.concatenateProps( selfProp, ancestorProps );
		
		return( props );
	
public static java.lang.StringgetJ2EEType(javax.management.ObjectName objectName)

		return( objectName.getKeyProperty( AMX.J2EE_TYPE_KEY )  );
	
public static java.lang.StringgetName(javax.management.ObjectName objectName)
Get the value of the AMX.NAME_KEY property within the ObjectName or AMX.NO_NAME if not present.

return
the name

		String	name	= objectName.getKeyProperty( AMX.NAME_KEY );
		
		if ( name == null )
		{
			name	= AMX.NO_NAME;
		}

		return( name  );
	
public static java.util.SetgetNames(java.util.Set amxs)
Extract the names from all ObjectNames. The name is the value of the property NAME_KEY (See {@link AMX}). Note that if two or more ObjectNames share the same name, the resulting Set will be of smaller size() than the original.

return
Set

		return getNamesSet( Util.toObjectNames( amxs ) );
	
public static java.lang.String[]getNamesArray(java.util.Set objectNames)
Extract the names from all ObjectNames.

return
String[] of names from the ObjectNames

		return( JMXUtil.getKeyProperty( AMX.NAME_KEY, objectNames ) );
	
public static java.util.SetgetNamesSet(java.util.Set objectNames)
Extract the names from all ObjectNames. The name is the value of the property NAME_KEY (See {@link AMX}). Note that if two or more ObjectNames share the same name, the resulting Set will be of smaller size() than the original.

return
Set

		return TypeCast.checkedStringSet(
		        JMXUtil.getKeyPropertySet( AMX.NAME_KEY, objectNames ) );
	
public static javax.management.ObjectNamegetObjectName(T proxy)
Get the ObjectName targeted by this {@link AMX}.

param
proxy an AMX

		return( getExtra( proxy ).getObjectName() );
	
public static javax.management.ObjectNamegetObjectName(java.util.Map candidates, java.lang.String name)
Get an ObjectName from a Map of ObjectName where the values are keyed by name.

param
candidates
param
name
return
ObjectName
throws
IllegalArgumentException if not found

		final Object	item	= candidates.get( name );
		if ( item == null )
		{
			throw new IllegalArgumentException( "Not found: " + name );
		}
		
		return (ObjectName)item;
	
public static java.util.SetgetPatternKeys(java.lang.String fullType)
Get all keys required for an ObjectName pattern which uniquely identifies the MBean.



			         		  	 
		  
	
		 		 
	
		final Set<String> requiredKeys	= GSetUtil.copySet( PATTERN_PROPS );
		
		// omit the last one, it is the simple type of this MBean, which we've
		// already included
		final String[]	types	= Util.getTypeArray( fullType );
		for( int i = 0; i < types.length - 1; ++i )
		{
			requiredKeys.add( types[ i ] );
		}

		return TypeCast.checkedStringSet( requiredKeys  );
	
public static java.lang.StringgetSelfProp(javax.management.ObjectName objectName)
Extract the j2eeType and name properties and return it as a single property j2eeType=name

param
objectName

		final String	j2eeType	= objectName.getKeyProperty( AMX.J2EE_TYPE_KEY );
		final String	name		= objectName.getKeyProperty( AMX.NAME_KEY );
		
		return( Util.makeProp( j2eeType, name ) );
	
public static java.lang.String[]getTypeArray(java.lang.String fullType)
Get the FullType as a String[], last element being the j2eeType.

param
fullType as returned from {@link AMX#getFullType}

		if ( fullType == null )
		{
			throw new IllegalArgumentException();
		}
		
		assert( AMX.FULL_TYPE_DELIM.equals( "." ) );
		return( fullType.split( "\\." )  );
	
public static java.lang.StringmakeJ2EETypeProp(java.lang.String value)
Make an ObjectName property of the form j2eeType=value.

param
value

		return( makeProp( AMX.J2EE_TYPE_KEY, value ) );
	
public static java.lang.StringmakeNameProp(java.lang.String value)
Make an ObjectName property of the form name=value.

param
value

		return( makeProp( AMX.NAME_KEY, value ) );
	
public static java.lang.StringmakeProp(java.lang.String name, java.lang.String value)
Make an ObjectName property of the form name=value.

param
name
param
value

		return( JMXUtil.makeProp( name, value ) );
	
public static java.lang.StringmakeRequiredProps(java.lang.String j2eeType, java.lang.String name)

param
j2eeType
param
name

		final String	j2eeTypeProp	= Util.makeJ2EETypeProp( j2eeType );
		final String	nameProp		= Util.makeNameProp( name );
		
		final String	props	= Util.concatenateProps( j2eeTypeProp, nameProp );
		
		return( props );
	
public static javax.management.ObjectNamenewObjectName(java.lang.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.

param
name

		return( JMXUtil.newObjectName( name ) );
	
public static javax.management.ObjectNamenewObjectName(java.lang.String domain, java.lang.String props)
Build an ObjectName. Calls newObjectName( domain + ":" + props )

param
domain the JMX domain
param
props properties of the ObjectName

		return( newObjectName( domain + ":" + props ) );
	
public static javax.management.ObjectNamenewObjectNamePattern(java.lang.String domain, java.lang.String props)
Build an ObjectName pattern.

param
domain the JMX domain
param
props properties of the ObjectName

		return( JMXUtil.newObjectNamePattern( domain, props ) );
	
public static javax.management.ObjectNamenewObjectNamePattern(javax.management.ObjectName objectName)
Build an ObjectName pattern.

param
objectName

		final String	props	= objectName.getKeyPropertyListString();
		
		return( newObjectNamePattern( objectName.getDomain(), props) );
	
public static voidsleep(long millis)

		try
		{
			Thread.sleep( millis );
		}
		catch( InterruptedException e )
		{
		}
	
public static java.util.SettoObjectNames(java.util.Set amxs)

return
a Set of ObjectNames from a Set of AMX.

		final Set<ObjectName>	objectNames	= new HashSet<ObjectName>();
		for( final AMX next : amxs )
		{
			objectNames.add( getObjectName( next ) );
		}
		return( Collections.checkedSet(objectNames, ObjectName.class) );
	
public static java.util.MaptoObjectNames(java.util.Map amxMap)

return
a Map of ObjectNames from a Map whose values are AMX.

		final Map<String,ObjectName>	m	= new HashMap<String,ObjectName>();
		
		for( final String key : amxMap.keySet() )
		{
			final AMX	value	= amxMap.get( key );
			m.put( key, getExtra( value ).getObjectName() );
		}
		return( Collections.checkedMap( m, String.class, ObjectName.class) );
	
public static javax.management.ObjectName[]toObjectNames(com.sun.appserv.management.base.AMX[] amx)

return
an ObjectName[] from an AMX[]

		final ObjectName[]	objectNames	= new ObjectName[ amx.length ];
		for( int i = 0; i < objectNames.length; ++i )
		{
			objectNames[ i ]	= amx[ i ] == null ? null : getExtra( amx[ i ] ).getObjectName();
		}
		
		return( objectNames );