com.p6spy.engine.outage
Class P6OutageDetector

java.lang.Object
  extended bycom.p6spy.engine.outage.P6OutageDetector
All Implemented Interfaces:
Runnable

public class P6OutageDetector
extends Object
implements Runnable

This class is a singleton. Since P6Spy is normally loaded by the system classpath, it is a normally a singleton across the JVM. The instance will determine if a statement has been long running and log the statement when such a statment is found. It accomplishes this by spawning a daemon thread which will wake up at configurable intervals of time (defined in seconds) and check if a statement is still executing since the last time the thread was awake. This is accomplished by this instance maintaining a list of active statements. The P6Statement and P6PreparedStatement objects will reqister their call with the instance just before the SQL call is delegated to the real driver. Once that statement finishes executing, the statement object will unregister that call from list. If during that time the thread in this instance sees the execute time exceed the threshold, it is flagged as a long-running statement and logged. The statement will continue to be logged if it appears in future iterations of the sleep/wake cycle. This class is implemented with lazy thread sychronization. The list of pending statements is a synchronized container, the rest is left open to thread hazards to reduce the performance impact. So the logging results might be slightly unreliable, but we aren't dealing with bank accounts here so thats okay.


Constructor Summary
protected P6OutageDetector()
          Creates new P6OutageDetector
 
Method Summary
static P6OutageDetector getInstance()
          Gets the instance of the detector.
 void registerInvocation(Object jdbcObject, long startTime, String category, String ps, String sql)
          Registers the execution of a statement.
 void run()
          Method for running the auxillary thread.
 void shutdown()
          Tells the auxillary thread to stop executing.
 void unregisterInvocation(Object jdbcObject)
          Unregisters the execution of a statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

P6OutageDetector

protected P6OutageDetector()
Creates new P6OutageDetector

Method Detail

getInstance

public static P6OutageDetector getInstance()
Gets the instance of the detector. A side effect of the first call to this method is that the auxillary thread will be kicked off here.

Returns:
the P6OutageDetector instance

run

public void run()
Method for running the auxillary thread.

Specified by:
run in interface Runnable

shutdown

public void shutdown()
Tells the auxillary thread to stop executing. Thread will exit upon waking next.


registerInvocation

public void registerInvocation(Object jdbcObject,
                               long startTime,
                               String category,
                               String ps,
                               String sql)
Registers the execution of a statement. This should be called just before the statement is passed to the real driver.


unregisterInvocation

public void unregisterInvocation(Object jdbcObject)
Unregisters the execution of a statement. This should be called just after the statement is passed to the real driver.