Class BlockingQueueConsumer<T>
java.lang.Object
org.apache.curator.framework.recipes.queue.BlockingQueueConsumer<T>
- All Implemented Interfaces:
QueueConsumer<T>
,ConnectionStateListener
Utility - a queue consumer that provides behavior similar to a
BlockingQueue
-
Constructor Summary
ConstructorDescriptionBlockingQueueConsumer
(ConnectionStateListener connectionStateListener) Creates with capacity ofInteger.MAX_VALUE
BlockingQueueConsumer
(ConnectionStateListener connectionStateListener, int capacity) BlockingQueueConsumer
(ConnectionStateListener connectionStateListener, BlockingQueue<T> queue) Wrap the given blocking queue -
Method Summary
Modifier and TypeMethodDescriptionvoid
consumeMessage
(T message) Process a message from the queueint
drainTo
(Collection<? super T> c) Removes all available elements from this queue and adds them to the given collection.getItems()
Return any currently queued items without removing them from the queueint
size()
Returns the number of currently queue itemsvoid
stateChanged
(CuratorFramework client, ConnectionState newState) Called when there is a state change in the connectiontake()
Take the next item from the queue, blocking until there is an item availableTake the next item from the queue, waiting up to the specified time for an available item.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.curator.framework.state.ConnectionStateListener
doNotProxy
-
Constructor Details
-
BlockingQueueConsumer
Creates with capacity ofInteger.MAX_VALUE
- Parameters:
connectionStateListener
- listener for connection state changes
-
BlockingQueueConsumer
- Parameters:
connectionStateListener
- listener for connection state changescapacity
- max capacity (i.e. puts block if full)
-
BlockingQueueConsumer
public BlockingQueueConsumer(ConnectionStateListener connectionStateListener, BlockingQueue<T> queue) Wrap the given blocking queue- Parameters:
connectionStateListener
- listener for connection state changesqueue
- queue to use
-
-
Method Details
-
consumeMessage
Description copied from interface:QueueConsumer
Process a message from the queue- Specified by:
consumeMessage
in interfaceQueueConsumer<T>
- Parameters:
message
- message to process- Throws:
Exception
- any errors
-
getItems
Return any currently queued items without removing them from the queue- Returns:
- items (can be empty)
-
size
public int size()Returns the number of currently queue items- Returns:
- currently queue item count or 0
-
take
Take the next item from the queue, blocking until there is an item available- Returns:
- the item
- Throws:
InterruptedException
- thread interruption
-
take
Take the next item from the queue, waiting up to the specified time for an available item. If the time elapses,null
is returned.- Parameters:
time
- amount of time to blockunit
- time unit- Returns:
- next item or null
- Throws:
InterruptedException
- thread interruption
-
drainTo
Removes all available elements from this queue and adds them to the given collection. This operation may be more efficient than repeatedly polling this queue. A failure encountered while attempting to add elements to collection c may result in elements being in neither, either or both collections when the associated exception is thrown. Attempts to drain a queue to itself result in IllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.- Parameters:
c
- the collection to transfer elements into- Returns:
- the number of elements transferred
- Throws:
UnsupportedOperationException
- 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 collection
-
stateChanged
Description copied from interface:ConnectionStateListener
Called when there is a state change in the connection- Specified by:
stateChanged
in interfaceConnectionStateListener
- Parameters:
client
- the clientnewState
- the new state
-