Class DistributedPriorityQueue<T>
java.lang.Object
org.apache.curator.framework.recipes.queue.DistributedPriorityQueue<T>
- All Implemented Interfaces:
Closeable,AutoCloseable,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
Modifier and TypeMethodDescriptionvoidclose()booleanWait until any pending puts are committedintReturn the most recent message count from the queue.Return the manager for put listenersvoidAdd an item into the queue.booleanSame asput(Object, int)but allows a maximum wait time if an upper bound was set viaQueueBuilder.maxItems.voidAdd a set of items with the same priority into the queue.booleanSame asputMulti(MultiItem, int)but allows a maximum wait time if an upper bound was set viaQueueBuilder.maxItems.voidsetErrorMode(ErrorMode newErrorMode) Used when the queue is created with aQueueBuilder.lockPath(String).voidstart()Start the queue.
-
Method Details
-
start
Start the queue. No other methods work until this is called -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
put
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 viaQueueBuilder.maxItems, this method will block until there is available space in the queue.- Parameters:
item- item to addpriority- item's priority - lower numbers come out of the queue first- Throws:
Exception- connection issues
-
put
Same asput(Object, int)but allows a maximum wait time if an upper bound was set viaQueueBuilder.maxItems.- Parameters:
item- item to addpriority- item's priority - lower numbers come out of the queue firstmaxWait- maximum waitunit- wait unit- Returns:
- true if items was added, false if timed out
- Throws:
Exception
-
putMulti
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 viaQueueBuilder.maxItems, this method will block until there is available space in the queue.- Parameters:
items- items to addpriority- item priority - lower numbers come out of the queue first- Throws:
Exception- connection issues
-
putMulti
public boolean putMulti(MultiItem<T> items, int priority, int maxWait, TimeUnit unit) throws Exception Same asputMulti(MultiItem, int)but allows a maximum wait time if an upper bound was set viaQueueBuilder.maxItems.- Parameters:
items- items to addpriority- item priority - lower numbers come out of the queue firstmaxWait- maximum waitunit- wait unit- Returns:
- true if items was added, false if timed out
- Throws:
Exception
-
setErrorMode
Description copied from interface:QueueBaseUsed when the queue is created with aQueueBuilder.lockPath(String). Determines the behavior when the queue consumer throws an exception- Specified by:
setErrorModein interfaceQueueBase<T>- Parameters:
newErrorMode- the new error mode (the default isErrorMode.REQUEUE
-
flushPuts
Description copied from interface:QueueBaseWait until any pending puts are committed- Specified by:
flushPutsin interfaceQueueBase<T>- Parameters:
waitTime- max wait timetimeUnit- time unit- Returns:
- true if the flush was successful, false if it timed out first
- Throws:
InterruptedException- if thread was interrupted
-
getPutListenerContainer
Return the manager for put listeners- Specified by:
getPutListenerContainerin interfaceQueueBase<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:
getLastMessageCountin interfaceQueueBase<T>- Returns:
- count (can be 0)
-