org.d_haven.event.command
Class AbstractThreadPolicy

java.lang.Object
  extended by org.d_haven.event.command.AbstractThreadPolicy
All Implemented Interfaces:
java.lang.Runnable, ThreadPolicy
Direct Known Subclasses:
OneThreadPolicy, ProcessorBoundThreadPolicy

public abstract class AbstractThreadPolicy
extends java.lang.Object
implements ThreadPolicy, java.lang.Runnable

The AbstractThreadPolicy keeps track of wether the management thread is running or not, and stores the ThreadManager for future use.


Field Summary
private  ThreadManager m_manager
           
private  boolean m_running
           
 
Constructor Summary
AbstractThreadPolicy()
           
 
Method Summary
protected  void endLoop()
          Provide a hook to do further cleanup when we end the management loop.
 void executeLoop(ThreadManager manager)
          Take care of the standard checks that need to be in place, and then delegate to the startLoop() method to do any further initialization.
 boolean isRunning()
          Returns whether this ThreadPolicy is currently running or not.
protected abstract  void process(java.util.Collection pipelines)
          Do the actual management logic that needs to be done in each time through the main loop.
 void run()
          Do the actual looping code.
protected abstract  void startLoop()
          Provide a hook to do further initialization when we start the management loop.
 void terminateLoop()
          Stops the loop and calls the endLoop() method to do any further tear down.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.d_haven.event.command.ThreadPolicy
createRunner, setThreadFactory
 

Field Detail

m_manager

private ThreadManager m_manager

m_running

private volatile boolean m_running
Constructor Detail

AbstractThreadPolicy

public AbstractThreadPolicy()
Method Detail

executeLoop

public void executeLoop(ThreadManager manager)
                 throws java.lang.InterruptedException
Take care of the standard checks that need to be in place, and then delegate to the startLoop() method to do any further initialization.

Specified by:
executeLoop in interface ThreadPolicy
Parameters:
manager - the ThreadManager to run the pipelines through
Throws:
java.lang.InterruptedException - if the calling thread is interrupted

isRunning

public boolean isRunning()
Returns whether this ThreadPolicy is currently running or not.

Specified by:
isRunning in interface ThreadPolicy
Returns:
true if the management thread is running

terminateLoop

public void terminateLoop()
                   throws java.lang.InterruptedException
Stops the loop and calls the endLoop() method to do any further tear down.

Specified by:
terminateLoop in interface ThreadPolicy
Throws:
java.lang.InterruptedException - if the calling thread is interrupted

run

public void run()
Do the actual looping code. The loop can handle any exceptoins that might happen in a consistent manner. Each time through the processing loop it will call the process(java.util.Collection) method.

Specified by:
run in interface java.lang.Runnable

process

protected abstract void process(java.util.Collection pipelines)
                         throws java.lang.Exception
Do the actual management logic that needs to be done in each time through the main loop.

Parameters:
pipelines - The pipelines to manage
Throws:
java.lang.Exception - if there is a problem or the thread is interrupted

startLoop

protected abstract void startLoop()
                           throws java.lang.InterruptedException
Provide a hook to do further initialization when we start the management loop. It is very important to remember to actually start the run() method. This object is Runnable so you can pass it in to a new thread.

Throws:
java.lang.InterruptedException - if the calling thread is interrupted

endLoop

protected void endLoop()
                throws java.lang.InterruptedException
Provide a hook to do further cleanup when we end the management loop.

Throws:
java.lang.InterruptedException - if the calling thread is interrupted