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 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, long)
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, long)
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 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: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)
-