Java Dynamic Management Kit 4.0 Tools Reference
  Search only this book
Download this book in PDF (74 KB)

Chapter 4 Tracing Mechanism

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

You control the tracing by defining the trace properties specific to the Java Dynamic Management Kit. There are three factors that affect the tracing:

  • The various components which send trace messages

  • The level of detail

  • The output destination

Receiving Trace/Debug Information

The com.sun.jdmk.Trace class provides methods for receiving trace/debug messages. Options provided by this class enable you to specify:

  • The types of trace/debug information

  • The level of trace/debug information

  • Receiving trace/debug information

All the classes of the Java Dynamic Management Kit use the trace class for printing traces. You can use the trace class in your own code for printing debug traces for your own classes.

Specifying the Types of Trace/Debug Information

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

  • INFO_MBEANSERVER: information about the MBean server

  • INFO_MLET: information from an MLet service

  • INFO_MONITOR: information from a monitor

  • INFO_TIMER: information from a timer

  • INFO_ADAPTOR_CONNECTOR: information concerning all adaptors and connectors

  • INFO_ADAPTOR_HTML: information from an HTML adaptor

  • INFO_CONNECTOR_RMI: information from a RMI connector

  • INFO_CONNECTOR_HTTP: information from HTTP connectors

  • INFO_ADAPTOR_SNMP: information from an SNMP adaptor

  • INFO_SNMP: information from a SNMP manager service

  • INFO_NOTIFICATION: information from notification mechanism

  • INFO_MISC: information sent from any other classes

  • INFO_ALL. Information from all classes

Specifying the Level of Trace/Debug Information

The level of detail controls the amount of messages you receive. The "trace" level is the default which gives information about the actions of the MBean server and other components. The "debug" level includes all the "trace" information and gives more detail about internal calls, especially in the connector MBeans. It is possible to specify the level of trace/debug information you want to receive. Two levels of information are specified:

  • LEVEL_TRACE-- provides information to help a developer when programming

  • LEVEL_DEBUG -- provides information to help diagnose Java Dynamic Management Kit 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.

Receiving Trace/Debug Information

The com.sun.jdmk.Trace 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:

  • adding a notification listener with a filter in the code. It is possible to have more than one notification listener but with different filters. With TraceFilter, you can specify the type and level of information you wish to receive. See Example 4-3 and Example 4-2.

  • specifying system properties in the command to start the Java interpreter when you run a class. In this case, the code of the class must include a call to method Trace.parse.TraceProperties();.


Example 4-1 Creating a Notification Listener

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


Example 4-2 Adding the Notification Listener to the class

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

You can also use the class TraceListener to save trace information to a file.


Example 4-3 Creating a Trace Filter

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