Class ThreadedWorkQueue<W>
- java.lang.Object
-
- net.sf.ehcache.constructs.refreshahead.ThreadedWorkQueue<W>
-
- Type Parameters:
W-
public class ThreadedWorkQueue<W> extends java.lang.ObjectThis class implements a work queue of pooled objects. You can offer a stream of objects to the backing poool of threads and it will consume them and hand them to the BatchWorker as a collection to be processed (batched).Essentially, it uses BatchWorker as Callable/Future with a collection argument.
- Author:
- cschanck
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceThreadedWorkQueue.BatchWorker<WW>Callback class, think of it as a Runnable with an argument that is aCollection.
-
Constructor Summary
Constructors Constructor Description ThreadedWorkQueue(ThreadedWorkQueue.BatchWorker<W> dispatcher, int numberOfThreads, java.util.concurrent.ThreadFactory factory, int maximumQueueSize, int batchSize)Create a work queue where work is dispatched through the given dispatcher, which the specified number of threads.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetBacklogCount()Get the current backlog count.intgetBatchSize()Get the batch sizeThreadedWorkQueue.BatchWorker<W>getDispatcher()get the dispatcher being used for this queue.intgetDroppedCount()Gets dropped counter.intgetOfferedCount()Gets offer counter.intgetProcessedCount()Gets processed count.booleanisAlive()Is this work queue still accepting work.voidoffer(W workUnit)Offer a work unit to queue.voidshutdown()Shutdown this queue.
-
-
-
Constructor Detail
-
ThreadedWorkQueue
public ThreadedWorkQueue(ThreadedWorkQueue.BatchWorker<W> dispatcher, int numberOfThreads, java.util.concurrent.ThreadFactory factory, int maximumQueueSize, int batchSize)
Create a work queue where work is dispatched through the given dispatcher, which the specified number of threads.- Parameters:
dispatcher- Thread safe dispatcher to use to dispatch worknumberOfThreads- Number of parallel threads used process work from this queuefactory-ThreadFactoryused to create the threadsmaximumQueueSize- maximum backlog of work items that can be queued before items get droppedbatchSize- number of items, at a maximum, to send to a dispatcher at a time.
-
-
Method Detail
-
offer
public void offer(W workUnit)
Offer a work unit to queue. Might push prior work units off of the work queue, dropped forever.- Parameters:
workUnit-
-
isAlive
public boolean isAlive()
Is this work queue still accepting work.- Returns:
- true if still alive
-
getBacklogCount
public long getBacklogCount()
Get the current backlog count. An approximation, by necessity.- Returns:
- count of items yet to be processed.
-
getOfferedCount
public int getOfferedCount()
Gets offer counter. Cumulative tripped- Returns:
- the offer counter
-
getDroppedCount
public int getDroppedCount()
Gets dropped counter.- Returns:
- the dropped counter
-
getProcessedCount
public int getProcessedCount()
Gets processed count.- Returns:
- the processed count
-
getDispatcher
public ThreadedWorkQueue.BatchWorker<W> getDispatcher()
get the dispatcher being used for this queue.- Returns:
- dispatcher
-
getBatchSize
public int getBatchSize()
Get the batch size- Returns:
- batch size
-
shutdown
public void shutdown()
Shutdown this queue. Propagates an interrupt to currently executingThreadedWorkQueue.BatchWorkerthreads.
-
-