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 TypeMethodDescriptionvoid
close()
boolean
Wait until any pending puts are committedint
Return the most recent message count from the queue.Return the manager for put listenersvoid
Add an item into the queue.boolean
Same asput(Object, int)
but allows a maximum wait time if an upper bound was set viaQueueBuilder.maxItems
.void
Add a set of items with the same priority into the queue.boolean
Same asputMulti(MultiItem, int)
but allows a maximum wait time if an upper bound was set viaQueueBuilder.maxItems
.void
setErrorMode
(ErrorMode newErrorMode) Used when the queue is created with aQueueBuilder.lockPath(String)
.void
start()
Start the queue.
-
Method Details
-
start
Start the queue. No other methods work until this is called -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in 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:QueueBase
Used when the queue is created with aQueueBuilder.lockPath(String)
. Determines the behavior when the queue consumer throws an exception- Specified by:
setErrorMode
in interfaceQueueBase<T>
- Parameters:
newErrorMode
- the new error mode (the default isErrorMode.REQUEUE
-
flushPuts
Description copied from interface:QueueBase
Wait until any pending puts are committed- Specified by:
flushPuts
in 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:
getPutListenerContainer
in 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:
getLastMessageCount
in interfaceQueueBase<T>
- Returns:
- count (can be 0)
-