Methods Summary |
---|
public void | checkAttributeTypes(javax.management.ObjectName objectName)Verify:
- that all Attributes are of standard types and Serializable
final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class);
final MBeanInfo info = Util.getExtra( proxy ).getMBeanInfo();
final MBeanAttributeInfo[] attributes = info.getAttributes();
boolean emittedName = false;
for( int i = 0; i < attributes.length; ++i )
{
final MBeanAttributeInfo attrInfo = attributes[ i ];
final String type = attrInfo.getType();
if ( ! isSuitableReturnTypeForAPI( type ) )
{
if ( ! emittedName )
{
emittedName = true;
}
if ( ! type.equals( CoverageInfo.class.getName() ) )
{
trace( "WARNING: unsuitable Attribute type in API: " +
type + " " + attrInfo.getName() + " in " + objectName );
}
}
}
|
private void | checkCompatibleOperationExists(javax.management.ObjectName objectName, java.lang.reflect.Method proxyMethod, java.lang.String mbeanMethodName, javax.management.MBeanInfo mbeanInfo)Verify that the proxy method has a compatible Attribute or operation.
- a proxy getter must have a corresponding Attribute returning an ObjectName
- a proxy operation must have a corresponding operation with matching signature
- a proxy operation must have a corresponding operation with compatible return type
final Class proxyReturnType = proxyMethod.getReturnType();
final String proxyMethodName = proxyMethod.getName();
String mbeanReturnType = null;
final Class[] parameterTypes = proxyMethod.getParameterTypes();
if ( JMXUtil.isGetter( proxyMethod ) )
{
// it's getter
final Map<String,MBeanAttributeInfo> m = JMXUtil.attributeInfosToMap( mbeanInfo.getAttributes() );
final String attrName = StringUtil.stripPrefix( mbeanMethodName, JMXUtil.GET );
final MBeanAttributeInfo attrInfo = (MBeanAttributeInfo)m.get( attrName );
if ( attrInfo != null )
{
mbeanReturnType = attrInfo.getType();
}
}
else
{
// look for an operation that matches
final MBeanOperationInfo[] operations = mbeanInfo.getOperations();
final String[] stringSig = ClassUtil.classnamesFromSignature( parameterTypes );
final MBeanOperationInfo opInfo = JMXUtil.findOperation( operations, mbeanMethodName, stringSig );
if ( opInfo != null )
{
mbeanReturnType = opInfo.getReturnType();
}
}
boolean hasPeer = mbeanReturnType != null;
if ( hasPeer )
{
// a proxy return type of AMX should have an Attribute type of ObjectName
if ( AMX.class.isAssignableFrom( proxyReturnType ) )
{
assert( mbeanReturnType.equals( ObjectName.class.getName() ) );
}
else // return types must match
{
assert( mbeanReturnType.equals( proxyReturnType.getName() ) );
}
hasPeer = true;
}
if( ! hasPeer )
{
trace( "MBean " + objectName + " has operation " + proxyMethodName +
" without corresponding peer Attribute/operation " + mbeanMethodName );
}
|
public void | checkContainerChild(java.lang.String childJ2EEType)Verify that each child's Container actually claims the child as a child.
final QueryMgr queryMgr = getQueryMgr();
final Set children = queryMgr.queryJ2EETypeSet( childJ2EEType );
final Iterator iter = children.iterator();
while ( iter.hasNext() )
{
final AMX containee = Util.asAMX(iter.next());
Container container = null;
final ObjectName objectName = Util.getObjectName( containee );
if ( ! shouldTest( objectName ) )
{
continue;
}
try
{
container = (Container)containee.getContainer();
}
catch( Exception e )
{
trace( "Can't get container for: " + objectName );
}
if ( container == null )
{
assert( containee.getJ2EEType().equals( XTypes.DOMAIN_ROOT ) ) :
"container is null for: " + objectName;
continue;
}
final Set<AMX> containeeSet = container.getContaineeSet( childJ2EEType );
final Set<ObjectName> containeeObjectNameSet = Util.toObjectNames( containeeSet );
assert( containeeObjectNameSet.contains( Util.getExtra( containee ).getObjectName() ) );
}
|
public void | checkContainerObjectName(javax.management.ObjectName objectName)Verify that the ObjectName returned from the ATTR_CONTAINER_OBJECT_NAME is the same
as the ObjectName obtained from the getContainer() proxy.
final ObjectName containerObjectName = (ObjectName)
getConnection().getAttribute( objectName, AMXAttributes.ATTR_CONTAINER_OBJECT_NAME );
if ( Util.getJ2EEType( objectName ).equals( XTypes.DOMAIN_ROOT ) )
{
assert( containerObjectName == null );
}
else
{
assert( containerObjectName != null );
final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class );
assert( Util.getObjectName( proxy.getContainer() ).equals( containerObjectName ) );
}
|
public void | checkCreateRemoveGet(javax.management.ObjectName objectName)Verify:
- each create() or createAbc() method ends in "Config" if it returns an AMXConfig subclass
- each remove() or removeAbc() method ends in "Config"
final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class );
if ( proxy instanceof Container )
{
final Method[] methods = getInterfaceClass( proxy ).getMethods();
final MBeanInfo mbeanInfo = Util.getExtra( proxy ).getMBeanInfo();
final MBeanOperationInfo[] operations = mbeanInfo.getOperations();
for( int methodIdx = 0; methodIdx < methods.length; ++methodIdx )
{
final Method method = methods[ methodIdx ];
final String methodName = method.getName();
if ( methodName.startsWith( "create" ) && ! methodName.endsWith( "Config" ) )
{
if ( AMXConfig.class.isAssignableFrom( method.getReturnType() ) &&
(! (proxy instanceof SecurityMapConfig)) )
{
trace( "WARNING: method " + methodName + " does not end in 'Config': " + objectName );
}
}
else if ( methodName.startsWith( "remove" ) &&
! methodName.endsWith( "Config" ) &&
proxy instanceof AMXConfig )
{
if ( //method.getReturnType() == Void.class &&
method.getParameterTypes().length == 1 &&
method.getParameterTypes()[ 0 ] == String.class &&
! method.getName().equals( "removeProperty" ) &&
! method.getName().equals( "removeSystemProperty" ) &&
(! (proxy instanceof SecurityMapConfig)) )
{
trace( "WARNING: method " + methodName + " does not end in 'Config': " + methodName );
}
}
}
}
|
public void | checkImplementsAMXConfig(javax.management.ObjectName objectName)Verify:
- if the interface name ends in "Config" or "ConfigMgr", then is is an AMXConfig
final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class );
final String interfaceName = Util.getExtra( proxy ).getInterfaceName();
if ( interfaceName.endsWith( "Config" ) || interfaceName.endsWith( "ConfigMgr" ) )
{
if ( !( proxy instanceof AMXConfig) )
{
trace( "WARNING: " + ClassUtil.stripPackageName( interfaceName ) + " does not implement AMXConfig" );
}
}
|
public void | checkInterface(javax.management.ObjectName src)Verify that the MBean has an ATTR_INTERFACE_NAME Attribute
final String interfaceName = (String)
getConnection().getAttribute( src, AMXAttributes.ATTR_INTERFACE_NAME );
assert( interfaceName != null );
|
public void | checkJ2EETypeAndName(javax.management.ObjectName src)Verify that the MBean has j2eeType and name.
assert( src.getKeyProperty( AMX.J2EE_TYPE_KEY ) != null );
assert( src.getKeyProperty( AMX.NAME_KEY ) != null );
|
public void | checkMaps(javax.management.ObjectName objectName)Verify that a proxy getAbcMap(...) Attribute or operation has an appropriate
MBean getAbcObjectNameMap() method.
final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class );
if ( proxy instanceof Container )
{
final Method[] methods = getInterfaceClass( proxy ).getMethods();
final MBeanInfo mbeanInfo = Util.getExtra( proxy ).getMBeanInfo();
for( int methodIdx = 0; methodIdx < methods.length; ++methodIdx )
{
final Method method = methods[ methodIdx ];
final String methodName = method.getName();
if ( isMapGetter( method ) )
{
if ( methodName.endsWith( OBJECTNAME_MAP_SUFFIX ) )
{
warning( "method should exist in MBeanInfo, not interface: " + methodName );
continue;
}
// verify that a corresponding peer method exists and
// has the right return type and same number and type of parameters
final String peerMethodName =
StringUtil.replaceSuffix( methodName, MAP_SUFFIX, OBJECTNAME_MAP_SUFFIX);
checkCompatibleOperationExists( Util.getObjectName( proxy ),
method,
peerMethodName,
mbeanInfo );
}
else if ( isMapGetterName( methodName ) )
{
warning( "operation " + methodName + " does not return a Map!" );
}
}
}
|
public void | checkMapsHaveCreateRemove(javax.management.ObjectName objectName)Verify that all getAbcConfigMgr() calls return a non-null result.
final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class );
if ( proxy instanceof Container && proxy.getGroup().equals( AMX.GROUP_CONFIGURATION ) )
{
final Extra extra = Util.getExtra( proxy );
final String[] attrNames = extra.getAttributeNames();
for( int i = 0; i < attrNames.length; ++i )
{
final String name = attrNames[ i ];
final String SUFFIX = "ObjectNameMap";
final String PREFIX = JMXUtil.GET;
if ( name.endsWith( SUFFIX ) )
{
final String base = StringUtil.stripPrefixAndSuffix( name, PREFIX, SUFFIX );
if ( base.endsWith( "ConnectorModuleConfig" ) )
{
// these are created via deployment not directly
continue;
}
final String createName = "create" + base;
final String removeName = "remove" + base;
final String j2eeType = proxy.getJ2EEType();
if ( ignoreCreateRemove( proxy.getJ2EEType(), createName ) )
{
continue;
}
final MBeanOperationInfo[] creates =
JMXUtil.findOperations( extra.getMBeanInfo().getOperations(), createName );
boolean haveCreate = false;
for( int op = 0; op < creates.length; ++op )
{
final MBeanOperationInfo info = creates[ op ];
if ( info.getReturnType().equals( ObjectName.class.getName() ) )
{
haveCreate = true;
break;
}
}
assert( haveCreate ) :
"Missing operation " + createName + "() for " + objectName;
final MBeanOperationInfo[] removes =
JMXUtil.findOperations( extra.getMBeanInfo().getOperations(), removeName );
boolean haveRemove = false;
for( int op = 0; op < removes.length; ++op )
{
final MBeanOperationInfo info = removes[ op ];
if ( info.getReturnType().equals( "void" ) &&
info.getSignature().length <= 2)
{
haveRemove = true;
break;
}
}
assert( haveRemove ) :
"Missing operation " + removeName + "() for " + objectName;
}
}
}
|
public void | checkNameMatchesJ2EEName(javax.management.ObjectName childObjectName)Verify that getName() is the same as the 'name' property in the ObjectName.
final AMX childProxy = getProxyFactory().getProxy( childObjectName, AMX.class);
if ( childProxy instanceof NamedConfigElement )
{
final String j2eeName = childProxy.getName();
assertEquals( j2eeName, childProxy.getName() );
}
|
public void | checkReturnTypes(javax.management.ObjectName objectName)Verify:
- that all return types are suitable for the API
final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class);
final MBeanInfo info = Util.getExtra( proxy ).getMBeanInfo();
final MBeanOperationInfo[] operations = info.getOperations();
boolean emittedName = false;
for( int i = 0; i < operations.length; ++i )
{
final MBeanOperationInfo opInfo = operations[ i ];
final String returnType = opInfo.getReturnType();
if ( ! isSuitableReturnTypeForAPI( returnType ) )
{
if ( ! emittedName )
{
emittedName = true;
trace( "\n" + objectName );
}
trace( "WARNING: unsuitable return type in API: " +
returnType + " " + opInfo.getName() + "(...)" );
}
}
|
public void | checkSelfObjectName(javax.management.ObjectName obj)Verify that the ObjectName returned from the MBean is in fact itself.
final ObjectName selfName = (ObjectName)
getConnection().getAttribute( obj, AMXAttributes.ATTR_OBJECT_NAME );
assert( selfName.equals( obj ) );
|
public void | checkTemplateAttributes(javax.management.ObjectName objectName)Look for Attributes that probably should be String and not int/long
due to our template facility ${...}
final AMX proxy = getProxyFactory().getProxy( objectName, AMX.class);
if ( proxy instanceof AMXConfig )
{
final AMXConfig config = (AMXConfig)proxy;
final Set<String> s = new HashSet<String>();
final MBeanInfo mbeanInfo = Util.getExtra( config ).getMBeanInfo();
final MBeanAttributeInfo[] attrInfos = mbeanInfo.getAttributes();
for( int i = 0; i < attrInfos.length; ++i )
{
final MBeanAttributeInfo info = attrInfos[ i ];
final String type = info.getType();
if ( type.equals( "int" ) || type.equals( "long" ) )
{
s.add( info.getName() );
}
}
if ( s.size() != 0 )
{
trace( "\n" + objectName +
" contains the following int/long Attributes which perhaps ought to be String" +
" due to the templatizing of config: " + toString( s ) + "\n" );
}
}
|
public static com.sun.enterprise.management.Capabilities | getCapabilities()
return getOfflineCapableCapabilities( true );
|
private boolean | ignoreCreateRemove(java.lang.String j2eeType, java.lang.String suggestedMethod)A few items supply Map of things, but have no corresponding create/remove routines.
boolean ignore = false;
if ( j2eeType.equals( XTypes.DOMAIN_CONFIG ) )
{
if ( suggestedMethod.equals( "createServerConfig" ) ||
suggestedMethod.equals( "createWebModuleConfig" ) ||
suggestedMethod.equals( "createEJBModuleConfig" ) ||
suggestedMethod.equals( "createJ2EEApplicationConfig" ) ||
suggestedMethod.equals( "createRARModuleConfig" ) ||
suggestedMethod.equals( "createAppClientModuleConfig" ) ||
suggestedMethod.equals( "createNodeAgentConfig" ) ||
false
)
{
ignore = true;
}
}
else if ( j2eeType.equals( XTypes.CLUSTERED_SERVER_CONFIG ) )
{
if ( suggestedMethod.equals( "createDeployedItemRefConfig" ) ||
suggestedMethod.equals( "createResourceRefConfig" )
)
{
ignore = true;
}
}
return( ignore );
|
private static boolean | isMapGetter(java.lang.reflect.Method method)
return( Map.class.isAssignableFrom( method.getReturnType() ) &&
isMapGetterName( method.getName() ) );
|
private static boolean | isMapGetterName(java.lang.String methodName)
return( methodName.startsWith( JMXUtil.GET ) &&
methodName.endsWith( MAP_SUFFIX ) );
|
private boolean | isSuitableReturnTypeForAPI(java.lang.String type)Verify that the type is suitable for the API. It must meet the following constraints
- that it is an OpenType or a standard Java type or a JMX type
- that it is Serializable or an interface
- or that it is an array whose elements meet the above constraints
- or that it is one of our specific Stats types
boolean isSuitable = SUITABLE_TYPES.contains( type );
if ( ! isSuitable )
{
final boolean isArray = ClassUtil.classnameIsArray( type );
if ( isArray ||
type.startsWith( "java." ) || type.startsWith( "javax.management." ) )
{
Class c = null;
try
{
c = ClassUtil.getClassFromName( type );
isSuitable = c.isInterface() || Serializable.class.isAssignableFrom( c ) ||
c == Object.class;
}
catch( ClassNotFoundException e )
{
trace( "WARNING: can't find class for type: " + type );
isSuitable = false;
}
if ( isArray )
{
final Class elementClass = ClassUtil.getArrayElementClass( c );
isSuitable = isSuitableReturnTypeForAPI( elementClass.getName() );
}
else if ( isSuitable &&
(! type.startsWith( "javax." )) &&
! c.isInterface() )
{
// insist on an interface except for those types explicit in SUITABLE_TYPES
isSuitable = false;
}
}
else if ( type.endsWith( "Stats" ) )
{
isSuitable = type.startsWith( "com.sun.appserv.management.monitor.statistics" ) ||
type.startsWith( "javax.management.j2ee.statistics" );
}
}
return( isSuitable );
|
public void | testAttributeTypes()
testAll( "checkAttributeTypes" );
|
public void | testContainerChild()Verify that all j2eeTypes have a proper Container that does actually hold them.
final TypeInfos infos = TypeInfos.getInstance();
final Set<String> j2eeTypesSet = infos.getJ2EETypes();
for( final String j2eeType : j2eeTypesSet )
{
checkContainerChild( j2eeType );
}
|
public void | testContainerObjectName()
testAll( "checkContainerObjectName" );
|
public void | testCreateRemoveGet()
testAll( "checkCreateRemoveGet" );
|
public void | testGetInterfaceName()
final Set<ObjectName> all = getQueryMgr().queryAllObjectNameSet();
final MBeanServerConnection conn =
Util.getExtra( getDomainRoot() ).getConnectionSource().getExistingMBeanServerConnection();
final Set<ObjectName> failedSet = new HashSet<ObjectName>();
for( final ObjectName objectName : all )
{
try
{
final String value = (String)
conn.getAttribute( objectName, AMXAttributes.ATTR_INTERFACE_NAME );
assert( value != null );
value.toString();
}
catch( AttributeNotFoundException e )
{
warning( "Can't get InterfaceName for: " + objectName );
failedSet.add( objectName );
}
}
if ( failedSet.size() != 0 )
{
warning( "The following MBeans did not return the Attribute InterfaceName:\n" +
CollectionUtil.toString( failedSet, "\n") );
assert( false );
throw new Error();
}
|
public void | testHaveJ2EE_TYPE()Statically verify that the interface for each proxy has a J2EE_TYPE field.
final TypeInfos infos = TypeInfos.getInstance();
final Set j2eeTypes = infos.getJ2EETypes();
boolean success = true;
final Iterator iter = j2eeTypes.iterator();
while ( iter.hasNext() )
{
final String j2eeType = (String)iter.next();
final TypeInfo info = infos.getInfo( j2eeType );
final Class theInterface = info.getInterface();
try
{
final String value =
(String)ClassUtil.getFieldValue( theInterface, "J2EE_TYPE" );
assert( value.equals( j2eeType ) ) :
"info and J2EE_TYPE don't match: " + j2eeType + " != " + value;
}
catch( Exception e )
{
trace( "no J2EE_TYPE field found for proxy of type: " + theInterface.getName() );
success = false;
}
}
assert( success );
|
public void | testImplementsAMXConfig()
testAll( "checkImplementsAMXConfig" );
|
public void | testImplementsAMXMonitoring()Verify:
- verify that if the interface name ends in "Monitor", then it is an AMX, Monitoring
- verify that if the interface name ends in "MonitorMgr", then it is an Container
final TypeInfos infos = TypeInfos.getInstance();
final Iterator iter = infos.getJ2EETypes().iterator();
while ( iter.hasNext() )
{
final TypeInfo info = infos.getInfo( (String)iter.next() );
final Class theInterface = info.getInterface();
final String interfaceName = theInterface.getName();
if ( ! MON_IGNORE.contains( theInterface ) )
{
if ( interfaceName.endsWith( "Monitor" ) )
{
if ( ! Monitoring.class.isAssignableFrom( theInterface ) )
{
warning( ClassUtil.stripPackageName( interfaceName ) + " does not implement Monitoring" );
}
}
else if ( interfaceName.endsWith( "MonitorMgr" ) )
{
if ( ! Container.class.isAssignableFrom( theInterface ) )
{
warning( ClassUtil.stripPackageName( interfaceName ) + " does not implement Container" );
}
}
}
}
|
public void | testInterface()
testAll( "checkInterface" );
|
public void | testInterfaceAgainstDelegate()
final long start = now();
final Set<AMX> all = getAllAMX();
final MBeanServerConnection conn = getMBeanServerConnection();
for( final AMX amx : all )
{
final String result = (String)
conn.invoke( Util.getObjectName( amx ),
"checkInterfaceAgainstDelegate", null, null );
}
printElapsed( "testInterfaceAgainstDelegate", all.size(), start );
|
public void | testJ2EETypeAndName()
testAll( "checkJ2EETypeAndName" );
|
public void | testMaps()
testAll( "checkMaps" );
|
public void | testMapsHaveCreateRemove()
testAll( "checkMapsHaveCreateRemove" );
|
public void | testMisc()
final long start = now();
final Set<AMX> all = getAllAMX();
for( final AMX amx : all )
{
amx.setMBeanLogLevel( amx.getMBeanLogLevel() );
final ObjectName objectName = Util.getObjectName( amx );
assert( objectName.getKeyProperty( AMX.NAME_KEY ) != null );
assert( objectName.getKeyProperty( AMX.J2EE_TYPE_KEY ) != null );
}
printElapsed( "testMisc", all.size(), start );
|
public void | testNameMatchesJ2EEName()
testAll( "checkNameMatchesJ2EEName" );
|
public void | testNoGoofyNames(javax.management.ObjectName objectName, javax.management.MBeanFeatureInfo[] featureInfos)
final Set<String> goofy = new HashSet<String>();
for( final MBeanFeatureInfo info : featureInfos )
{
final String name = info.getName();
if ( name.indexOf( "ObjectNameObjectName" ) >= 0 )
{
goofy.add( name );
}
}
if ( goofy.size() != 0 )
{
assert( false ) : NEWLINE +
"MBean " + objectName + " has the following goofy Attributes:" + NEWLINE +
CollectionUtil.toString( goofy, NEWLINE );
}
|
public void | testNoGoofyNames()
final long start = now();
final Set<AMX> all = getAllAMX();
for( final AMX amx : all )
{
final ObjectName objectName = Util.getObjectName( amx );
final MBeanInfo mbeanInfo = Util.getExtra( amx ).getMBeanInfo();
testNoGoofyNames( objectName, mbeanInfo.getAttributes() );
testNoGoofyNames( objectName, mbeanInfo.getOperations() );
}
printElapsed( "testNoGoofyNames", all.size(), start );
|
public void | testReturnTypes()
testAll( "checkReturnTypes" );
|
public void | testSelfObjectName()
testAll( "checkSelfObjectName" );
|
public void | testTemplateAttributes()
testAll( "checkTemplateAttributes" );
|
public void | testToString()
final long start = now();
final Set<AMX> all = getAllAMX();
for( final AMX amx : all )
{
final AMXDebugStuff debug = getTestUtil().asAMXDebugStuff( amx );
if ( debug != null )
{
final String s = debug.getImplString( true );
assert( s.length() != 0 );
}
}
printElapsed( "testToString", all.size(), start );
|