Top Description Inners Fields Constructors Methods
net.sf.ehcache.constructs.refreshahead

public Class ThreadedWorkQueue<W>

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collection, java.util.concurrent.ExecutorService, .LinkedBlockingQueue, .ThreadFactory, .ThreadPoolExecutor, .TimeUnit, java.util.concurrent.atomic.AtomicInteger

This 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 and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ThreadedWorkQueue.BatchWorker<WW>

Callback class, think of it as a Runnable with an argument that is a Collection.

Field Summary

Modifier and TypeField and Description
private final int
private final ThreadedWorkQueue.BatchWorker<W>
private final AtomicInteger
private volatile boolean
private static final int
private final AtomicInteger
private final AtomicInteger
private final LinkedBlockingQueue<W>
private final ExecutorService

Constructor Summary

AccessConstructor and Description
public
ThreadedWorkQueue(ThreadedWorkQueue.BatchWorker<W>
Thread safe dispatcher to use to dispatch work
dispatcher
,
int
Number of parallel threads used process work from this queue
numberOfThreads
,
ThreadFactory
ThreadFactory used to create the threads
factory
,
int
maximum backlog of work items that can be queued before items get dropped
maximumQueueSize
,
int
number of items, at a maximum, to send to a dispatcher at a time.
batchSize
)

Create a work queue where work is dispatched through the given dispatcher, which the specified number of threads.

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

count of items yet to be processed.
getBacklogCount
()

Get the current backlog count.

public int

Returns:

batch size
getBatchSize
()

Get the batch size

public ThreadedWorkQueue.BatchWorker<W>

Returns:

dispatcher
getDispatcher
()

get the dispatcher being used for this queue.

public int

Returns:

the dropped counter
getDroppedCount
()

Gets dropped counter.

public int

Returns:

the offer counter
getOfferedCount
()

Gets offer counter.

public int

Returns:

the processed count
getProcessedCount
()

Gets processed count.

public boolean

Returns:

true if still alive
isAlive
()

Is this work queue still accepting work.

public void
offer(W workUnit)

Offer a work unit to queue.

private void
pullFromQueueAndDispatch()

Actually do the work.

public void
shutdown()

Shutdown this queue.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

batchSizeback to summary
private final int batchSize
dispatcherback to summary
private final ThreadedWorkQueue.BatchWorker<W> dispatcher
droppedCounterback to summary
private final AtomicInteger droppedCounter
isAliveback to summary
private volatile boolean isAlive
MINUTES_OF_THE_IDLE_LIFEback to summary
private static final int MINUTES_OF_THE_IDLE_LIFE
offerCounterback to summary
private final AtomicInteger offerCounter
processedCounterback to summary
private final AtomicInteger processedCounter
queueback to summary
private final LinkedBlockingQueue<W> queue
threadPoolback to summary
private final ExecutorService threadPool

Constructor Detail

ThreadedWorkQueueback to summary
public ThreadedWorkQueue(ThreadedWorkQueue.BatchWorker<W> dispatcher, int numberOfThreads, 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:ThreadedWorkQueue.BatchWorker<W>

Thread safe dispatcher to use to dispatch work

numberOfThreads:int

Number of parallel threads used process work from this queue

factory:ThreadFactory

ThreadFactory used to create the threads

maximumQueueSize:int

maximum backlog of work items that can be queued before items get dropped

batchSize:int

number of items, at a maximum, to send to a dispatcher at a time.

Method Detail

getBacklogCountback to summary
public long getBacklogCount()

Get the current backlog count. An approximation, by necessity.

Returns:long

count of items yet to be processed.

getBatchSizeback to summary
public int getBatchSize()

Get the batch size

Returns:int

batch size

getDispatcherback to summary
public ThreadedWorkQueue.BatchWorker<W> getDispatcher()

get the dispatcher being used for this queue.

Returns:ThreadedWorkQueue.BatchWorker<W>

dispatcher

getDroppedCountback to summary
public int getDroppedCount()

Gets dropped counter.

Returns:int

the dropped counter

getOfferedCountback to summary
public int getOfferedCount()

Gets offer counter. Cumulative tripped

Returns:int

the offer counter

getProcessedCountback to summary
public int getProcessedCount()

Gets processed count.

Returns:int

the processed count

isAliveback to summary
public boolean isAlive()

Is this work queue still accepting work.

Returns:boolean

true if still alive

offerback to summary
public void offer(W workUnit)

Offer a work unit to queue. Might push prior work units off of the work queue, dropped forever.

pullFromQueueAndDispatchback to summary
private void pullFromQueueAndDispatch() throws InterruptedException

Actually do the work.

shutdownback to summary
public void shutdown()

Shutdown this queue. Propagates an interrupt to currently executing BatchWorker threads.

net.sf.ehcache.constructs.refreshahead back to summary

public Interface ThreadedWorkQueue.BatchWorker<WW>


Callback class, think of it as a Runnable with an argument that is a Collection.
Author
cschanck

Method Summary

Modifier and TypeMethod and Description
public void
process(Collection<? extends WW> collection)

Process a batch of work.

Method Detail

processback to summary
public void process(Collection<? extends WW> collection)

Process a batch of work.