bb.util
Class ThreadMonitor.UnitTest.ListenerTest

java.lang.Object
  extended by bb.util.ThreadMonitor.UnitTest.ListenerTest
All Implemented Interfaces:
ThreadMonitorListener, Closeable
Enclosing class:
ThreadMonitor.UnitTest

private static class ThreadMonitor.UnitTest.ListenerTest
extends Object
implements Closeable, ThreadMonitorListener

Simple ThreadMonitorListener implementation meant for test purposes: it prints all events to System.out (except for onThreadState, which outputs to pw), it uses barrier to coordinate actions with the main thread, and onThreadState can be configured to deliberately throw a RuntimeException when makeFail called.


Field Summary
private  CyclicBarrier barrier
           
private  boolean fail
           
private  long instanceId
           
private static AtomicLong instanceIdNext
           
private  PrintWriter pw
           
 
Constructor Summary
private ThreadMonitor.UnitTest.ListenerTest()
           
 
Method Summary
private  void await()
          Waits for the main thread to reach a common barrier point with the Timer thread executing this method.
 void close()
           
private  void makeFail()
           
 void onDeadlocked(String state)
          Called whenever the associated ThreadMonitor instance first detects deadlock when previously it had detected no deadlock.
 void onMonitoringError(Throwable t)
          Called when the associated ThreadMonitor instance has detected some error while monitoring.
 void onMonitoringStarted()
          Called when the associated ThreadMonitor instance has just started monitoring.
 void onMonitoringStopped()
          Called when the associated ThreadMonitor instance has just stopped monitoring.
 void onNotDeadlocked(String state)
          Called whenever the associated ThreadMonitor instance first detects no deadlock when previously it had detected deadlock.
 void onThreadState(String state)
          Called whenever the associated ThreadMonitor instance has measured a new thread state.
private  void setBarrier(CyclicBarrier barrier)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instanceIdNext

private static AtomicLong instanceIdNext

instanceId

private final long instanceId

pw

private final PrintWriter pw

barrier

private CyclicBarrier barrier

fail

private boolean fail
Constructor Detail

ThreadMonitor.UnitTest.ListenerTest

private ThreadMonitor.UnitTest.ListenerTest()
                                     throws IOException
Throws:
IOException
Method Detail

onMonitoringStarted

public void onMonitoringStarted()
Description copied from interface: ThreadMonitorListener
Called when the associated ThreadMonitor instance has just started monitoring. This method will be called repeatedly if ThreadMonitor goes thru multiple start and stop cycles.

Specified by:
onMonitoringStarted in interface ThreadMonitorListener

onMonitoringStopped

public void onMonitoringStopped()
Description copied from interface: ThreadMonitorListener
Called when the associated ThreadMonitor instance has just stopped monitoring. This method will be called repeatedly if ThreadMonitor goes thru multiple start and stop cycles.

Specified by:
onMonitoringStopped in interface ThreadMonitorListener

onMonitoringError

public void onMonitoringError(Throwable t)
Description copied from interface: ThreadMonitorListener
Called when the associated ThreadMonitor instance has detected some error while monitoring.

Specified by:
onMonitoringError in interface ThreadMonitorListener
Parameters:
t - the Throwable which caused the error

onThreadState

public void onThreadState(String state)
Description copied from interface: ThreadMonitorListener
Called whenever the associated ThreadMonitor instance has measured a new thread state. This method will be called repeatedly.

Specified by:
onThreadState in interface ThreadMonitorListener
Parameters:
state - the entire thread state which was just measured

onDeadlocked

public void onDeadlocked(String state)
                  throws RuntimeException
Description copied from interface: ThreadMonitorListener
Called whenever the associated ThreadMonitor instance first detects deadlock when previously it had detected no deadlock. This method will be called repeatedly if the JVM cycles in and out of deadlock.

Specified by:
onDeadlocked in interface ThreadMonitorListener
Parameters:
state - the thread state of just the deadlocked threads
Throws:
RuntimeException

onNotDeadlocked

public void onNotDeadlocked(String state)
Description copied from interface: ThreadMonitorListener
Called whenever the associated ThreadMonitor instance first detects no deadlock when previously it had detected deadlock. This method will be called repeatedly if the JVM cycles in and out of deadlock.

Specified by:
onNotDeadlocked in interface ThreadMonitorListener
Parameters:
state - the entire thread state which was just measured

setBarrier

private void setBarrier(CyclicBarrier barrier)

await

private void await()
Waits for the main thread to reach a common barrier point with the Timer thread executing this method.


makeFail

private void makeFail()

close

public void close()
Specified by:
close in interface Closeable