com.netflix.curator.framework.recipes.queue
Class DistributedPriorityQueue<T>

java.lang.Object
  extended by com.netflix.curator.framework.recipes.queue.DistributedPriorityQueue<T>
All Implemented Interfaces:
QueueBase<T>, java.io.Closeable

public class DistributedPriorityQueue<T>
extends java.lang.Object
implements java.io.Closeable, QueueBase<T>

An implementation of the Distributed Priority Queue ZK recipe.

Internally, this uses a DistributedQueue. The only difference is that you specify a priority when putting into the queue.

IMPORTANT NOTE: The priority queue will perform far worse than a standard queue. Every time an item is added to/removed from the queue, every watcher must re-get all the nodes


Method Summary
 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.
 com.netflix.curator.framework.listen.ListenerContainer<QueuePutListener<T>> getPutListenerContainer()
          Return the manager for put listeners
 void put(T item, int priority)
          Add an item into the queue.
 boolean put(T item, int priority, int maxWait, java.util.concurrent.TimeUnit unit)
          Same as put(Object, int) but allows a maximum wait time if an upper bound was set via QueueBuilder.maxItems.
 void putMulti(MultiItem<T> items, int priority)
          Add a set of items with the same priority into the queue.
 boolean putMulti(MultiItem<T> items, int priority, int maxWait, java.util.concurrent.TimeUnit unit)
          Same as putMulti(MultiItem, int) but allows a maximum wait time if an upper bound was set via QueueBuilder.maxItems.
 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
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.io.Closeable
Throws:
java.io.IOException

put

public void put(T item,
                int priority)
         throws java.lang.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
priority - item's priority - lower numbers come out of the queue first
Throws:
java.lang.Exception - connection issues

put

public boolean put(T item,
                   int priority,
                   int maxWait,
                   java.util.concurrent.TimeUnit unit)
            throws java.lang.Exception
Same as put(Object, int) but allows a maximum wait time if an upper bound was set via QueueBuilder.maxItems.

Parameters:
item - item to add
priority - item's priority - lower numbers come out of the queue first
maxWait - maximum wait
unit - wait unit
Returns:
true if items was added, false if timed out
Throws:
java.lang.Exception

putMulti

public void putMulti(MultiItem<T> items,
                     int priority)
              throws java.lang.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
priority - item priority - lower numbers come out of the queue first
Throws:
java.lang.Exception - connection issues

putMulti

public boolean putMulti(MultiItem<T> items,
                        int priority,
                        int maxWait,
                        java.util.concurrent.TimeUnit unit)
                 throws java.lang.Exception
Same as putMulti(MultiItem, int) but allows a maximum wait time if an upper bound was set via QueueBuilder.maxItems.

Parameters:
items - items to add
priority - item priority - lower numbers come out of the queue first
maxWait - maximum wait
unit - wait unit
Returns:
true if items was added, false if timed out
Throws:
java.lang.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,
                         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

getPutListenerContainer

public com.netflix.curator.framework.listen.ListenerContainer<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)