A handy class for tracking repeated calls to methods that should not be

called repeatedly.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1484 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2004-08-13 21:14:48 +00:00
parent 6cf9708e1d
commit 6a8f69cb12
@@ -0,0 +1,51 @@
//
// $Id$
package com.samskivert.util;
import com.samskivert.Log;
/**
* A class used to debug situations where a method that should be called
* once and only once is being called again later and one wishes to report
* the stack trace of the first and current calling on any repeat
* callings. <em>Note:</em> this object is not thread safe. If the
* multiple callings may take place on different threads, you must
* synchronize the calls to {@link #checkCall} yourself.
*/
public class RepeatCallTracker
{
/**
* This method should be called when the code passes through the code
* path that should be called only once. The first time through this
* path, the method will return false and record the stack trace.
* Subsquent calls will log an error and report the current and
* first-time-through stack traces.
*
* @param warning the warning message to issue prior to logging the
* two stack traces.
*/
public boolean checkCall (String warning)
{
if (_firstCall == null) {
_firstCall = new Exception("---- First call ----");
_firstCall.fillInStackTrace();
return false;
}
Log.logStackTrace(new Exception(warning));
Log.logStackTrace(_firstCall);
return true;
}
/**
* Resets this repeat call tracker.
*/
public void clear ()
{
_firstCall = null;
}
/** Used to keep the stack trace around from the first call. */
protected Exception _firstCall;
}