com.sun.jdmk
Class TraceListener

java.lang.Object
  extended bycom.sun.jdmk.TraceListener
All Implemented Interfaces:
EventListener, NotificationListener

public class TraceListener
extends Object
implements NotificationListener

An object of this class can be used to receive notifications sent out by the class Trace, and all notifications received will be saved to a file specified, or write to user screen. This listener will print or save information with two formats:

This class can be used as a default listener, a user can write his own listener to treat trace information the way he wants.


Field Summary
protected  boolean formated
           
protected  boolean needTobeClosed
           
protected  PrintStream out
           
 
Constructor Summary
TraceListener()
          Construct a default trace listener.
TraceListener(PrintStream ps)
          Construct a trace listener with a specified.
TraceListener(String fileName)
          Construct a trace listener with a file specified to save all information received.
 
Method Summary
 void handleNotification(Notification notif, Object handback)
          Called by the class Trace to receive trace information.
 void setFile(String fileName)
          Specify a file to save information received
 void setFormated(boolean f)
          Choose a format to output trace information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected PrintStream out

needTobeClosed

protected boolean needTobeClosed

formated

protected boolean formated
Constructor Detail

TraceListener

public TraceListener()
Construct a default trace listener. All information will printed on screen (System.out) without format.


TraceListener

public TraceListener(PrintStream ps)
              throws IllegalArgumentException
Construct a trace listener with a specified.

Parameters:
ps - A PrintStream object used to print trace information.

For example, it can take value as System.out or System.err.

Throws:
IllegalArgumentException - thrown if the PrintStream parameter is null.

TraceListener

public TraceListener(String fileName)
              throws IOException
Construct a trace listener with a file specified to save all information received.

If specified file exists currently, all trace information will be appended to this file.

Parameters:
fileName - the file used to save information.
Throws:
IOException - thrown if failed to open or to write the file.
Method Detail

setFormated

public void setFormated(boolean f)
Choose a format to output trace information.

Parameters:
f - if true, the full information will be printed out.

handleNotification

public void handleNotification(Notification notif,
                               Object handback)
Called by the class Trace to receive trace information.

Specified by:
handleNotification in interface NotificationListener

setFile

public void setFile(String fileName)
             throws IOException
Specify a file to save information received

Parameters:
fileName - the file used to save information. It will replace the old file or the PrintStream object set before.
Throws:
IOException - thrown if failed to open or to write the file.

FCS Release
jdmk-5_1-b34.1 2005.02.10_16:46:09_MET

Copyright 1998-2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.