org.openuat.util
Class SafetyBeltTimer

java.lang.Object
  extended by org.openuat.util.SafetyBeltTimer
All Implemented Interfaces:
java.lang.Runnable

public class SafetyBeltTimer
extends java.lang.Object
implements java.lang.Runnable

This is a currently safety belt against the dongle being stuck in authentication mode or the other dongle never entering authentication mode. I.e., it is a safeguard against that specific loop ending up being an endless loop (which is not good in terms of fault tolerance). This helper class implements a "grenade timer" that will let the main event loop bail out with a timeout when it is stuck for too long at the same round number. It is also useful for other purposes, even if it has been created specifically for DongleProtocolHandler#handleDongleCommunication for safeguarding its main loop. There is no need to explicitly stop the thread, it will just time out and stop.

Version:
1.0
Author:
Rene Mayrhofer

Constructor Summary
SafetyBeltTimer(int time, java.io.InputStream abortStream)
           
 
Method Summary
 boolean isTriggered()
          Returns true when the timer has triggered and the task should terminate.
 void reset()
          Allows to send a hearbeat signal to the timer by resetting it.
 void run()
          Implements the timer background thread.
 void stop()
          This stops the safety belt timer gracefully without triggering it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SafetyBeltTimer

public SafetyBeltTimer(int time,
                       java.io.InputStream abortStream)
Parameters:
time - The time, in milliseconds, that this timer will use.
abortStream - If set, then this stream will be forcefully closed when the timer is triggered. This can be used for enforcing timeouts on blocking reads. Set to null to disable this functionality.
Method Detail

run

public void run()
Implements the timer background thread.

Specified by:
run in interface java.lang.Runnable

isTriggered

public boolean isTriggered()
Returns true when the timer has triggered and the task should terminate.


reset

public void reset()
Allows to send a hearbeat signal to the timer by resetting it. This allows to implement heartbeat like functionality where the timer can get reset whenever some progress is being made.


stop

public void stop()
This stops the safety belt timer gracefully without triggering it.



2005-2006, Rene Mayrhofer.