de.cau.cs.kieler.sim.kiem.execution
Class TimeoutThread

java.lang.Object
  extended by java.lang.Thread
      extended by de.cau.cs.kieler.sim.kiem.execution.TimeoutThread
All Implemented Interfaces:
Runnable

public class TimeoutThread
extends Thread

The Class TimeoutThread. It is used to handle timeouts of methods implemented by DataComponents during the execution. An instance of this class is designed to run in a concurrent worker thread. Whenever the timeout method is called the timeout is activated.

There are two possibilities to stop or deactivate the timeout when the component finished in time:
1. set another new timeout by calling timeout(int, String, DataComponentWrapper, Execution) again.
2. reset the timeout by calling abortTimeout().


When a timeout is triggered then an error message is generated and the execution is stopped immediately. Note that the execution manager only tries to stop all concurrent threads but cannot guarantee that they really terminate in the end.

If a timeout is triggered and the execution is stopped, the timeout thread itself also terminates.

A timeout must be at least 100ms (reasonable).

Rating proposed yellow
(2009-01-15)

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
TimeoutThread()
          Instantiates a new timeout thread.
 
Method Summary
 void abortTimeout()
          Abort a timeout.
static boolean isAwaitUserResponse()
          Checks whether await user response is true.
 void run()
          When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
static void setAwaitUserRepsonse(boolean awaitUserResponseParam)
          Sets the await user repsonse flag.
 void terminate()
          Terminates this thread by awaking it (if it is suspended).
 void timeout(int timeoutParam, String jobDescriptionParam, DataComponentWrapper dataComponentWrapperParam, Execution executionParam)
          Activate as a new timeout.
 
Methods inherited from class java.lang.Thread
currentThread, getName, getPriority, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, setDaemon, setName, setPriority, sleep, start, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeoutThread

public TimeoutThread()
Instantiates a new timeout thread.

Method Detail

setAwaitUserRepsonse

public static void setAwaitUserRepsonse(boolean awaitUserResponseParam)
Sets the await user repsonse flag. USE WITH CAUTION - this deactivates any timeouts!

Parameters:
awaitUserResponseParam - the new await user repsonse

isAwaitUserResponse

public static boolean isAwaitUserResponse()
Checks whether await user response is true.

Returns:
true, if is await user response

timeout

public void timeout(int timeoutParam,
                    String jobDescriptionParam,
                    DataComponentWrapper dataComponentWrapperParam,
                    Execution executionParam)
Activate as a new timeout. The jobDescription should hold information about the called methods of the DataComponentWrapper.

Parameters:
timeoutParam - the timeout in ms
jobDescriptionParam - the job description
dataComponentWrapperParam - the affected DataComponentWrapper
executionParam - a link to the execution

abortTimeout

public void abortTimeout()
Abort a timeout. This aborts the current timeout. Another way to abort a timeout is to simply set a new one by calling the method timeout(int, String, DataComponentWrapper, Execution) .


terminate

public void terminate()
Terminates this thread by awaking it (if it is suspended). The run() method will terminate if it sees the terminate flag to be true.


run

public void run()
Description copied from interface: Runnable
When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

Specified by:
run in interface Runnable
Overrides:
run in class Thread