com.sun.grizzly.http
Class KeepAliveCountManager

java.lang.Object
  extended by com.sun.grizzly.http.KeepAliveCountManager

public class KeepAliveCountManager
extends Object

Keep Alive subsystems. This class will cancel SelectionKey based on the maxKeepAliveRequests.

Author:
Jeanfrancois Arcand

Field Summary
static int KEEP_ALIVE_RULE
           
protected  ConcurrentHashMap<SelectionKey,Integer> keepAliveCounts
          Placeholder for keep-alive count monitoring.
protected  int maxKeepAliveRequests
          Maximum number of requests in a single transaction.
protected  PipelineStatistic pipelineStat
          The PipelineStatistic objects used when gathering statistics.
 
Constructor Summary
KeepAliveCountManager()
          Default constructor.
 
Method Summary
 void addTask(Task task)
          Add an object to this pipeline
 boolean dropConnection()
          Return true if we need to close the connection just after the first request.
 int getCurrentThreadCount()
          Return the current number of active threads.
 int getCurrentThreadsBusy()
          Return the current number of active threads.
 int getKeepAliveTimeoutInSeconds()
          Gets the number of seconds before a keep-alive connection that has been idle times out and is closed.
 int getMaxKeepAliveRequests()
          Return the maximum number of keep-alive requests per connection.
 int getMaxSpareThreads()
          Return the maximum spare thread.
 int getMaxThreads()
          Return the number of threads used by this pipeline.
 int getMinSpareThreads()
          Return the minimum spare thread.
 String getName()
          Return the name of this Pipeline
 PipelineStatistic getPipelineStatistic()
          Return the PipelineStatistic object used to gather statistic;
 Task getTask()
          Return a SelectionKey object available in the pipeline.
 int getWaitingThread()
          Return the number of waiting threads.
 void initPipeline()
          Init the Pipeline by initializing the required WorkerThread.
 boolean interruptThread(long threadId)
          Interrupt the Thread using it thread id
 void setKeepAliveTimeoutInSeconds(int keepAliveTimeout)
          Sets the number of seconds before a keep-alive connection that has been idle times out and is closed.
 void setMaxKeepAliveRequests(int maxKeepAliveRequests)
          Set the maximum number of Keep-Alive requests that we will honor per connection.
 void setMaxThreads(int maxThreads)
          Set the number of threads used by this pipeline.
 void setMinSpareThreads(int minSpareThreads)
          Set the minimum space thread this Pipeline can handle.
 void setMinThreads(int minThreads)
          Set the minimum thread this Pipeline will creates when initializing.
 void setName(String name)
          Set the name of this Pipeline
 void setPipelineStatistic(PipelineStatistic pipelineStatistic)
          Set the PipelineStatistic object used to gather statistic;
 void setPort(int port)
          Set the port used by this Pipeline
 void setPriority(int priority)
          Set the thread priority of the Pipeline
 void setQueueSizeInBytes(int maxQueueSizeInBytes)
          Set the maximum pending connection this Pipeline can handle.
 void setThreadsIncrement(int threadsIncrement)
           
 void setThreadsTimeout(int threadsTimeout)
           
 int size()
          Returns the number of tasks in this Pipeline.
 void startPipeline()
          Start the Pipeline and all associated WorkerThread
 void stopPipeline()
          Stop the Pipeline and all associated WorkerThread
 String toString()
           
 boolean trap(SelectionKey key)
          Monitor keep-alive request count for the given connection.
 void untrap(SelectionKey key)
          Stop monitoring keep-alive request count for the given connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEEP_ALIVE_RULE

public static final int KEEP_ALIVE_RULE
See Also:
Constant Field Values

keepAliveCounts

protected ConcurrentHashMap<SelectionKey,Integer> keepAliveCounts
Placeholder for keep-alive count monitoring.


maxKeepAliveRequests

protected int maxKeepAliveRequests
Maximum number of requests in a single transaction.


pipelineStat

protected PipelineStatistic pipelineStat
The PipelineStatistic objects used when gathering statistics.

