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
Modifier and Type | Method and 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.
|
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.
|
public void start() throws java.lang.Exception
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public void put(T item, int priority) throws java.lang.Exception
QueueBuilder.maxItems
, this method will
block until there is available space in the queue.item
- item to addpriority
- item's priority - lower numbers come out of the queue firstjava.lang.Exception
- connection issuespublic boolean put(T item, int priority, int maxWait, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
put(Object, int)
but allows a maximum wait time if an upper bound was set
via QueueBuilder.maxItems
.item
- item to addpriority
- item's priority - lower numbers come out of the queue firstmaxWait
- maximum waitunit
- wait unitjava.lang.Exception
public void putMulti(MultiItem<T> items, int priority) throws java.lang.Exception
QueueBuilder.maxItems
, this method will
block until there is available space in the queue.items
- items to addpriority
- item priority - lower numbers come out of the queue firstjava.lang.Exception
- connection issuespublic boolean putMulti(MultiItem<T> items, int priority, int maxWait, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
putMulti(MultiItem, int)
but allows a maximum wait time if an upper bound was set
via QueueBuilder.maxItems
.items
- items to addpriority
- item priority - lower numbers come out of the queue firstmaxWait
- maximum waitunit
- wait unitjava.lang.Exception
public void setErrorMode(ErrorMode newErrorMode)
QueueBase
QueueBuilder.lockPath(String)
. Determines
the behavior when the queue consumer throws an exceptionsetErrorMode
in interface QueueBase<T>
newErrorMode
- the new error mode (the default is ErrorMode.REQUEUE
public boolean flushPuts(long waitTime, java.util.concurrent.TimeUnit timeUnit) throws java.lang.InterruptedException
QueueBase
public ListenerContainer<QueuePutListener<T>> getPutListenerContainer()
getPutListenerContainer
in interface QueueBase<T>
public int getLastMessageCount()
getLastMessageCount
in interface QueueBase<T>