Class ConcurrentCollectorSingle<DATATYPE>
java.lang.Object
com.helger.commons.concurrent.collector.AbstractConcurrentCollector<DATATYPE>
com.helger.commons.concurrent.collector.ConcurrentCollectorSingle<DATATYPE>
- Type Parameters:
DATATYPE- The type of the objects in the queue.
- All Implemented Interfaces:
IConcurrentCollector,IMutableConcurrentCollector<DATATYPE>
Concurrent collector that performs action on each object separately
- Author:
- Philip Helger
-
Field Summary
Fields inherited from class com.helger.commons.concurrent.collector.AbstractConcurrentCollector
DEFAULT_MAX_QUEUE_SIZE, m_aQueue, STOP_QUEUE_OBJECT -
Constructor Summary
ConstructorsConstructorDescriptionConstructor that usesAbstractConcurrentCollector.DEFAULT_MAX_QUEUE_SIZEelements as the maximum queue length.ConcurrentCollectorSingle(int nMaxQueueSize) Constructor.ConcurrentCollectorSingle(BlockingQueue<Object> aQueue) Constructor using an existingBlockingQueue. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidcollect()This method starts the collector by taking objects from the internalBlockingQueue.final IConcurrentPerformer<DATATYPE> setPerformer(IConcurrentPerformer<DATATYPE> aPerformer) Set the performer to be used.Methods inherited from class com.helger.commons.concurrent.collector.AbstractConcurrentCollector
drainQueue, getQueueLength, isQueueEmpty, isStopped, queueObject, stopQueuingNewObjects
-
Constructor Details
-
ConcurrentCollectorSingle
public ConcurrentCollectorSingle()Constructor that usesAbstractConcurrentCollector.DEFAULT_MAX_QUEUE_SIZEelements as the maximum queue length. -
ConcurrentCollectorSingle
Constructor.- Parameters:
nMaxQueueSize- The maximum number of items that can be in the queue. Must be > 0.
-
ConcurrentCollectorSingle
Constructor using an existingBlockingQueue.- Parameters:
aQueue-BlockingQueueto use. May not benull.
-
-
Method Details
-
getPerformer
- Returns:
- The current performer set.
nullif none was explicitly set.
-
setPerformer
@Nonnull public final ConcurrentCollectorSingle<DATATYPE> setPerformer(@Nonnull IConcurrentPerformer<DATATYPE> aPerformer) Set the performer to be used. This method must be invoked before the collector can be run. The passed implementation must be rock-solid as this class will not make any retries. If the passed performer throws and exception without handling the objects correct the objects will be lost!- Parameters:
aPerformer- The performer to be used. May not benull.- Returns:
- this for chaining
- Throws:
IllegalStateException- If another performer is already present!
-
collect
public final void collect()This method starts the collector by taking objects from the internalBlockingQueue. So this method blocks and must be invoked from a separate thread. This method runs untilAbstractConcurrentCollector.stopQueuingNewObjects()is new called and the queue is empty.- Throws:
IllegalStateException- if no performer is set - seesetPerformer(IConcurrentPerformer)
-