Class Specific Name Resolver

org.eclipse.mat.api.nameResolver

0.7.0

When browsing the object list, the Memory Analyzer prints a class specific name next to the object address. This could be the content of the char[] for a java.lang.String or the name attribute of a java.lang.Thread object.

Use this extension point to provide custom name resolvers: for example the title for catalog objects, the user id of authenticated session, etc. etc.

<!ELEMENT extension (resolver)+>

<!ATTLIST extension

point CDATA #REQUIRED

id    CDATA #IMPLIED

name  CDATA #IMPLIED>


<!ELEMENT resolver EMPTY>

<!ATTLIST resolver

impl CDATA #REQUIRED>


Following is an example of a name resolver declaration:

   

<extension point=

"org.eclipse.mat.api.nameResolver"

>

<resolver impl=

"org.eclipse.mat.inspections.CommonNameResolver$ThreadResolver"

/>

</extension>

The implemenation could look like this:

   @Subject("java.lang.Thread")
   public static class ThreadResolver implements IClassSpecificNameResolver
   {
      public String resolve(IObject obj) throws SnapshotException
      {
         IObject name = (IObject) obj.resolveValue("name");
         return name != null ? name.getClassSpecificName() : null;
      }
  }

The @Subject tells the Memory Analyzer, to use this name resolver for all instances of type "java.lang.Thread". The implementation then extracts the name attribute (which is a String or a char[] object, depending on the implementation of the JDK) and returns its class specific name.

The value of the impl attribute must represent an implementor of org.eclipse.mat.snapshot.extension.IClassSpecificNameResolver.

The Memory Analyzer supplies a number of name resolvers itself. Check out the org.eclipse.mat.inspections.CommonNameResolver for more samples.