Fields Summary |
---|
private int | waitingThreadsThe number of thread waiting for a Task |
private int | maxThreadsThe maximum number of Thread |
private int | minThreadsThe minimum numbers of WorkerThread |
private int | portThe port used. |
private int | threadCountThe number of WorkerThread |
private String | nameThe name of this Pipeline |
private int | priorityThe Thread Priority |
private boolean | isStartedHas the pipeline already started |
private ThreadPoolExecutor | workerThreadsExecutorService wrapped by this pipeline. |
private ArrayBlockingQueue | arrayBlockingQueueConnection queue |
private int | maxQueueSizeInBytesMaximum pending connection before refusing requests. |
private int | queueSizeInBytesmaximum size of the connection queue, in bytes. |
protected PipelineStatistic | pipelineStatThe PipelineStatistic objects used when gathering statistics. |
Methods Summary |
---|
public void | addTask(Task task)Add an object to this pipeline
if (workerThreads.getQueue().size() > maxQueueSizeInBytes ){
task.cancelTask("Maximum Connections Reached: "
+ pipelineStat.getQueueSizeInBytes()
+ " -- Retry later", HtmlHelper.OK);
task.getSelectorThread().returnTask(task);
return;
}
workerThreads.execute((Runnable)task);
if ( pipelineStat != null) {
pipelineStat.gather(size());
}
|
public boolean | expireKey(java.nio.channels.SelectionKey key)Invoked when the SelectorThread is about to expire a SelectionKey.
return true;
|
public int | getCurrentThreadCount()Return the current number of threads used.
return workerThreads.getPoolSize() ;
|
public int | getCurrentThreadsBusy()Return the curent number of threads that are currently processing
a task.
return workerThreads.getActiveCount();
|
public int | getMaxSpareThreads()Return the maximum spare thread.
return getWaitingThread();
|
public int | getMaxThreads()Return the number of threads used by this pipeline.
return maxThreads;
|
public int | getMinSpareThreads()Return the minimum spare thread.
return 0;
|
public java.lang.String | getName()Return the name of this Pipeline
return name+port;
|
public PipelineStatistic | getPipelineStatistic()Return the PipelineStatistic object used
to gather statistic;
return pipelineStat;
|
public int | getQueueSizeInBytes()Get the maximum pending connection this Pipeline
can handle.
return maxQueueSizeInBytes;
|
public Task | getTask()Return a Task object available in the pipeline.
return null;
|
public int | getWaitingThread()Return the number of waiting threads.
return workerThreads.getPoolSize() - workerThreads.getActiveCount();
|
public void | initPipeline()Init the Pipeline by initializing the required
ThreadPoolExecutor .
// ------------------------------------------------ Lifecycle ------------/
if (isStarted){
return;
}
isStarted = true;
arrayBlockingQueue =
new ArrayBlockingQueue<Runnable>(maxQueueSizeInBytes, true);
workerThreads = new ThreadPoolExecutor(
maxThreads,
maxThreads,
0L,
TimeUnit.MILLISECONDS,
arrayBlockingQueue,
new GrizzlyThreadFactory(name,port,priority),
this);
|
public boolean | interruptThread(long threadID)Interrupt the Thread using it thread id
return ((GrizzlyThreadFactory)workerThreads.getThreadFactory())
.interruptThread(threadID);
|
public void | rejectedExecution(java.lang.Runnable r, java.util.concurrent.ThreadPoolExecutor executor)When the maxQueueSizeInBytesConnection is reached,
terminate Task
Task task = (Task)r;
task.cancelTask("Maximum Connections Reached -- Retry later",
HtmlHelper.OK);
task.getSelectorThread().returnTask(task);
|
public void | setMaxThreads(int maxThreads)Set the number of threads used by this pipeline.
this.maxThreads = maxThreads;
|
public void | setMinSpareThreads(int minSpareThreads)Set the minimum space thread this Pipeline can handle.
|
public void | setMinThreads(int minThreads)Set the minimum thread this Pipeline will creates
when initializing.
this.minThreads = minThreads;
|
public void | setName(java.lang.String name)Set the name of this Pipeline
this.name = name;
|
public void | setPipelineStatistic(PipelineStatistic pipelineStatistic)Set the PipelineStatistic object used
to gather statistic;
this.pipelineStat = pipelineStatistic;
|
public void | setPort(int port)Set the port used by this Pipeline
this.port = port;
|
public void | setPriority(int priority)Set the thread priority of the Pipeline
this.priority = priority;
|
public void | setQueueSizeInBytes(int maxQueueSizeInBytes)Set the maximum pending connection this Pipeline
can handle.
this.maxQueueSizeInBytes = maxQueueSizeInBytes;
if ( pipelineStat != null )
pipelineStat.setQueueSizeInBytes(maxQueueSizeInBytes);
|
public void | setThreadsIncrement(int threadsIncrement)
; // Not Supported
|
public void | setThreadsTimeout(int threadsTimeout)
; // Not Supported
|
public int | size()Returns the number of tasks in this Pipeline .
return workerThreads.getQueue().size();
|
public void | startPipeline()Start the Pipeline
if (isStarted){
return;
}
; // Do nothing
|
public void | stopPipeline()Stop the Pipeline
if (!isStarted){
return;
}
isStarted = false;
workerThreads.shutdown();
|
public java.lang.String | toString()
return "name: " + name + " maxThreads: " + maxThreads
+ " minThreads:" + minThreads;
|