org.d_haven.event.command

Class ProcessorBoundThreadPolicy

public class ProcessorBoundThreadPolicy extends AbstractThreadPolicy

The ProcessorBoundThreadPolicy is a ThreadPolicy designed to process pipelines in a number of threads that is a multiple of the number of threads in the system. This implementation requires that you have the Runtime.getRuntime().getAvailableProcessors() method introduced in Java 1.4. If you want to use the event system on an older JVM, do not use this class.
Field Summary
static longDEFAULT_WAIT_TIME
PooledExecutorm_executor
intm_numThreads
longm_waitTime
Constructor Summary
ProcessorBoundThreadPolicy()
Create a new ProcessorBoundThreadPolicy with one thread per processor and a default wait time of one second between runs.
ProcessorBoundThreadPolicy(int multiplier)
Create a new ProcessorBoundThreadPolicy with the number of threads equal to the number of processor multiplied by the supplied multiplier.
ProcessorBoundThreadPolicy(int multiplier, long waitTime)
Create a new ProcessorBoundThreadPolicy with the number of threads equal to the number of processor multiplied by the supplied multiplier.
Method Summary
EventPipelineRunnercreateRunner(EventPipeline pipeline)
protected voidendLoop()
intgetNumThreads()
Get the number of threads to use for running the pipelines.
ThreadFactorygetThreadFactory()
Get the ThreadFactory used to create new threads.
longgetWaitTime()
Get the time we wait between runs of the pipeline.
protected voidprocess(Collection pipelines)
voidsetThreadFactory(ThreadFactory factory)
protected voidstartLoop()
StringtoString()

Field Detail

DEFAULT_WAIT_TIME

private static final long DEFAULT_WAIT_TIME

m_executor

private final PooledExecutor m_executor

m_numThreads

private final int m_numThreads

m_waitTime

private final long m_waitTime

Constructor Detail

ProcessorBoundThreadPolicy

public ProcessorBoundThreadPolicy()
Create a new ProcessorBoundThreadPolicy with one thread per processor and a default wait time of one second between runs.

ProcessorBoundThreadPolicy

public ProcessorBoundThreadPolicy(int multiplier)
Create a new ProcessorBoundThreadPolicy with the number of threads equal to the number of processor multiplied by the supplied multiplier. It also uses the default wait time of one second between runs.

Parameters: multiplier the multiplier against the number of threads

Throws: IllegalArgumentException if the multiplier is less than 1

ProcessorBoundThreadPolicy

public ProcessorBoundThreadPolicy(int multiplier, long waitTime)
Create a new ProcessorBoundThreadPolicy with the number of threads equal to the number of processor multiplied by the supplied multiplier. It also uses the supplied wait time for use between runs.

Parameters: multiplier the multiplier against the number of threads waitTime the time to wait between runs

Throws: IllegalArgumentException if the multiplier or waitTime is less than 1

Method Detail

createRunner

public EventPipelineRunner createRunner(EventPipeline pipeline)

endLoop

protected void endLoop()

getNumThreads

public int getNumThreads()
Get the number of threads to use for running the pipelines.

Returns: the number of threads

getThreadFactory

public ThreadFactory getThreadFactory()
Get the ThreadFactory used to create new threads.

Returns: the thread factory

getWaitTime

public long getWaitTime()
Get the time we wait between runs of the pipeline.

Returns: the wait time in ms

process

protected void process(Collection pipelines)

setThreadFactory

public void setThreadFactory(ThreadFactory factory)

startLoop

protected void startLoop()

toString

public String toString()