Package com.globalmentor.collections
Class AbstractRunnableBlockingQueueConsumer<E>
java.lang.Object
com.globalmentor.collections.AbstractRunnableBlockingQueueConsumer<E>
- Type Parameters:
E
- The type of elements held in the queue.
public abstract class AbstractRunnableBlockingQueueConsumer<E>
extends Object
implements Consumer<E>, Runnable
A runnable consumer that takes elements from a blocking queue and consume them. Normally this consumer is run in a separate thread so that consuming can
occur asynchronously. Each element is taken using
BlockingQueue.take()
and processed using consume(Object)
. This runnable's interruption
policy is to end execution.- Author:
- Garret Wilson
- See Also:
-
Constructor Summary
ConstructorDescriptionAbstractRunnableBlockingQueueConsumer
(BlockingQueue<E> blockingQueue) Blocking queue constructor. -
Method Summary
Modifier and TypeMethodDescriptionabstract void
Consumes an element from the queue.protected BlockingQueue<E>
void
run()
The main functionality of the consumer, which consumes data from the blocking queue and callsconsume(Object)
.protected void
started()
Called when the consumer is started before processing ends.protected void
stopped()
Called when the consumer is stopped after processing ends.
-
Constructor Details
-
AbstractRunnableBlockingQueueConsumer
Blocking queue constructor.- Parameters:
blockingQueue
- The blocking queue from which elements will be consumed.- Throws:
NullPointerException
- if the given blocking queue isnull
.
-
-
Method Details
-
getBlockingQueue
- Returns:
- The blocking queue from which elements are being consumed.
-
run
public void run()The main functionality of the consumer, which consumes data from the blocking queue and callsconsume(Object)
. -
started
protected void started()Called when the consumer is started before processing ends. -
consume
Consumes an element from the queue. -
stopped
protected void stopped()Called when the consumer is stopped after processing ends.
-