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.
- All Implemented Interfaces:
Consumer<E>
,java.lang.Runnable
public abstract class AbstractRunnableBlockingQueueConsumer<E> extends java.lang.Object implements Consumer<E>, java.lang.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 usingBlockingQueue.take()
and processed usingconsume(Object)
. This runnable's interruption policy is to end execution.- Author:
- Garret Wilson
- See Also:
BlockingQueue.take()
-
-
Constructor Summary
Constructors Constructor Description AbstractRunnableBlockingQueueConsumer(java.util.concurrent.BlockingQueue<E> blockingQueue)
Blocking queue constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
consume(E element)
Consumes an element from the queue.protected java.util.concurrent.BlockingQueue<E>
getBlockingQueue()
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 Detail
-
AbstractRunnableBlockingQueueConsumer
public AbstractRunnableBlockingQueueConsumer(java.util.concurrent.BlockingQueue<E> blockingQueue)
Blocking queue constructor.- Parameters:
blockingQueue
- The blocking queue from which elements will be consumed.- Throws:
java.lang.NullPointerException
- if the given blocking queue isnull
.
-
-
Method Detail
-
getBlockingQueue
protected java.util.concurrent.BlockingQueue<E> 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)
.- Specified by:
run
in interfacejava.lang.Runnable
-
started
protected void started()
Called when the consumer is started before processing ends.
-
consume
public abstract void consume(E element)
Consumes an element from the queue.
-
stopped
protected void stopped()
Called when the consumer is stopped after processing ends.
-
-