Sun Identity Manager 8.1 System Administrator's Guide

Tracing Adapters

You can use trace information to verify that a resource adapter has started, to verify that all setting changes were saved, and to diagnose problems with the adapter.

This section contains information to help you configure adapter tracing, and is organized into the following topics:

General Notes About Tracing Adapters

When you enable tracing for an adapter, you must identify the methods that you want to trace by typing:


com.waveset.adapter.sample.MyResourceAdapter

You must also provide calls to create log entries for any new methods in your custom resource adapter so the adapter can write its resource settings to a log file.

In some cases, you can specify additional logging parameters for the resource instance, such as:


Note –

Instrumenting Code with Trace Points

The Identity Manager trace facility enables you to instrument code with trace points in the adapters component (resource adapters). This section contains some guidelines to help you to consistently use trace points to assess and resolve adapter problems.

Some guiding principles for instrumenting code with trace points are as follows:

You can specify a trace level for a trace point to control how much information displays. The following table describes each of the trace levels that are defined in the com.sun.idm.logging.TraceManager interface.

Table 5–2 Defined Trace Levels

Trace Level 

Trace Variable 

Usage 

Trace.LEVEL1

Entry and exit points of public methods of the resource adapter interface 

Trace.LEVEL2

Entry and exit points of non-public methods or methods not included in the Identity Manager component external interface 

Trace.LEVEL3

Decision points or significant variables 

Trace.LEVEL4

Very detailed information, such as significant variables within a loop 

n/a 

Trace.ALWAYS

Do not perform a trace-level check  

Note: Use this option if you have already specified the trace level in a condition.


Note –

Use the com.sun.idm.logging.Trace class to prevent circular dependencies on the com.sun.idm.logging package that implements the com.sun.idm.logging.TraceManager interface.


When adding trace points to code, be aware of the following information:

The following sections describe specific trace levels in greater detail and provide examples showing how to use trace points in code.

Using Entry and Exit Trace Points

Consider these guidelines before adding entry and exit trace points to your code:

Following are some simple entry and exit trace statements. For these examples, assume the following CLASS variables are declared for each statement.

private static final String CLASS = 
"com.waveset.adapter.MyResourceAdapter"; 
protected static Trace _trace = Trace.getTrace();

Example 5–1 Entry Trace Point Example

final String METHOD = methodName; 
_trace.entry(_trace.LEVEL1, CLASS, METHOD);
_trace.entry(_trace.LEVEL1, CLASS, METHOD, user);
if (_trace.level1(CLASS, METHOD)) {    
_trace.entry(_trace.ALWAYS, CLASS, METHOD,
user= + user); 
}

// Show the size of an array argument
// ASSUME: password is an argument to the method
// Note the use of the Util.length() method. It is
// a convenience method that guards against null.
if (_trace.level1(CLASS, METHOD)) {
    StringBuffer sb = new StringBuffer(32);
    sb.append(password length=);
    ab.append(Util.length(password));
    _trace.entry(_trace.ALWAYS, CLASS, METHOD, sb.toString());
}


Example 5–2 Exit Trace Point Example

_trace.exit(_trace.LEVEL1, CLASS, METHOD);

_trace.exit(_trace.LEVEL1, CLASS, METHOD, returnValue);
if (_trace.level1(CLASS, METHOD)) {
    _trace.exit(_trace.ALWAYS, CLASS, METHOD,
      returnValue != null ? returnValue.getName() : returnValue);
}

// Show the size of an array 
String[] accounts = ... 
if (_trace.level1(CLASS, METHOD)) {    
    StringBuffer sb = new StringBuffer(32)
    sb.append(accounts length=);    
    ab.append(accounts.length);    
    _trace.exit(_trace.ALWAYS, CLASS, METHOD, sb.toString()); 
}

Using Information Trace Points

Consider these guidelines before adding information trace points to your code:

Following is an example of a simple information trace statement. For this example, assume the following CLASS variables are declared.

private static final String CLASS = 
"com.waveset.adapter.MyResourceAdapter"; 
protected static Trace _trace = Trace.getTrace();

Example 5–3 Information Trace Point Example

_trace.info(_trace.LEVEL3, CLASS, METHOD, Some Message);
WavesetResult result = new WavesetResult(); 
try {   
   someMethod(); 
}  catch(Exception e) {   
   String msg = Some Error Message;   
   WavesetException we = new Waveset(msg, e);   
   _trace.caught(_trace.LEVEL3, CLASS, METHOD, e);   
   result.addException(we); 
}

Using Exception Trace Points

Consider these guidelines before adding exception trace points to your code:

Following is an example of a simple exception trace statement. For this example, assume the following CLASS variables are declared:

private static final String CLASS = 
"com.waveset.adapter.MyResourceAdapter"; 
protected static Trace _trace = Trace.getTrace();

Example 5–4 Exception Trace Point Example

try {   
   someMethod(); 
}  catch(Exception e) {   
   _trace.throwing(_trace.ALWAYS, CLASS, METHOD, e);   
   throw e; 
}


try {   
   someMethod(); 
}  catch(Exception e) {   
   _trace.throwing(_trace.ALWAYS, CLASS, METHOD, e);   
   WavesetException we = new WavesetException(Some Message, e);   
   throw we; 
}


if (error) {   
  WavesetException e = new WavesetException(Some Error Message.; 
  _trace.throwing(_trace.LEVEL3, CLASS, METHOD, e);   
  throw e;
}

try {
   someMethod();
}  catch(Exception e) {
   _trace.caught(_trace.LEVEL1, CLASS, METHOD, e);
}
// execution continues.
someOtherMethod();

Using Trace Point Templates

Using trace point templates can help you provide consistent and useful trace points in Identity Manager resource adapters. Identity Manager provides Eclipse templates in the following location:

src/wps/doc/eclipse-trace-templates.xml

To import these templates into Eclipse, select Window -> Preferences -> Java -> Editor -> Templates.


Note –

You can create similar templates if you are using Emacs or IDEA.


Other Tracing Guidelines

This section describes some additional tracing guidelines, including the following:

Tracing Inner Classes

Remember to trace significant methods in inner classes. Be sure to declare a final static CLASS variable if there are any trace methods in the inner class.


Example 5–5 Example of Using a CLASS Variable in Inner Classes

private final static String CLASS = 
com.waveset.adapter.SomeResourceAdapter$AdapterInnerClass;

Tracing Static Initializers

In general, do not use the trace facility in static initializers. Identity Manager executes these initializers when the class is loaded, which can occur when the repository is initialized. Use the Debug class to trace anything significant in static initializers.