com.atlassian.bamboo.executor
Class InterruptThreadWatchdog

java.lang.Object
  extended by com.atlassian.bamboo.executor.InterruptThreadWatchdog
All Implemented Interfaces:
org.apache.tools.ant.util.TimeoutObserver

@ThreadSafe
public abstract class InterruptThreadWatchdog
extends java.lang.Object
implements org.apache.tools.ant.util.TimeoutObserver

An abstract class for interrupting a thread after a given timeout. onBeforeInterrupt(Thread) is for implementors adding logical logging comments


Constructor Summary
InterruptThreadWatchdog(long timeoutSeconds, java.lang.Thread thread)
          Creates a new watchdog with a given timeoutSeconds.
 
Method Summary
 long getTimeoutSeconds()
           
 boolean isThreadInterrupted()
          Indicates whether the thread run was killed on timeoutSeconds or not.
protected abstract  void onBeforeInterrupt(java.lang.Thread thread)
          Forced extension point, usually would just have some intelligent logging.
 void start()
          Watches the given process and terminates it, if it runs for too long.
 void stop()
          Stops the watcher.
 void timeoutOccured(org.apache.tools.ant.util.Watchdog w)
          Called after watchdog has finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InterruptThreadWatchdog

public InterruptThreadWatchdog(long timeoutSeconds,
                               @NotNull
                               java.lang.Thread thread)
Creates a new watchdog with a given timeoutSeconds.

Parameters:
timeoutSeconds - the timeout for the thread in seconds. It must be greater than 0.
thread -
Method Detail

start

public void start()
Watches the given process and terminates it, if it runs for too long. All information from the previous run are reset.

Parameters:
process - the process to monitor. It cannot be null
Throws:
java.lang.IllegalStateException - if a process is still being monitored.

stop

public void stop()
Stops the watcher. It will notify all threads possibly waiting on this object.


timeoutOccured

public void timeoutOccured(org.apache.tools.ant.util.Watchdog w)
Called after watchdog has finished. This can be called in the watchdog thread

Specified by:
timeoutOccured in interface org.apache.tools.ant.util.TimeoutObserver
Parameters:
w - the watchdog

onBeforeInterrupt

protected abstract void onBeforeInterrupt(java.lang.Thread thread)
Forced extension point, usually would just have some intelligent logging. Will run under synchronization

Parameters:
thread -

isThreadInterrupted

public boolean isThreadInterrupted()
Indicates whether the thread run was killed on timeoutSeconds or not.

Returns:
true if the process was killed otherwise false.

getTimeoutSeconds

public long getTimeoutSeconds()


Copyright © 2013 Atlassian Software Systems Pty Ltd. All Rights Reserved.