All Packages Class Hierarchy This Package Previous Next Index
Class phil.util.traceJ.Trace
java.lang.Object
|
+----phil.util.traceJ.Trace
- public class Trace
- extends Object
- implements Traceable
Provides trace functionality for single-threaded Java applications. If used
to trace multiple threads of an application, then the trace depth is uselesss
and may in fact generate out-of-bounds errors.
A multi-threaded version is available. Please contact me at philreed@ticnet.com
for information.
NOTE: Example program source is included in examples\TestTrace.java
USAGE NOTES:  
Trace.method()
must be called before any trace statements in the
body of a method will be executed. Likewise, Trace.constructor()
must be called before any trace statements in the body of a class constructor.
-
active
- The current state of the trace (does it have valid bits?).
-
bits
- The trace bits currently in use.
-
currentClass
- The name of the current class.
-
currentDepth
- The current depth (in traced classes/methods).
-
methodStack
- The name of the current method.
-
open
- The current state of the output stream.
-
outputName
- The name of the trace output file.
-
threadName
- The name of the thread/component.
-
Trace()
- Opens a trace output stream to standard output.
-
Trace(int)
- Opens a trace output stream to standard output and activates traces using the specified bits.
-
Trace(String)
- Opens a trace output stream.
-
Trace(String, int)
- Opens a trace output stream and activates traces using the specified bits.
-
close()
- Deactivates traces.
-
constructor(Object)
- Used to enable tracing of a class constructor.
-
dump(TraceToken, char[])
- Generates a formatted hex dump of
buffer
and adds it to the output stream.
-
dump(TraceToken, char[], int, int)
- Generates a formatted hex dump of
buffer
from offset
for length
and adds it to the output stream.
-
dump(TraceToken, String)
- Generates a formatted hex dump of
buffer
and adds it to the output stream.
-
dump(TraceToken, String, int, int)
- Generates a formatted hex dump of
buffer
from offset
for length
and adds it to the output stream.
-
dumpStack()
- Dumps the contents of the method call stack to the trace output stream in
reverse order.
-
dumpTraceBits()
- Dumps the active trace bits to the output stream.
-
exit(TraceToken)
- Removes the current method from the method stack and indicates its exit in the
trace output stream.
-
exit(TraceToken, boolean)
- Removes the current method from the method stack and indicates its exit in the
trace output stream.
-
field(TraceToken, String, int)
- Prints the name and contents of a field to the trace output stream.
-
field(TraceToken, String, Object)
- Prints the name and contents of a field to the trace output stream.
-
field(TraceToken, String, String)
- Prints the name and contents of a field to the trace output stream.
-
getBitArray()
- Generates a String array containing the names of the active trace bits.
-
getBits()
- Returns the active trace bits.
-
getMethodStack()
- Returns a Vector containing Strings representing the method call stack.
-
method(Object, String, int)
- Adds the current method to the method stack and indicates its entry in the
trace output stream.
-
print(TraceToken, String)
- Prints the specified string to the trace output stream.
-
print(TraceToken, String, int)
- Prints the specified string to the trace output stream.
-
set(int)
- Sets the trace bits in use to those specified.
-
test(int)
- Tests if a bit or set of bits is currently set.
active
protected static boolean active
- The current state of the trace (does it have valid bits?).
open
protected static boolean open
- The current state of the output stream.
bits
protected static int bits
- The trace bits currently in use.
currentDepth
protected static int currentDepth
- The current depth (in traced classes/methods).
outputName
protected static String outputName
- The name of the trace output file.
threadName
protected static String threadName
- The name of the thread/component.
methodStack
protected static Vector methodStack
- The name of the current method.
currentClass
protected String currentClass
- The name of the current class.
Trace
public Trace()
- Opens a trace output stream to standard output.
Trace
public Trace(int bits)
- Opens a trace output stream to standard output and activates traces using the specified bits.
- Parameters:
- bits - an
int
value representing trace bits.
Trace
public Trace(String traceName)
- Opens a trace output stream.
If
traceName
is a null string (length=0) then a TraceGUI
object is created and used for output.
- Parameters:
- traceName - a String containing the file name for trace output.
Trace
public Trace(String traceName,
int bits)
- Opens a trace output stream and activates traces using the specified bits.
If
traceName
is a null string (length=0) then a TraceGUI
object is created and used for output.
- Parameters:
- traceName - a
String
containing the file name for trace output.
- bits - an
int
value representing trace bits.
close
public void close()
- Deactivates traces. The output stream is flushed and closed.
constructor
public TraceToken constructor(Object traceObject)
- Used to enable tracing of a class constructor. Tracing is only performed if the
TR_CONSTRUCT bit is enabled.
- Parameters:
- traceObject - The object being constructed. Suggest using
this
.
- Returns:
- The token used for all trace operations in the constructor.
dump
public void dump(TraceToken token,
char buffer[])
- Generates a formatted hex dump of
buffer
and adds it to the output stream.
- Parameters:
- token - The
TraceToken
used by the current constructor or method.
- buffer - char[]
dump
public void dump(TraceToken token,
char buffer[],
int offset,
int length)
- Generates a formatted hex dump of
buffer
from offset
for length
and adds it to the output stream.
- Parameters:
- token - The
TraceToken
used by the current constructor or method.
- buffer - char[]
- offset - int
- length - int
dump
public void dump(TraceToken token,
String buffer)
- Generates a formatted hex dump of
buffer
and adds it to the output stream.
- Parameters:
- token - The
TraceToken
used by the current constructor or method.
- buffer - java.lang.String
dump
public void dump(TraceToken token,
String buffer,
int offset,
int length)
- Generates a formatted hex dump of
buffer
from offset
for length
and adds it to the output stream.
- Parameters:
- token - The
TraceToken
used by the current constructor or method.
- buffer - char[]
dumpStack
public void dumpStack()
- Dumps the contents of the method call stack to the trace output stream in
reverse order.
dumpTraceBits
protected void dumpTraceBits()
- Dumps the active trace bits to the output stream.
exit
public void exit(TraceToken token)
- Removes the current method from the method stack and indicates its exit in the
trace output stream.
- Parameters:
- token - The
TraceToken
used by the current constructor or method.
exit
public void exit(TraceToken token,
boolean value)
- Removes the current method from the method stack and indicates its exit in the
trace output stream.
- Parameters:
- token - The
TraceToken
used by the current constructor or method.
- value - boolean
field
public void field(TraceToken token,
String fieldName,
int value)
- Prints the name and contents of a field to the trace output stream.
- Parameters:
- token - The
TraceToken
used by the current constructor or method.
- fieldName - java.lang.String
- value - int
field
public void field(TraceToken token,
String fieldName,
Object value)
- Prints the name and contents of a field to the trace output stream.
- Parameters:
- token - The
TraceToken
used by the current constructor or method.
- fieldName - java.lang.String
- value - java.lang.Object
field
public void field(TraceToken token,
String fieldName,
String value)
- Prints the name and contents of a field to the trace output stream.
- Parameters:
- token - The
TraceToken
used by the current constructor or method.
- fieldName - java.lang.String
- value - java.lang.String
getBitArray
protected String[] getBitArray()
- Generates a String array containing the names of the active trace bits.
- Returns:
- java.lang.String[]
getBits
public int getBits()
- Returns the active trace bits.
- Returns:
- int
getMethodStack
public Vector getMethodStack()
- Returns a Vector containing Strings representing the method call stack.
The elements are in call order with the last element representing the most
recent method traced.
- Returns:
- java.util.Vector
method
public TraceToken method(Object caller,
String methodName,
int bits)
- Adds the current method to the method stack and indicates its entry in the
trace output stream.
- Parameters:
- caller - The object being traced. Suggest using
this
.
- methodName - a String containing the name of the traced method.
- bits - an integer value representing trace bits for which this method should be traced.
- Returns:
- TraceToken The token used for all trace operations in the method.
print
public void print(TraceToken token,
String text)
- Prints the specified string to the trace output stream. The string is appended to
a trace prefix string prior to output.
- Parameters:
- token - The
TraceToken
used by the current constructor or method.
- text - The string to print.
print
public void print(TraceToken token,
String text,
int msgType)
- Prints the specified string to the trace output stream. The string is appended to
a trace prefix string prior to output and, if
msgType
contains a valid,
active type, an eye-catcher string is also included.
- Parameters:
- token - The
TraceToken
used by the current constructor or method.
- text - The string to print.
- msgType - int value, TR_DIAG or TR_COMMENT, any other value causes the default
print format to be used.
set
public void set(int bits)
- Sets the trace bits in use to those specified.
- Parameters:
- bits - int
test
public boolean test(int bits)
- Tests if a bit or set of bits is currently set.
- Parameters:
- bits - int
- Returns:
- boolean
All Packages Class Hierarchy This Package Previous Next Index