Class DistributedDelayQueue<T>

java.lang.Object
org.apache.curator.framework.recipes.queue.DistributedDelayQueue<T>
All Implemented Interfaces:
Closeable, AutoCloseable, QueueBase<T>

public class DistributedDelayQueue<T> extends Object implements Closeable, QueueBase<T>

A variation of the DistributedPriorityQueue that uses time as the priority. When items are added to the queue, a delay value is given. The item will not be sent to a consumer until the time elapses.

  • Method Details

    • start

      public void start() throws Exception
      Start the queue. No other methods work until this is called
      Specified by:
      start in interface QueueBase<T>
      Throws:
      Exception - startup errors
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • put

      public void put(T item, long delayUntilEpoch) throws Exception
      Add an item into the queue. Adding is done in the background - thus, this method will return quickly.

      NOTE: if an upper bound was set via QueueBuilder.maxItems, this method will block until there is available space in the queue.
      Parameters:
      item - item to add
      delayUntilEpoch - future epoch (milliseconds) when this item will be available to consumers
      Throws:
      Exception - connection issues
    • put

      public boolean put(T item, long delayUntilEpoch, int maxWait, TimeUnit unit) throws Exception
      Same as put(Object, long) but allows a maximum wait time if an upper bound was set via QueueBuilder.maxItems.
      Parameters:
      item - item to add
      delayUntilEpoch - future epoch (milliseconds) when this item will be available to consumers
      maxWait - maximum wait
      unit - wait unit
      Returns:
      true if items was added, false if timed out
      Throws:
      Exception
    • putMulti

      public void putMulti(MultiItem<T> items, long delayUntilEpoch) throws Exception
      Add a set of items with the same priority into the queue. Adding is done in the background - thus, this method will return quickly.

      NOTE: if an upper bound was set via QueueBuilder.maxItems, this method will block until there is available space in the queue.
      Parameters:
      items - items to add
      delayUntilEpoch - future epoch (milliseconds) when this item will be available to consumers
      Throws:
      Exception - connection issues
    • putMulti

      public boolean putMulti(MultiItem<T> items, long delayUntilEpoch, int maxWait, TimeUnit unit) throws Exception
      Same as putMulti(MultiItem, long) but allows a maximum wait time if an upper bound was set via QueueBuilder.maxItems.
      Parameters:
      items - items to add
      delayUntilEpoch - future epoch (milliseconds) when this item will be available to consumers
      maxWait - maximum wait
      unit - wait unit
      Returns:
      true if items was added, false if timed out
      Throws:
      Exception
    • setErrorMode

      public void setErrorMode(ErrorMode newErrorMode)
      Description copied from interface: QueueBase
      Used when the queue is created with a QueueBuilder.lockPath(String). Determines the behavior when the queue consumer throws an exception
      Specified by:
      setErrorMode in interface QueueBase<T>
      Parameters:
      newErrorMode - the new error mode (the default is ErrorMode.REQUEUE
    • flushPuts

      public boolean flushPuts(long waitTime, TimeUnit timeUnit) throws InterruptedException
      Description copied from interface: QueueBase
      Wait until any pending puts are committed
      Specified by:
      flushPuts in interface QueueBase<T>
      Parameters:
      waitTime - max wait time
      timeUnit - time unit
      Returns:
      true if the flush was successful, false if it timed out first
      Throws:
      InterruptedException - if thread was interrupted
    • getPutListenerContainer

      public Listenable<QueuePutListener<T>> getPutListenerContainer()
      Return the manager for put listeners
      Specified by:
      getPutListenerContainer in interface QueueBase<T>
      Returns:
      put listener container
    • getLastMessageCount

      public int getLastMessageCount()
      Return the most recent message count from the queue. This is useful for debugging/information purposes only.
      Specified by:
      getLastMessageCount in interface QueueBase<T>
      Returns:
      count (can be 0)