Constructor Detail

KeepAliveCountManager

public KeepAliveCountManager()
Default constructor.

Method Detail

initPipeline

public void initPipeline()
Init the Pipeline by initializing the required WorkerThread.


startPipeline

public void startPipeline()
Start the Pipeline and all associated WorkerThread


stopPipeline

public void stopPipeline()
Stop the Pipeline and all associated WorkerThread


addTask

public void addTask(Task task)
Add an object to this pipeline


getTask

public Task getTask()
Return a SelectionKey object available in the pipeline. All Threads will synchronize on that method


size

public int size()
Returns the number of tasks in this Pipeline.

Returns:
Number of tasks in this Pipeline.

getWaitingThread

public int getWaitingThread()
Return the number of waiting threads.


setMaxThreads

public void setMaxThreads(int maxThreads)
Set the number of threads used by this pipeline.


getMaxThreads

public int getMaxThreads()
Return the number of threads used by this pipeline.


getCurrentThreadCount

public int getCurrentThreadCount()
Return the current number of active threads.


getCurrentThreadsBusy

public int getCurrentThreadsBusy()
Return the current number of active threads.


getMaxSpareThreads

public int getMaxSpareThreads()
Return the maximum spare thread.


setPriority

public void setPriority(int priority)
Set the thread priority of the Pipeline


setName

public void setName(String name)
Set the name of this Pipeline


getName

public String getName()
Return the name of this Pipeline

Returns:
the name of this Pipeline

setPort

public void setPort(int port)
Set the port used by this Pipeline

Parameters:
port - the port used by this Pipeline

setMinThreads

public void setMinThreads(int minThreads)
Set the minimum thread this Pipeline will creates when initializing.

Parameters:
minThreads - the minimum number of threads.

toString

public String toString()
Overrides:
toString in class Object

setQueueSizeInBytes

public void setQueueSizeInBytes(int maxQueueSizeInBytes)
Set the maximum pending connection this Pipeline can handle.


setThreadsIncrement

public void setThreadsIncrement(int threadsIncrement)

setThreadsTimeout

public void setThreadsTimeout(int threadsTimeout)

getMinSpareThreads

public int getMinSpareThreads()
Return the minimum spare thread.


setMinSpareThreads

public void setMinSpareThreads(int minSpareThreads)
Set the minimum space thread this Pipeline can handle.


trap

public boolean trap(SelectionKey key)
Monitor keep-alive request count for the given connection.

Returns:
true if the request can be processed, false if the maximun number of requests has been reached.

untrap

public void untrap(SelectionKey key)
Stop monitoring keep-alive request count for the given connection.


getMaxKeepAliveRequests

public int getMaxKeepAliveRequests()
Return the maximum number of keep-alive requests per connection.


setMaxKeepAliveRequests

public void setMaxKeepAliveRequests(int maxKeepAliveRequests)
Set the maximum number of Keep-Alive requests that we will honor per connection. A value < 0 will disabled the keep-alive mechanism.


setKeepAliveTimeoutInSeconds

public void setKeepAliveTimeoutInSeconds(int keepAliveTimeout)
Sets the number of seconds before a keep-alive connection that has been idle times out and is closed.

Parameters:
keepAliveTimeout - Keep-alive timeout in number of seconds

getKeepAliveTimeoutInSeconds

public int getKeepAliveTimeoutInSeconds()
Gets the number of seconds before a keep-alive connection that has been idle times out and is closed.

Returns:
Keep-alive timeout in number of seconds

dropConnection

public boolean dropConnection()
Return true if we need to close the connection just after the first request.


setPipelineStatistic

public void setPipelineStatistic(PipelineStatistic pipelineStatistic)
Set the PipelineStatistic object used to gather statistic;


getPipelineStatistic

public PipelineStatistic getPipelineStatistic()
Return the PipelineStatistic object used to gather statistic;


interruptThread

public boolean interruptThread(long threadId)
Interrupt the Thread using it thread id



Copyright © 2009 SUN Microsystems. All Rights Reserved.