Methods Summary |
---|
public void | attributeGetFailure(java.lang.String name)
Integer count = mAttributeGetFailures.get( name );
count = Integer.valueOf(count == null ? 1
: 1 + count.intValue());
mAttributeGetFailures.put( name, count );
|
public void | attributeSetFailure(java.lang.String name)
Integer count = mAttributeSetFailures.get( name );
count = Integer.valueOf(count == null ? 1
: 1 + count.intValue());
mAttributeSetFailures.put( name, count );
|
public void | attributeWasRead(java.lang.String name)
if ( mLegalReadableAttributes.contains( name ) )
{
mAttributesRead.add( name );
}
else
{
unknownAttribute( name );
}
|
public void | attributeWasWritten(java.lang.String name)
if ( mLegalWriteableAttributes.contains( name ) )
{
mAttributesWritten.add( name );
}
else
{
unknownAttribute( name );
}
|
public void | attributesWereRead(java.lang.String[] names)
for( final String name : names )
{
attributeWasRead( name );
}
|
private void | checkHaveMBeanInfo()
if ( getMBeanInfo() == null )
{
throw new IllegalArgumentException(
"MBeanInfo must be set using setMBeanInfo() prior to call" );
}
|
public void | clear()
mAttributesRead.clear();
mAttributesWritten.clear();
mOperationsInvoked.clear();
mAttributeGetFailures.clear();
mAttributeSetFailures.clear();
mUnknownAttributes.clear();
mUnknownOperations.clear();
mInvocationFailures.clear();
|
public java.util.Map | getAttributeGetFailures()
return new HashMap<String,Integer>( mAttributeGetFailures );
|
public int | getAttributeReadCoverage()
return percent( mAttributesRead.size(), mLegalReadableAttributes.size() );
|
public java.util.Map | getAttributeSetFailures()
return new HashMap<String,Integer>( mAttributeSetFailures );
|
public int | getAttributeWriteCoverage()
return percent( mAttributesWritten.size(), getNumWriteableAttributes() );
|
public java.util.Set | getAttributesNotRead()
checkHaveMBeanInfo();
// remove all Attributes which were written from the legal set
final Set<String> notRead = new HashSet<String>( mLegalReadableAttributes );
notRead.removeAll( mAttributesRead );
return notRead;
|
public java.util.Set | getAttributesNotWritten()
checkHaveMBeanInfo();
// remove all Attributes which were read from the legal set
final Set<String> notWritten = new HashSet<String>( mLegalWriteableAttributes );
notWritten.removeAll( mAttributesWritten );
return notWritten;
|
public java.util.Set | getAttributesRead()
return new HashSet<String>( mAttributesRead );
|
public java.util.Set | getAttributesWritten()
return new HashSet<String>( mAttributesWritten );
|
public boolean | getFullCoverage()
return getAttributeReadCoverage() == 100 &&
getAttributeWriteCoverage() == 100 &&
getOperationCoverage() == 100;
|
private java.lang.String | getFullOperationName(java.lang.String name, java.lang.String[] sig)
final String sigString = StringUtil.toString( ",", sig == null ? EMPTY_SIG : sig );
final String s = name + "(" + sigString + ")";
return s;
|
public java.util.Map | getInvocationFailures()
return new HashMap<String,Integer>( mInvocationFailures );
|
public javax.management.MBeanInfo | getMBeanInfo()
return mMBeanInfo;
|
public int | getNumOperations()
return mLegalOperations.size();
|
public int | getNumReadableAttributes()
checkHaveMBeanInfo();
return mLegalReadableAttributes.size();
|
public int | getNumWriteableAttributes()
checkHaveMBeanInfo();
return mLegalWriteableAttributes.size();
|
public int | getOperationCoverage()
checkHaveMBeanInfo();
final int numOperations = mLegalOperations.size();
// do it this way; some illegal operations get invoked, too
final Set<String> remaining = new HashSet<String>( mLegalOperations );
for( final String invoked : mOperationsInvoked )
{
remaining.remove( invoked );
}
final int numInvoked = numOperations - remaining.size();
return percent( numInvoked, numOperations );
|
public java.util.Set | getOperations()
return mLegalOperations;
|
public java.util.Set | getOperationsInvoked()
return new HashSet<String>( mOperationsInvoked );
|
public java.util.Set | getOperationsNotInvoked()
checkHaveMBeanInfo();
// remove all Attributes which were read from the legal set
final Set<String> notInvoked = new HashSet<String>( mLegalOperations );
notInvoked.removeAll( getOperationsInvoked() );
return notInvoked;
|
public java.util.Set | getReadableAttributes()
return mLegalReadableAttributes;
|
public java.util.Map | getUnknownAttributes()
return new HashMap<String,Integer>( mUnknownAttributes );
|
public java.util.Map | getUnknownOperations()
return new HashMap<String,Integer>( mUnknownOperations );
|
public java.util.Set | getWriteableAttributes()
return mLegalWriteableAttributes;
|
public void | ignoreUnknownAttribute(java.lang.String name)
mUnknownAttributes.remove( name );
mAttributeGetFailures.remove( name );
mAttributeSetFailures.remove( name );
|
public void | markAsInvoked(java.lang.String fullName)
if ( (! fullName.endsWith( ")" )) || fullName.indexOf( "(" ) < 0 )
{
throw new IllegalArgumentException( fullName );
}
mOperationsInvoked.add( fullName );
|
public void | merge(CoverageInfo info)
mAttributesRead.addAll( info.getAttributesRead() );
mAttributesWritten.addAll( info.getAttributesWritten() );
mOperationsInvoked.addAll( info.getOperationsInvoked() );
mergeCounts( info.getAttributeGetFailures(), mAttributeGetFailures );
mergeCounts( info.getAttributeSetFailures(), mAttributeSetFailures );
mergeCounts( info.getUnknownAttributes(), mUnknownAttributes );
mergeCounts( info.getUnknownOperations(), mUnknownOperations );
mergeCounts( info.getInvocationFailures(), mInvocationFailures );
|
private void | mergeCounts(java.util.Map src, java.util.Map dest)
for( final String key : src.keySet() )
{
final Integer srcValue = src.get( key );
final Integer destValue = dest.get( key );
final int sum = srcValue.intValue() +
(destValue == null ? 0 : destValue.intValue());
dest.put(key, Integer.valueOf(sum));
}
|
public void | operationFailed(java.lang.String name, java.lang.String[] sig)
final String fullName = getFullOperationName( name, sig );
if ( ! getOperations().contains( fullName ) )
{
throw new IllegalArgumentException( fullName );
}
Integer count = mInvocationFailures.get( name );
count = Integer.valueOf(count == null ? 1
: 1 + count.intValue());
mInvocationFailures.put( fullName, count );
|
public void | operationWasInvoked(java.lang.String name, java.lang.String[] sig)
final String fullName = getFullOperationName( name, sig );
if ( mLegalOperations.contains( fullName ) )
{
mOperationsInvoked.add( fullName );
}
else
{
unknownOperation( fullName, sig );
assert( ! mOperationsInvoked.contains( fullName ) );
}
|
private int | percent(int numerator, int denominator)
return (int)((((float)numerator / (float)denominator))*100.0);
|
private void | sdebug(java.lang.Object o)
System.out.println( "" + o );
|
public void | setMBeanInfo(javax.management.MBeanInfo mbeanInfo)
mLegalOperations = new HashSet<String>();
mLegalReadableAttributes = new HashSet<String>();
mLegalWriteableAttributes = new HashSet<String>();
if ( mbeanInfo != null ) try
{
final MBeanOperationInfo[] ops = mbeanInfo.getOperations();
for( final MBeanOperationInfo opInfo : ops )
{
final String[] sig = JMXUtil.getSignature( opInfo.getSignature() );
final String fullName =
getFullOperationName( opInfo.getName(), sig );
mLegalOperations.add( fullName );
}
mLegalOperations = Collections.unmodifiableSet( mLegalOperations );
final MBeanAttributeInfo[] allAttrInfos = getMBeanInfo().getAttributes();
final MBeanAttributeInfo[] readables =
JMXUtil.filterAttributeInfos( allAttrInfos,
ReadWriteAttributeFilter.READABLE_FILTER );
final MBeanAttributeInfo[] writeables =
JMXUtil.filterAttributeInfos( allAttrInfos,
ReadWriteAttributeFilter.WRITEABLE_FILTER );
mLegalReadableAttributes =
GSetUtil.newUnmodifiableStringSet( JMXUtil.getAttributeNames( readables ) );
mLegalWriteableAttributes =
GSetUtil.newUnmodifiableStringSet( JMXUtil.getAttributeNames( writeables ) );
}
catch( Exception e )
{
System.out.println( ExceptionUtil.toString( e ) );
throw new RuntimeException( e );
}
|
public java.lang.String | toString()
return toString( true );
|
private java.lang.String | toString(java.util.Collection c)
return CollectionUtil.toString( c );
|
private java.lang.String | toString(java.util.Collection c, java.lang.String sep)
return CollectionUtil.toString( c, sep );
|
public java.lang.String | toString(boolean verbose)
final String NEWLINE = System.getProperty( "line.separator" );
final String INDENT = " ";
final String ITEM_SEP = NEWLINE + INDENT;
final StringBuilder b = new StringBuilder();
b.append( "Attribute read coverage " +
getAttributesRead().size() + "/" + getNumReadableAttributes() +
" = " + getAttributeReadCoverage() + "%" + NEWLINE );
b.append( "Attribute write coverage " +
getAttributesWritten().size() + "/" + getNumWriteableAttributes() +
" = " + getAttributeWriteCoverage() + "%" + NEWLINE );
b.append( "Operation invocation coverage " +
getOperationsInvoked().size() + "/" + getNumOperations() +
" = " + getOperationCoverage() + "%" + NEWLINE );
if ( verbose )
{
b.append( mAttributesRead.size() +
" Attributes read: " + ITEM_SEP +
toString( getAttributesRead(), ITEM_SEP) + NEWLINE );
b.append( mAttributesWritten.size() +
" Attributes written: " + ITEM_SEP +
toString( getAttributesWritten(), ITEM_SEP) + NEWLINE );
b.append( mOperationsInvoked.size() +
" operations invoked: " + ITEM_SEP +
toString( getOperationsInvoked(), ITEM_SEP) + NEWLINE );
}
if ( getMBeanInfo() != null )
{
Set<String> not = null;
not = getAttributesNotRead();
if ( not.size() != 0 || verbose )
{
b.append( not.size() +
" Attributes NOT read:" + ITEM_SEP + toString( not, ITEM_SEP ) + NEWLINE );
}
not = getAttributesNotWritten();
if ( not.size() != 0 || verbose )
{
b.append( not.size() +
" Attributes NOT written:" + ITEM_SEP + toString( not, ITEM_SEP) + NEWLINE );
}
not = getOperationsNotInvoked();
if ( not.size() != 0 || verbose )
{
b.append( not.size() +
" operations NOT invoked:" + ITEM_SEP +
CollectionUtil.toString( not, ITEM_SEP ) + NEWLINE );
}
}
else
{
b.append( "WARNING: MBeanInfo not supplied, " +
"can't emit Attributes/operations not read/written/invoked" + NEWLINE );
}
Map<String,Integer> failures = null;
failures = getAttributeGetFailures();
if ( failures.size() != 0 || verbose )
{
b.append( failures.keySet().size() +
" getAttribute failures: " + ITEM_SEP +
toString( failures.keySet(), ITEM_SEP) + NEWLINE );
}
failures = getAttributeSetFailures();
if ( failures.size() != 0 || verbose )
{
b.append( failures.keySet().size() +
" setAttribute failures: " + ITEM_SEP +
toString( failures.keySet(), ITEM_SEP) + NEWLINE );
}
failures = getUnknownAttributes();
if ( failures.size() != 0 || verbose )
{
b.append( failures.keySet().size() +
" unknown Attributes: " + ITEM_SEP +
toString( failures.keySet(), ITEM_SEP) + NEWLINE );
}
failures = getUnknownOperations();
if ( failures.size() != 0 || verbose )
{
b.append( failures.keySet().size() +
" unknown operations: " + ITEM_SEP +
toString( failures.keySet(), ITEM_SEP) + NEWLINE );
}
failures = getInvocationFailures();
if ( failures.size() != 0 || verbose )
{
b.append( failures.keySet().size() +
" invoke() failures: " + ITEM_SEP +
CollectionUtil.toString( failures.keySet(), ITEM_SEP) + NEWLINE );
}
return b.toString();
|
private void | unknownAttribute(java.lang.String name)
Integer count = mUnknownAttributes.get( name );
count = Integer.valueOf(count == null ? 1
: 1 + count.intValue());
mUnknownAttributes.put( name, count );
|
private void | unknownOperation(java.lang.String name, java.lang.String[] sig)
final String fullName =
getFullOperationName( name, sig );
Integer count = mUnknownOperations.get( fullName );
count = Integer.valueOf(count == null ? 1
: 1 + count.intValue());
mUnknownOperations.put( fullName, count );
|