Class DistributedDelayQueue<T>
java.lang.Object
org.apache.curator.framework.recipes.queue.DistributedDelayQueue<T>
- All Implemented Interfaces:
Closeable,AutoCloseable,QueueBase<T>
A variation of the DistributedPriorityQueue that uses time as the priority. When items are added to the queue, a delay value is given. The item will not be sent to a consumer until the time elapses.
-
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, long)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, long)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 adddelayUntilEpoch- future epoch (milliseconds) when this item will be available to consumers- Throws:
Exception- connection issues
-
put
Same asput(Object, long)but allows a maximum wait time if an upper bound was set viaQueueBuilder.maxItems.- Parameters:
item- item to adddelayUntilEpoch- future epoch (milliseconds) when this item will be available to consumersmaxWait- 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 adddelayUntilEpoch- future epoch (milliseconds) when this item will be available to consumers- Throws:
Exception- connection issues
-
putMulti
public boolean putMulti(MultiItem<T> items, long delayUntilEpoch, int maxWait, TimeUnit unit) throws Exception Same asputMulti(MultiItem, long)but allows a maximum wait time if an upper bound was set viaQueueBuilder.maxItems.- Parameters:
items- items to adddelayUntilEpoch- future epoch (milliseconds) when this item will be available to consumersmaxWait- 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)
-