Package org.pepsoft.util.jobqueue
Class UniqueJobQueue<T extends Job>
java.lang.Object
org.pepsoft.util.jobqueue.UniqueJobQueue<T>
A FIFO job queue where each job may only exist at most once in the queue.
What constitutes "the same job" is determined by the
Object.equals(java.lang.Object)
and Object.hashCode() methods of the job itself, and is therefore the
responsibility of the programmer.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Empty the queue.voiddrain()Block until the queue is empty.pollJob()Non-blocking.booleanRemove a job from the queue if it has not already been executed.booleanrescheduleJob(T job) Adds a job to the front of the queue.booleanAdds a job to the front of the queue, but only if it is not on the queue yet.takeJob()Blocking.
-
Constructor Details
-
UniqueJobQueue
public UniqueJobQueue()
-
-
Method Details
-
takeJob
Blocking.- Throws:
InterruptedException
-
pollJob
Non-blocking. -
scheduleJobIfNotScheduled
Adds a job to the front of the queue, but only if it is not on the queue yet.- Parameters:
job- The job to schedule.- Returns:
trueif the job was scheduled,falseif it already was on the queue.
-
rescheduleJob
Adds a job to the front of the queue. If the job was already on the queue the existing instance is removed.- Parameters:
job- The job to schedule.- Returns:
trueif the job already existed on the queue,falseif it did not.
-
removeJob
Remove a job from the queue if it has not already been executed.- Parameters:
job- The job to remove.- Returns:
trueif the job was still on the queue and has been removed.
-
drain
Block until the queue is empty.- Throws:
InterruptedException
-
clear
public void clear()Empty the queue.
-