public class BlockingQueueConsumer<T> extends Object implements QueueConsumer<T>
BlockingQueue| Constructor and Description |
|---|
BlockingQueueConsumer(org.apache.curator.framework.state.ConnectionStateListener connectionStateListener)
Creates with capacity of
Integer.MAX_VALUE |
BlockingQueueConsumer(org.apache.curator.framework.state.ConnectionStateListener connectionStateListener,
BlockingQueue<T> queue)
Wrap the given blocking queue
|
BlockingQueueConsumer(org.apache.curator.framework.state.ConnectionStateListener connectionStateListener,
int capacity) |
| Modifier and Type | Method and Description |
|---|---|
void |
consumeMessage(T message)
Process a message from the queue
|
int |
drainTo(Collection<? super T> c)
Removes all available elements from this queue and adds them
to the given collection.
|
List<T> |
getItems()
Return any currently queued items without removing them from the queue
|
int |
size()
Returns the number of currently queue items
|
void |
stateChanged(org.apache.curator.framework.CuratorFramework client,
org.apache.curator.framework.state.ConnectionState newState) |
T |
take()
Take the next item from the queue, blocking until there is an item available
|
T |
take(int time,
TimeUnit unit)
Take the next item from the queue, waiting up to the specified time for
an available item.
|
public BlockingQueueConsumer(org.apache.curator.framework.state.ConnectionStateListener connectionStateListener)
Integer.MAX_VALUEconnectionStateListener - listener for connection state changespublic BlockingQueueConsumer(org.apache.curator.framework.state.ConnectionStateListener connectionStateListener,
int capacity)
capacity - max capacity (i.e. puts block if full)connectionStateListener - listener for connection state changespublic BlockingQueueConsumer(org.apache.curator.framework.state.ConnectionStateListener connectionStateListener,
BlockingQueue<T> queue)
queue - queue to useconnectionStateListener - listener for connection state changespublic void consumeMessage(T message) throws Exception
QueueConsumerconsumeMessage in interface QueueConsumer<T>message - message to processException - any errorspublic List<T> getItems()
public int size()
public T take() throws InterruptedException
InterruptedException - thread interruptionpublic T take(int time, TimeUnit unit) throws InterruptedException
null is returned.time - amount of time to blockunit - time unitInterruptedException - thread interruptionpublic int drainTo(Collection<? super T> c)
c - the collection to transfer elements intoUnsupportedOperationException - if addition of elements
is not supported by the specified collectionClassCastException - if the class of an element of this queue
prevents it from being added to the specified collectionNullPointerException - if the specified collection is nullIllegalArgumentException - if the specified collection is this
queue, or some property of an element of this queue prevents
it from being added to the specified collectionpublic void stateChanged(org.apache.curator.framework.CuratorFramework client,
org.apache.curator.framework.state.ConnectionState newState)
stateChanged in interface org.apache.curator.framework.state.ConnectionStateListenerCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.