Class AbstractConcurrentCollector<DATATYPE>
- java.lang.Object
-
- com.helger.commons.concurrent.collector.AbstractConcurrentCollector<DATATYPE>
-
- Type Parameters:
DATATYPE- The type of the objects in the queue.
- All Implemented Interfaces:
IConcurrentCollector,IMutableConcurrentCollector<DATATYPE>
- Direct Known Subclasses:
ConcurrentCollectorMultiple,ConcurrentCollectorSingle
@ThreadSafe public abstract class AbstractConcurrentCollector<DATATYPE> extends Object implements IMutableConcurrentCollector<DATATYPE>
Abstract concurrent collector based onBlockingQueue.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_QUEUE_SIZEDefault maximum queue sizeprotected BlockingQueue<Object>m_aQueuestatic ObjectSTOP_QUEUE_OBJECTThe STOP object that is internally added to the queue to indicate the last token.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractConcurrentCollector(int nMaxQueueSize)Constructor creating anArrayBlockingQueueinternally.protectedAbstractConcurrentCollector(BlockingQueue<Object> aQueue)Constructor using an arbitraryBlockingQueue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ICommonsList<DATATYPE>drainQueue()intgetQueueLength()booleanisQueueEmpty()booleanisStopped()Check if this collector is already stopped.ESuccessqueueObject(DATATYPE aObject)Submit an object to the queue.ESuccessstopQueuingNewObjects()Stop taking new objects in the collector.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.helger.commons.concurrent.collector.IMutableConcurrentCollector
collect
-
-
-
-
Field Detail
-
DEFAULT_MAX_QUEUE_SIZE
public static final int DEFAULT_MAX_QUEUE_SIZE
Default maximum queue size- See Also:
- Constant Field Values
-
STOP_QUEUE_OBJECT
public static final Object STOP_QUEUE_OBJECT
The STOP object that is internally added to the queue to indicate the last token. Should implement Comparable for the priority queue
-
m_aQueue
protected final BlockingQueue<Object> m_aQueue
-
-
Constructor Detail
-
AbstractConcurrentCollector
protected AbstractConcurrentCollector(@Nonnegative int nMaxQueueSize)
Constructor creating anArrayBlockingQueueinternally.- Parameters:
nMaxQueueSize- The maximum number of items that can be in the queue. Must be > 0.
-
AbstractConcurrentCollector
protected AbstractConcurrentCollector(@Nonnull BlockingQueue<Object> aQueue)
Constructor using an arbitraryBlockingQueue.- Parameters:
aQueue- TheBlockingQueueto be used. May not benull.
-
-
Method Detail
-
queueObject
@Nonnull public final ESuccess queueObject(@Nonnull DATATYPE aObject)
Description copied from interface:IMutableConcurrentCollectorSubmit an object to the queue.- Specified by:
queueObjectin interfaceIMutableConcurrentCollector<DATATYPE>- Parameters:
aObject- The object to submit. May not benull.- Returns:
ESuccess
-
isQueueEmpty
public boolean isQueueEmpty()
- Specified by:
isQueueEmptyin interfaceIConcurrentCollector- Returns:
trueif the queue is empty,falseotherwise.
-
getQueueLength
@Nonnegative public final int getQueueLength()
- Specified by:
getQueueLengthin interfaceIConcurrentCollector- Returns:
- The number of objects currently in the queue.
-
stopQueuingNewObjects
@Nonnull public final ESuccess stopQueuingNewObjects()
Description copied from interface:IMutableConcurrentCollectorStop taking new objects in the collector. Returns directly and does not wait until the processing finished.- Specified by:
stopQueuingNewObjectsin interfaceIMutableConcurrentCollector<DATATYPE>- Returns:
ESuccess
-
isStopped
public final boolean isStopped()
Description copied from interface:IConcurrentCollectorCheck if this collector is already stopped.- Specified by:
isStoppedin interfaceIConcurrentCollector- Returns:
trueif the collector is stopped,falseotherwise.
-
drainQueue
@Nonnull @ReturnsMutableCopy public final ICommonsList<DATATYPE> drainQueue()
-
-