Note when shutdown has been requested and refuse to accept further units from

that time, rather than from the time that the shutdown is actually processed.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2525 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
samskivert
2009-02-01 22:51:24 +00:00
parent bdd3f45d29
commit bb53933b74
+16 -2
View File
@@ -144,8 +144,8 @@ public class Invoker extends LoopingThread
*/
public void postUnit (Unit unit)
{
if (!isRunning()) {
throw new IllegalStateException("Invoker has been shutdown");
if (!shutdownRequested()) {
throw new IllegalStateException("Cannot post units to shutdown invoker.");
}
// note the time
unit.queueStamp = System.currentTimeMillis();
@@ -211,6 +211,7 @@ public class Invoker extends LoopingThread
@Override
public void shutdown ()
{
_shutdownRequested = true;
_queue.append(new Unit() {
@Override public boolean invoke () {
_running = false;
@@ -231,6 +232,15 @@ public class Invoker extends LoopingThread
_profileBucketCount = bucketCount;
}
/**
* Returns true if {@link #shutdown} has been called. {@link #isRunning} may still return true
* until the shutdown unit is reached and processed by the invoker thread.
*/
protected boolean shutdownRequested ()
{
return _shutdownRequested;
}
/**
* Called before we process an invoker unit.
*
@@ -328,6 +338,10 @@ public class Invoker extends LoopingThread
/** The duration of time after which we consider a unit to be delinquent and log a warning. */
protected static long _defaultLongThreshold = 500L;
/** True after {@link #shutdown} has been called but before the invoker has finished processing
* any remaining queued units. */
protected volatile boolean _shutdownRequested;
/** Whether or not to track invoker unit performance. */
protected static final boolean PERF_TRACK = true;
}