boolean worksOK = true;
final MBeanServerConnection conn = getMBeanServerConnection();
final MBeanInfo mbeanInfo = conn.getMBeanInfo( objectName );
assert( mbeanInfo != null );
final MBeanAttributeInfo[] attrInfos = mbeanInfo.getAttributes();
for( final MBeanAttributeInfo attrInfo : attrInfos )
{
try
{
final Object value = conn.getAttribute( objectName, attrInfo.getName() );
}
catch( Exception e )
{
final Throwable rootCause = ExceptionUtil.getRootCause( e );
warning( "MBean " + StringUtil.quote( objectName ) +
" threw an exception trying to get Attribute " +
StringUtil.quote( attrInfo.getName() ) + ": " + rootCause );
worksOK = false;
}
}
final String[] attrNames = JMXUtil.getAttributeNames( attrInfos );
try
{
// System.out.println( objectName + " {" + ArrayStringifier.stringify( attrNames, ", " ) + "}");
final AttributeList attrs = conn.getAttributes( objectName, attrNames );
assert( attrs.size() == attrInfos.length );
// verify that Attribute names match what was returned
final Set<String> attrNamesSet = GSetUtil.newSet( attrNames );
assert( attrNamesSet.size() == attrNames.length ); // should all be unique
final List<Attribute> typed = TypeCast.asList( attrs );
for( final Attribute attr : typed )
{
assert( attrNamesSet.contains( attr.getName() ) );
}
}
catch( Exception e )
{
final Throwable rootCause = ExceptionUtil.getRootCause( e );
warning( "MBean " + StringUtil.quote( objectName ) +
" threw an exception trying to get getAttributes(" +
ArrayStringifier.stringify( attrNames, ", " ) + "): " + rootCause );
worksOK = false;
}
return( worksOK );