util
Class ExecutingMethod

java.lang.Object
  extended by util.ExecutingMethod

public class ExecutingMethod
extends Object

A static class that allows tracing of the currently executing method.

WARNING: This class is not independent of the implementation of the java virtual machine. In particular, it uses the stack trace of an auxilliary throwable to trace back the method that was called. This involves string parsing, which might not be implementation independent.

This class can only trace methods that are public and are not overloaded.


Nested Class Summary
static class ExecutingMethod.Test
          Test class.
static class ExecutingMethod.Trace
          Second test.
 
Field Summary
private static int DEFDEPTH
          Default depth.
private static int DEFTRACE
          Default depth.
private static long ms
          Time.
 
Constructor Summary
ExecutingMethod()
           
 
Method Summary
static StackTraceElement getExecuting(int depth)
          Stack traces are available from 1.4
static Method getMethod()
          Returns the method from where this method was called.
static Method getMethod(int depth)
          Traces through a stack track generated just to allow parsing of the calling class and method.
static void printAllThreadTraces()
          Gets the stack traces of all currently active threads and issuss them to std-err.
static void printCurrentThreadTrace()
          Prints the stack trace of the current thread.
private static void printSingleThreadTrace(Thread exe, StackTraceElement[] cur)
          Takes a thread and all its thread stack trace elements and puts them in a readable form to std-err.
static void printThreadTrace(Thread t)
          Prints the stack trace of the specialized thread.
static void printTrace()
          Print the class, method and line number of the caller.
static void threadDebug(long ms)
          Starts a thread that waits the specified number of milliseconds and then calls the thread stack trace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFDEPTH

private static final int DEFDEPTH
Default depth.

See Also:
Constant Field Values

DEFTRACE

private static final int DEFTRACE
Default depth.

See Also:
Constant Field Values

ms

private static long ms
Time.

Constructor Detail

ExecutingMethod

public ExecutingMethod()
Method Detail

getMethod

public static Method getMethod()
Returns the method from where this method was called.


getMethod

public static Method getMethod(int depth)
Traces through a stack track generated just to allow parsing of the calling class and method. The throwable generated is read line by line until the argument number is reached. This line is interpreted as a combination of a class and a method name of the following format (question marks represent arbitrary characters, asterisks arbitrary characters of arbitrary length, whitespaces): *atclassname.method(*. If a class and methodname was parsed, the class loader is asked if it knows the class. All of the methods are queried for the first one that matches the parsed name. This method is returned.

Returns:
null on exceptions or parsing failures

getExecuting

public static StackTraceElement getExecuting(int depth)
Stack traces are available from 1.4


printTrace

public static void printTrace()
Print the class, method and line number of the caller.


printAllThreadTraces

public static void printAllThreadTraces()
Gets the stack traces of all currently active threads and issuss them to std-err.


printThreadTrace

public static void printThreadTrace(Thread t)
Prints the stack trace of the specialized thread.


printCurrentThreadTrace

public static void printCurrentThreadTrace()
Prints the stack trace of the current thread.


printSingleThreadTrace

private static void printSingleThreadTrace(Thread exe,
                                           StackTraceElement[] cur)
Takes a thread and all its thread stack trace elements and puts them in a readable form to std-err.


threadDebug

public static void threadDebug(long ms)
Starts a thread that waits the specified number of milliseconds and then calls the thread stack trace.