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>
public class ConcurrentCollectorMultiple<DATATYPE> extends AbstractConcurrentCollector<DATATYPE>
Concurrent collector that performs action on multiple objects at once- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_PERFORM_COUNTThe 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
Constructors Constructor Description ConcurrentCollectorMultiple()Constructor 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)Constructor using an existingBlockingQueueand the default max perform count (50).ConcurrentCollectorMultiple(BlockingQueue<Object> aQueue, int nMaxPerformCount)Constructor using an existingBlockingQueue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcollect()This method starts the collector by taking objects from the internalBlockingQueue.intgetMaxPerformCount()IConcurrentPerformer<List<DATATYPE>>getPerformer()ConcurrentCollectorMultiple<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 Detail
-
DEFAULT_MAX_PERFORM_COUNT
public static final int DEFAULT_MAX_PERFORM_COUNT
The default number of objects to be put in the queue for execution.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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
public ConcurrentCollectorMultiple(@Nonnull BlockingQueue<Object> aQueue)
Constructor using an existingBlockingQueueand the default max perform count (50).- 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 Detail
-
getMaxPerformCount
@Nonnegative public final int getMaxPerformCount()
- Returns:
- The maximum number of objects to be put in the list for execution. Always ≥ 0.
-
getPerformer
@Nullable public final IConcurrentPerformer<List<DATATYPE>> 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)
-
-