Java Dynamic Management Kit 5.0 Tools Reference

Chapter 4 Tracing Mechanism

This chapter explains how to use the tracing mechanism to help you trace or debug the Java Dynamic Management Kit (DMK) API. The tracing mechanism uses the notification mechanism to distribute the trace and debug information, giving you internal runtime information. You can specify the information type and level of trace and debug information you want to receive. To receive trace and debug information you must add a notification listener to the class com.sun.jdmk.TraceManager.

You control the tracing by defining the trace properties specific to the Java DMK. Three factors affect tracing:

The com.sun.jdmk.trace.Trace class is used to emit trace messages. All the classes of the Java DMK use this Trace class for sending traces. You can use the Trace class in your own code for producing debug traces for your own classes.

The com.sun.jdmk.TraceManager class provides methods for receiving trace and debug messages. Options provided by the TraceManager class are described in the following sections:

Receiving Trace and Debug Information

The com.sun.jdmk.TraceManager class uses the notification mechanism to distribute the information. You must add a notification listener to receive information (see example Example 4–1). There are two ways to receive trace information:


Example 4–1 Creating a Notification Listener

// Create a listener and save all info to the file /tmp/trace 
TraceListener listener = new TraceListener("/tmp/trace"); 


Example 4–2 Creating a Trace Filter

// create a trace filter with LEVEL_DEBUG and INFO_ALL/
TraceFilter filter = new TraceFilter(Trace.LEVEL_DEBUG, Trace.INFO_ALL);


Example 4–3 Adding the Notification Listener to the class

// add the listener to the class Trace/
TraceManager.addNotificationListener(listener, filter, null);

Specifying the Type of Trace and Debug Information

It is possible to specify the type of trace and debug information you want to receive. The following types are specified:

The preceding information is held by the TraceTags class

Specifying the Level of Trace and Debug Information

The level of detail controls the number of messages you receive. The trace level is the default that gives information about the actions of the MBean server and other components. The debug level includes all the trace information providing information to help diagnose Java DMK implementation. If this level is specified, the information of LEVEL_TRACE is sent too. It is possible to specify the level of trace or debug information you want to receive. Two levels of information are specified in the TraceTags class:

LEVEL_TRACE

Provides information to help a developer when programming

LEVEL_DEBUG

Provides information to help diagnose Java DMK implementation

If you choose the second option, you will automatically receive all trace information as well as debug information. By default, the level is set to LEVEL_TRACE.