Package com.tnsai.coordination
Class TaskQueue
java.lang.Object
com.tnsai.coordination.TaskQueue
Thread-safe priority-based task queue for orchestrator-worker pattern.
Tasks with higher priority are dequeued first.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all tasks from the queue.dequeue()Retrieves and removes the highest priority task from the queue.Retrieves and removes the highest priority task from the queue.voidAdds a task to the queue.getName()booleanisEmpty()Checks if the queue is empty.intsize()Returns the number of tasks in the queue.toString()
-
Constructor Details
-
TaskQueue
-
-
Method Details
-
enqueue
Adds a task to the queue. Non-blocking operation.- Parameters:
task- the task to add
-
dequeue
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
Retrieves and removes the highest priority task from the queue. Waits up to the specified timeout.- Parameters:
timeout- the maximum time to waitunit- 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
-
toString
-