public class BlockingQueueConsumer<T> extends java.lang.Object implements QueueConsumer<T>
BlockingQueue
Constructor and Description |
---|
BlockingQueueConsumer(ConnectionStateListener connectionStateListener)
Creates with capacity of
Integer.MAX_VALUE |
BlockingQueueConsumer(ConnectionStateListener connectionStateListener,
java.util.concurrent.BlockingQueue<T> queue)
Wrap the given blocking queue
|
BlockingQueueConsumer(ConnectionStateListener connectionStateListener,
int capacity) |
Modifier and Type | Method and Description |
---|---|
void |
consumeMessage(T message)
Process a message from the queue
|
int |
drainTo(java.util.Collection<? super T> c)
Removes all available elements from this queue and adds them
to the given collection.
|
java.util.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(CuratorFramework client,
ConnectionState newState)
Called when there is a state change in the connection
|
T |
take()
Take the next item from the queue, blocking until there is an item available
|
T |
take(int time,
java.util.concurrent.TimeUnit unit)
Take the next item from the queue, waiting up to the specified time for
an available item.
|
public BlockingQueueConsumer(ConnectionStateListener connectionStateListener)
Integer.MAX_VALUE
connectionStateListener
- listener for connection state changespublic BlockingQueueConsumer(ConnectionStateListener connectionStateListener, int capacity)
capacity
- max capacity (i.e. puts block if full)connectionStateListener
- listener for connection state changespublic BlockingQueueConsumer(ConnectionStateListener connectionStateListener, java.util.concurrent.BlockingQueue<T> queue)
queue
- queue to useconnectionStateListener
- listener for connection state changespublic void consumeMessage(T message) throws java.lang.Exception
QueueConsumer
consumeMessage
in interface QueueConsumer<T>
message
- message to processjava.lang.Exception
- any errorspublic java.util.List<T> getItems()
public int size()
public T take() throws java.lang.InterruptedException
java.lang.InterruptedException
- thread interruptionpublic T take(int time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
null
is returned.time
- amount of time to blockunit
- time unitjava.lang.InterruptedException
- thread interruptionpublic int drainTo(java.util.Collection<? super T> c)
c
- the collection to transfer elements intojava.lang.UnsupportedOperationException
- if addition of elements
is not supported by the specified collectionjava.lang.ClassCastException
- if the class of an element of this queue
prevents it from being added to the specified collectionjava.lang.NullPointerException
- if the specified collection is nulljava.lang.IllegalArgumentException
- 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(CuratorFramework client, ConnectionState newState)
ConnectionStateListener
stateChanged
in interface ConnectionStateListener
client
- the clientnewState
- the new state