Class TaskQueue

java.lang.Object
com.tnsai.coordination.TaskQueue

public class TaskQueue extends Object
Thread-safe priority-based task queue for orchestrator-worker pattern. Tasks with higher priority are dequeued first.
  • Constructor Details

    • TaskQueue

      public TaskQueue(String name)
  • Method Details

    • enqueue

      public void enqueue(Task task)
      Adds a task to the queue. Non-blocking operation.
      Parameters:
      task - the task to add
    • dequeue

      public Task dequeue() throws InterruptedException
      Retrieves and removes the highest priority task from the queue. Blocks until a task is available.
      Returns:
      the next task
      Throws:
      InterruptedException - if interrupted while waiting
    • dequeue

      public Task dequeue(long timeout, TimeUnit unit) throws InterruptedException
      Retrieves and removes the highest priority task from the queue. Waits up to the specified timeout.
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit
      Returns:
      the next task, or null if timeout
      Throws:
      InterruptedException - if interrupted while waiting
    • size

      public int size()
      Returns the number of tasks in the queue.
      Returns:
      queue size
    • isEmpty

      public boolean isEmpty()
      Checks if the queue is empty.
      Returns:
      true if empty
    • clear

      public void clear()
      Clears all tasks from the queue.
    • getName

      public String getName()
    • toString

      public String toString()
      Overrides:
      toString in class Object