public class DistributedQueue<T> extends 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 and Description |
---|---|
protected static class |
DistributedQueue.ProcessType |
Modifier and Type | Method and Description |
---|---|
void |
close() |
boolean |
flushPuts(long waitTime,
TimeUnit timeUnit)
Wait until any pending puts are committed
|
protected List<String> |
getChildren() |
protected long |
getDelay(String itemNode) |
int |
getLastMessageCount()
Return the most recent message count from the queue.
|
Listenable<QueuePutListener<T>> |
getPutListenerContainer()
Return the manager for put listeners
|
protected String |
makeRequeueItemPath(String itemPath) |
protected boolean |
processWithLockSafety(String itemNode,
DistributedQueue.ProcessType type) |
void |
put(T item)
Add an item into the queue.
|
boolean |
put(T item,
int maxWait,
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,
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(List<String> children) |
void |
start()
Start the queue.
|
protected boolean |
tryRemove(String itemNode) |
public void start() throws Exception
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public Listenable<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.REQUEUE
public boolean flushPuts(long waitTime, TimeUnit timeUnit) throws InterruptedException
flushPuts
in interface QueueBase<T>
waitTime
- max wait timetimeUnit
- time unitInterruptedException
- if thread was interruptedpublic void put(T item) throws Exception
QueueBuilder.maxItems
, this method will
block until there is available space in the queue.item
- item to addException
- connection issuespublic boolean put(T item, int maxWait, TimeUnit unit) throws 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 unitException
public void putMulti(MultiItem<T> items) throws Exception
QueueBuilder.maxItems
, this method will
block until there is available space in the queue.items
- items to addException
- connection issuespublic boolean putMulti(MultiItem<T> items, int maxWait, TimeUnit unit) throws 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 unitException
public int getLastMessageCount()
getLastMessageCount
in interface QueueBase<T>
protected long getDelay(String itemNode)
protected boolean processWithLockSafety(String itemNode, DistributedQueue.ProcessType type) throws Exception
Exception
Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.