Class DistributedIdQueue<T>

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

public class DistributedIdQueue<T> extends Object implements QueueBase<T>
A version of DistributedQueue that allows IDs to be associated with queue items. Items can then be removed from the queue if needed
  • Method Details

    • start

      public void start() throws Exception
      Description copied from interface: QueueBase
      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
    • getPutListenerContainer

      public Listenable<QueuePutListener<T>> getPutListenerContainer()
      Description copied from interface: QueueBase
      Return the manager for put listeners
      Specified by:
      getPutListenerContainer in interface QueueBase<T>
      Returns:
      put listener container
    • 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
    • getLastMessageCount

      public int getLastMessageCount()
      Description copied from interface: QueueBase
      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)
    • put

      public void put(T item, String itemId) throws Exception
      Put an item into the queue with the given Id

      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
      itemId - item Id
      Throws:
      Exception - errors
    • put

      public boolean put(T item, String itemId, int maxWait, TimeUnit unit) throws Exception
      Same as put(Object, String) but allows a maximum wait time if an upper bound was set via QueueBuilder.maxItems.
      Parameters:
      item - item
      itemId - item Id
      maxWait - maximum wait
      unit - wait unit
      Returns:
      true if items was added, false if timed out
      Throws:
      Exception
    • remove

      public int remove(String id) throws Exception
      Remove any items with the given Id
      Parameters:
      id - item Id to remove
      Returns:
      number of items removed
      Throws:
      Exception - errors