org.ros.concurrent
Class CancellableLoop

java.lang.Object
  extended by org.ros.concurrent.CancellableLoop
All Implemented Interfaces:
java.lang.Runnable

public abstract class CancellableLoop
extends java.lang.Object
implements java.lang.Runnable

An interruptable loop that can be run by an ExecutorService.


Constructor Summary
CancellableLoop()
           
 
Method Summary
 void cancel()
          Interrupts the loop.
protected  void handleInterruptedException(java.lang.InterruptedException e)
          An InterruptedException was thrown.
 boolean isRunning()
           
protected abstract  void loop()
          The body of the loop.
 void run()
           
protected  void setup()
          The setup block for the loop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CancellableLoop

public CancellableLoop()
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable

setup

protected void setup()
The setup block for the loop. This will be called exactly once before the first call to loop().


loop

protected abstract void loop()
                      throws java.lang.InterruptedException
The body of the loop. This will run continuously until the CancellableLoop has been interrupted externally or by calling cancel().

Throws:
java.lang.InterruptedException

handleInterruptedException

protected void handleInterruptedException(java.lang.InterruptedException e)
An InterruptedException was thrown.


cancel

public void cancel()
Interrupts the loop.


isRunning

public boolean isRunning()
Returns:
true if the loop is running