Class DistributedDelayQueue<T>
- java.lang.Object
-
- org.apache.curator.framework.recipes.queue.DistributedDelayQueue<T>
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,QueueBase<T>
public class DistributedDelayQueue<T> extends java.lang.Object implements java.io.Closeable, 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()booleanflushPuts(long waitTime, java.util.concurrent.TimeUnit timeUnit)Wait until any pending puts are committedintgetLastMessageCount()Return the most recent message count from the queue.org.apache.curator.framework.listen.ListenerContainer<QueuePutListener<T>>getPutListenerContainer()Return the manager for put listenersvoidput(T item, long delayUntilEpoch)Add an item into the queue.booleanput(T item, long delayUntilEpoch, int maxWait, java.util.concurrent.TimeUnit unit)Same asput(Object, long)but allows a maximum wait time if an upper bound was set viaQueueBuilder.maxItems.voidputMulti(MultiItem<T> items, long delayUntilEpoch)Add a set of items with the same priority into the queue.booleanputMulti(MultiItem<T> items, long delayUntilEpoch, int maxWait, java.util.concurrent.TimeUnit unit)Same 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 Detail
-
start
public void start() throws java.lang.ExceptionStart the queue. No other methods work until this is called
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
put
public void put(T item, long delayUntilEpoch) throws java.lang.Exception
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:
java.lang.Exception- connection issues
-
put
public boolean put(T item, long delayUntilEpoch, int maxWait, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
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:
java.lang.Exception
-
putMulti
public void putMulti(MultiItem<T> items, long delayUntilEpoch) throws java.lang.Exception
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:
java.lang.Exception- connection issues
-
putMulti
public boolean putMulti(MultiItem<T> items, long delayUntilEpoch, int maxWait, java.util.concurrent.TimeUnit unit) throws java.lang.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:
java.lang.Exception
-
setErrorMode
public void setErrorMode(ErrorMode newErrorMode)
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
public boolean flushPuts(long waitTime, java.util.concurrent.TimeUnit timeUnit) throws java.lang.InterruptedExceptionDescription copied from interface:QueueBaseWait until any pending puts are committed
-
getPutListenerContainer
public org.apache.curator.framework.listen.ListenerContainer<QueuePutListener<T>> 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)
-
-