Package editor.util

Class 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.

    • 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.
        Specified by:
        run in interface Runnable
        Overrides:
        run in class Thread
      • 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)