Class DistributedIdQueue<T>

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, QueueBase<T>

    public class DistributedIdQueue<T>
    extends java.lang.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 Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      boolean flushPuts​(long waitTime, java.util.concurrent.TimeUnit timeUnit)
      Wait until any pending puts are committed
      int getLastMessageCount()
      Return the most recent message count from the queue.
      org.apache.curator.framework.listen.ListenerContainer<QueuePutListener<T>> getPutListenerContainer()
      Return the manager for put listeners
      void put​(T item, java.lang.String itemId)
      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.
      boolean put​(T item, java.lang.String itemId, int maxWait, java.util.concurrent.TimeUnit unit)
      Same as put(Object, String) but allows a maximum wait time if an upper bound was set via QueueBuilder.maxItems.
      int remove​(java.lang.String id)
      Remove any items with the given Id
      void setErrorMode​(ErrorMode newErrorMode)
      Used when the queue is created with a QueueBuilder.lockPath(String).
      void start()
      Start the queue.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • start

        public void start()
                   throws java.lang.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:
        java.lang.Exception - startup errors
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • getPutListenerContainer

        public org.apache.curator.framework.listen.ListenerContainer<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
      • flushPuts

        public boolean flushPuts​(long waitTime,
                                 java.util.concurrent.TimeUnit timeUnit)
                          throws java.lang.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:
        java.lang.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,
                        java.lang.String itemId)
                 throws java.lang.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:
        java.lang.Exception - errors
      • put

        public boolean put​(T item,
                           java.lang.String itemId,
                           int maxWait,
                           java.util.concurrent.TimeUnit unit)
                    throws java.lang.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:
        java.lang.Exception
      • remove

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