Class UniqueJobQueue<T extends Job>

java.lang.Object
org.pepsoft.util.jobqueue.UniqueJobQueue<T>

public class UniqueJobQueue<T extends Job> extends Object
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 Details

    • UniqueJobQueue

      public UniqueJobQueue()
  • Method Details

    • takeJob

      public T takeJob() throws InterruptedException
      Blocking.
      Throws:
      InterruptedException
    • pollJob

      public T pollJob()
      Non-blocking.
    • scheduleJobIfNotScheduled

      public boolean scheduleJobIfNotScheduled(T job)
      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:
      true if the job was scheduled, false if it already was on the queue.
    • rescheduleJob

      public boolean rescheduleJob(T job)
      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:
      true if the job already existed on the queue, false if it did not.
    • removeJob

      public boolean removeJob(T job)
      Remove a job from the queue if it has not already been executed.
      Parameters:
      job - The job to remove.
      Returns:
      true if the job was still on the queue and has been removed.
    • drain

      public void drain() throws InterruptedException
      Block until the queue is empty.
      Throws:
      InterruptedException
    • clear

      public void clear()
      Empty the queue.