Class ConcurrentCollectorMultiple<DATATYPE>
java.lang.Object
com.helger.commons.concurrent.collector.AbstractConcurrentCollector<DATATYPE>
com.helger.commons.concurrent.collector.ConcurrentCollectorMultiple<DATATYPE>
- Type Parameters:
DATATYPE- The type of the objects in the queue.
- All Implemented Interfaces:
IConcurrentCollector,IMutableConcurrentCollector<DATATYPE>
Concurrent collector that performs action on multiple objects at once
- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default number of objects to be put in the queue for execution.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 andDEFAULT_MAX_PERFORM_COUNTas the max perform count.ConcurrentCollectorMultiple(int nMaxQueueSize, int nMaxPerformCount) Constructor.ConcurrentCollectorMultiple(BlockingQueue<Object> aQueue, int nMaxPerformCount) Constructor using an existingBlockingQueue. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidcollect()This method starts the collector by taking objects from the internalBlockingQueue.final intfinal IConcurrentPerformer<List<DATATYPE>> setPerformer(IConcurrentPerformer<List<DATATYPE>> aPerformer) Set the performer to be used.Methods inherited from class com.helger.commons.concurrent.collector.AbstractConcurrentCollector
drainQueue, getQueueLength, isQueueEmpty, isStopped, queueObject, stopQueuingNewObjects
-
Field Details
-
DEFAULT_MAX_PERFORM_COUNT
public static final int DEFAULT_MAX_PERFORM_COUNTThe default number of objects to be put in the queue for execution.- See Also:
-
-
Constructor Details
-
ConcurrentCollectorMultiple
public ConcurrentCollectorMultiple()Constructor that usesAbstractConcurrentCollector.DEFAULT_MAX_QUEUE_SIZEelements as the maximum queue length andDEFAULT_MAX_PERFORM_COUNTas the max perform count. -
ConcurrentCollectorMultiple
public ConcurrentCollectorMultiple(@Nonnegative int nMaxQueueSize, @Nonnegative int nMaxPerformCount) Constructor.- Parameters:
nMaxQueueSize- The maximum number of items that can be in the queue. Must be > 0.nMaxPerformCount- The maximum number of objects to be put in the queue for execution. Must be > 0.
-
ConcurrentCollectorMultiple
- Parameters:
aQueue-BlockingQueueto use. May not benull.
-
ConcurrentCollectorMultiple
public ConcurrentCollectorMultiple(@Nonnull BlockingQueue<Object> aQueue, @Nonnegative int nMaxPerformCount) Constructor using an existingBlockingQueue.- Parameters:
aQueue-BlockingQueueto use. May not benull.nMaxPerformCount- The maximum number of objects to be put in the list for execution. Must be > 0.
-
-
Method Details
-
getMaxPerformCount
- Returns:
- The maximum number of objects to be put in the list for execution. Always ≥ 0.
-
getPerformer
- Returns:
- The current performer set.
nullif none was explicitly set.
-
setPerformer
@Nonnull public final ConcurrentCollectorMultiple<DATATYPE> setPerformer(@Nonnull IConcurrentPerformer<List<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)
-