Added isRunning() to RunQueue, made BasicRunQueue work both in separate-thread
mode and in just-call-run()-yourself mode. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2473 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -45,19 +45,26 @@ public class BasicRunQueue extends LoopingThread
|
||||
_queue = new Queue<Runnable>();
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
// from interface RunQueue
|
||||
public void postRunnable (Runnable r)
|
||||
{
|
||||
_queue.append(r);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
// from interface RunQueue
|
||||
public boolean isDispatchThread ()
|
||||
{
|
||||
return Thread.currentThread() == this;
|
||||
return Thread.currentThread() == _dispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override // from LoopingThread
|
||||
protected void willStart ()
|
||||
{
|
||||
super.willStart();
|
||||
_dispatcher = Thread.currentThread();
|
||||
}
|
||||
|
||||
@Override // from LoopingThread
|
||||
protected void iterate ()
|
||||
{
|
||||
Runnable r = _queue.get();
|
||||
@@ -69,7 +76,7 @@ public class BasicRunQueue extends LoopingThread
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override // from LoopingThread
|
||||
protected void kick ()
|
||||
{
|
||||
postRunnable(new Runnable() {
|
||||
@@ -81,4 +88,8 @@ public class BasicRunQueue extends LoopingThread
|
||||
|
||||
/** The queue of things to run. */
|
||||
protected Queue<Runnable> _queue;
|
||||
|
||||
/** Our dispatcher thread (may == this or may be something else if we're being used directly
|
||||
* rather than in separate thread mode). */
|
||||
protected Thread _dispatcher;
|
||||
}
|
||||
|
||||
@@ -29,22 +29,29 @@ public interface RunQueue
|
||||
{
|
||||
/** A useful RunQueue that uses the AWT dispatch thread. */
|
||||
public static final RunQueue AWT = new RunQueue() {
|
||||
public void postRunnable (Runnable r) {
|
||||
EventQueue.invokeLater(r);
|
||||
}
|
||||
|
||||
public boolean isDispatchThread () {
|
||||
return EventQueue.isDispatchThread();
|
||||
}
|
||||
};
|
||||
public void postRunnable (Runnable r) {
|
||||
EventQueue.invokeLater(r);
|
||||
}
|
||||
public boolean isDispatchThread () {
|
||||
return EventQueue.isDispatchThread();
|
||||
}
|
||||
public boolean isRunning () {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Post the specified Runnable to be run on the RunQueue.
|
||||
*/
|
||||
public void postRunnable (Runnable r);
|
||||
void postRunnable (Runnable r);
|
||||
|
||||
/**
|
||||
* @return true if the calling thread is the RunQueue dispatch thread.
|
||||
*/
|
||||
public boolean isDispatchThread ();
|
||||
boolean isDispatchThread ();
|
||||
|
||||
/**
|
||||
* @return true if this run queue is still processing runnables, false if it has been shutdown.
|
||||
*/
|
||||
boolean isRunning ();
|
||||
}
|
||||
|
||||
@@ -98,6 +98,11 @@ public class SerialExecutorTest extends TestCase
|
||||
return Thread.currentThread() == _main;
|
||||
}
|
||||
|
||||
public boolean isRunning ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Test suite ()
|
||||
{
|
||||
return new SerialExecutorTest();
|
||||
|
||||
Reference in New Issue
Block a user