Package editor.util
Class TaskQueue
- java.lang.Object
-
- java.lang.Thread
-
- editor.util.TaskQueue
-
- All Implemented Interfaces:
Runnable
public class TaskQueue extends Thread
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
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancelTasks(Class taskClass)static voidemptyAndRemoveQueue(String strQueueName)Clears all the inactive tasks in the specified queue.voidemptyQueue()Empty the queuestatic TaskQueuegetInstance(ILogger logger, String strQueueName)Fetch a TaskQueue by name.static TaskQueuegetInstance(String strQueueName)Fetch a TaskQueue by name.List<Runnable>getTasks()Get a list of all the tasks in this TaskQueue.static booleanhasWork()static voidkillAll()Stops all task queues and dumps thier queue.protected voidlog(Throwable t)Log an exception or error.RunnablepeekTask()Peek at the "current" task in the queue.voidpostTask(Runnable task)Posts a task to the queue (asynchronously).voidpostTaskAndWait(Runnable runnable)voidpostTaskAndWait(Runnable runnable, long timeout)voidrun()Do NOT ever call this! Public only by contract.voidsetILogger(ILogger logger)intsize()Get the size of the queue at the instance this is called.voidwaitUntilAllCurrentTasksFinish()-
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
-
-
-
-
Method Detail
-
getInstance
public static TaskQueue getInstance(String strQueueName)
Fetch a TaskQueue by name. If the TaskQueue doesn't already exist, creates the TaskQueue.
-
getInstance
public static TaskQueue getInstance(ILogger logger, String strQueueName)
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
public static void emptyAndRemoveQueue(String strQueueName)
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
public void postTask(Runnable task)
Posts a task to the queue (asynchronously).- Parameters:
task- A task to run in the TaskQueue's thread.
-
waitUntilAllCurrentTasksFinish
public void waitUntilAllCurrentTasksFinish()
-
peekTask
public Runnable peekTask()
Peek at the "current" task in the queue. It may or may not be running.- Returns:
- The "current" task in the queue.
-
getTasks
public List<Runnable> 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
protected void log(Throwable t)
Log an exception or error.
-
hasWork
public static boolean hasWork()
-
postTaskAndWait
public void postTaskAndWait(Runnable runnable, long timeout)
-
postTaskAndWait
public void postTaskAndWait(Runnable runnable)
-
cancelTasks
public void cancelTasks(Class taskClass)
-
setILogger
public void setILogger(ILogger logger)
-
-