java.io.Closeable, java.lang.AutoCloseable, QueueBase<T>public class DistributedQueue<T> extends java.lang.Object implements QueueBase<T>
An implementation of the Distributed Queue ZK recipe. Items put into the queue are guaranteed to be ordered (by means of ZK's PERSISTENT_SEQUENTIAL node).
Guarantees:
LeaderSelector to nominate a single consumer.QueueBuilder.lockPath(String) is used, there is only guaranteed processing of each message to the point of receipt by a given instance.
QueueBuilder.lockPath(String)| Modifier and Type | Class | Description |
|---|---|---|
protected static class |
DistributedQueue.ProcessType |
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
|
boolean |
flushPuts(long waitTime,
java.util.concurrent.TimeUnit timeUnit) |
Wait until any pending puts are committed
|
protected java.util.List<java.lang.String> |
getChildren() |
|
protected long |
getDelay(java.lang.String itemNode) |
|
int |
getLastMessageCount() |
Return the most recent message count from the queue.
|
org.apache.curator.framework.listen.ListenerContainer<QueuePutListener<T>> |
getPutListenerContainer() |
Return the manager for put listeners
|
protected java.lang.String |
makeRequeueItemPath(java.lang.String itemPath) |
|
protected boolean |
processWithLockSafety(java.lang.String itemNode,
DistributedQueue.ProcessType type) |
|
void |
put(T item) |
Add an item into the queue.
|
boolean |
put(T item,
int maxWait,
java.util.concurrent.TimeUnit unit) |
Same as
put(Object) but allows a maximum wait time if an upper bound was set
via QueueBuilder.maxItems. |
void |
putMulti(MultiItem<T> items) |
Add a set of items into the queue.
|
boolean |
putMulti(MultiItem<T> items,
int maxWait,
java.util.concurrent.TimeUnit unit) |
Same as
putMulti(MultiItem) but allows a maximum wait time if an upper bound was set
via QueueBuilder.maxItems. |
void |
setErrorMode(ErrorMode newErrorMode) |
Used when the queue is created with a
QueueBuilder.lockPath(String). |
protected void |
sortChildren(java.util.List<java.lang.String> children) |
|
void |
start() |
Start the queue.
|
protected boolean |
tryRemove(java.lang.String itemNode) |
public void start()
throws java.lang.Exception
public void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.io.Closeablejava.io.IOExceptionpublic org.apache.curator.framework.listen.ListenerContainer<QueuePutListener<T>> getPutListenerContainer()
getPutListenerContainer in interface QueueBase<T>public void setErrorMode(ErrorMode newErrorMode)
QueueBuilder.lockPath(String). Determines
the behavior when the queue consumer throws an exceptionsetErrorMode in interface QueueBase<T>newErrorMode - the new error mode (the default is ErrorMode.REQUEUEpublic boolean flushPuts(long waitTime,
java.util.concurrent.TimeUnit timeUnit)
throws java.lang.InterruptedException
public void put(T item) throws java.lang.Exception
QueueBuilder.maxItems, this method will
block until there is available space in the queue.item - item to addjava.lang.Exception - connection issuespublic boolean put(T item, int maxWait, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
put(Object) but allows a maximum wait time if an upper bound was set
via QueueBuilder.maxItems.item - item to addmaxWait - maximum waitunit - wait unitjava.lang.Exceptionpublic void putMulti(MultiItem<T> items) throws java.lang.Exception
QueueBuilder.maxItems, this method will
block until there is available space in the queue.items - items to addjava.lang.Exception - connection issuespublic boolean putMulti(MultiItem<T> items, int maxWait, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
putMulti(MultiItem) but allows a maximum wait time if an upper bound was set
via QueueBuilder.maxItems.items - items to addmaxWait - maximum waitunit - wait unitjava.lang.Exceptionpublic int getLastMessageCount()
getLastMessageCount in interface QueueBase<T>protected void sortChildren(java.util.List<java.lang.String> children)
protected java.util.List<java.lang.String> getChildren()
throws java.lang.Exception
java.lang.Exceptionprotected long getDelay(java.lang.String itemNode)
protected boolean tryRemove(java.lang.String itemNode)
throws java.lang.Exception
java.lang.Exceptionprotected boolean processWithLockSafety(java.lang.String itemNode,
DistributedQueue.ProcessType type)
throws java.lang.Exception
java.lang.Exceptionprotected java.lang.String makeRequeueItemPath(java.lang.String itemPath)
Copyright © 2011–2018 The Apache Software Foundation. All rights reserved.