Class PriorityQueueScheduler

  • All Implemented Interfaces:
    Scheduler, java.lang.Iterable<Job>, java.util.Collection<Job>, java.util.concurrent.BlockingQueue<Job>, java.util.Queue<Job>

    public class PriorityQueueScheduler
    extends AbstractQueueScheduler
    This class provides and implementation of scheduler with a priority sensitive queue.

    Jobs with higher priority will be processed first.

    Author:
    Maksim Tkachenko, Ween Jiann Lee
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(Request r, Handler h, Priority p, Priority pf)
      Adds a request to the queue.
      boolean offer​(Job job, long timeout, java.util.concurrent.TimeUnit unit)  
      Job poll()  
      Job poll​(long timeout, java.util.concurrent.TimeUnit unit)  
      void put​(Job job)  
      • Methods inherited from class java.util.AbstractQueue

        add, addAll, clear, element, remove
      • Methods inherited from class java.util.AbstractCollection

        contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.concurrent.BlockingQueue

        add, contains, remove
      • Methods inherited from interface java.util.Collection

        addAll, clear, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Queue

        element, remove
    • Constructor Detail

      • PriorityQueueScheduler

        public PriorityQueueScheduler()
    • Method Detail

      • add

        public final void add​(Request r,
                              Handler h,
                              Priority p,
                              Priority pf)
        Description copied from interface: Scheduler
        Adds a request to the queue.

        This request would be parsed by the handler specified, and its priority can be downgraded to a minimum priority specified.

        Parameters:
        r - request to fetch when dequeued
        h - handler to be used to parse the request
        p - initial priority of the request
        pf - the minimum (floor) priority of this request
      • put

        public final void put​(@Nonnull
                              Job job)
      • offer

        public final boolean offer​(Job job,
                                   long timeout,
                                   @Nonnull
                                   java.util.concurrent.TimeUnit unit)
      • poll

        public final Job poll​(long timeout,
                              @Nonnull
                              java.util.concurrent.TimeUnit unit)
                       throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • poll

        public final Job poll()