Package editor.util
Class TaskQueue
java.lang.Object
java.lang.Thread
editor.util.TaskQueue
- All Implemented Interfaces:
Runnable
A general purpose concurrent task queue. Facilitates creating named queues
containing any number of Runnable tasks. A task is posted to its queue
asynchronously. Each queue maintains a single thread and tasks are executed
in the order they are posted.
Improvements to this class might include some sort of priority scheduling
for tasks. For now they execute with equal priority.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ILogger
private final LinkedList<Runnable>
private boolean
A static map of the uniquely named queues.Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancelTasks
(Class taskClass) static void
emptyAndRemoveQueue
(String strQueueName) Clears all the inactive tasks in the specified queue.void
Empty the queuestatic TaskQueue
getInstance
(ILogger logger, String strQueueName) Fetch a TaskQueue by name.static TaskQueue
getInstance
(String strQueueName) Fetch a TaskQueue by name.getTasks()
Get a list of all the tasks in this TaskQueue.static boolean
hasWork()
static void
killAll()
Stops all task queues and dumps thier queue.protected void
Log an exception or error.peekTask()
Peek at the "current" task in the queue.void
Posts a task to the queue (asynchronously).void
postTaskAndWait
(Runnable runnable) void
postTaskAndWait
(Runnable runnable, long timeout) void
run()
Do NOT ever call this! Public only by contract.void
setILogger
(ILogger logger) int
size()
Get the size of the queue at the instance this is called.void
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Field Details
-
QUEUE_MAP
A static map of the uniquely named queues. -
_logger
-
_queue
-
_shutdown
private boolean _shutdown
-
-
Constructor Details
-
TaskQueue
Use one of the getInstance() methods to create a TaskQueue.
-
-
Method Details
-
getInstance
Fetch a TaskQueue by name. If the TaskQueue doesn't already exist, creates the TaskQueue. -
getInstance
Fetch a TaskQueue by name. If the TaskQueue doesn't already exist, creates the TaskQueue.- Parameters:
logger
- An optional logger.strQueueName
- The unique name for the queue.- Returns:
- The TaskQueue associated with the specified name.
-
emptyAndRemoveQueue
Clears all the inactive tasks in the specified queue. -
killAll
public static void killAll()Stops all task queues and dumps thier queue. This is a very dangerous method and should only be called from tests. -
postTask
Posts a task to the queue (asynchronously).- Parameters:
task
- A task to run in the TaskQueue's thread.
-
waitUntilAllCurrentTasksFinish
public void waitUntilAllCurrentTasksFinish() -
peekTask
Peek at the "current" task in the queue. It may or may not be running.- Returns:
- The "current" task in the queue.
-
getTasks
Get a list of all the tasks in this TaskQueue.- Returns:
- A cloned list of all the tasks in this TaskQueue.
-
emptyQueue
public void emptyQueue()Empty the queue -
size
public int size()Get the size of the queue at the instance this is called. -
run
public void run()Do NOT ever call this! Public only by contract. -
log
Log an exception or error. -
hasWork
public static boolean hasWork() -
postTaskAndWait
-
postTaskAndWait
-
cancelTasks
-
setILogger
-