FileDocCategorySizeDatePackage
KeepAlivePipeline.javaAPI DocGlassfish v2 API12515Mon Aug 27 15:56:52 BST 2007com.sun.enterprise.web.connector.grizzly

KeepAlivePipeline

public class KeepAlivePipeline extends Object
Keep Alive subsystems. This class will cancel SelectionKey based on the maxKeepAliveRequests.
author
Jeanfrancois Arcand

Fields Summary
public static final int
KEEP_ALIVE_RULE
private int
maxThreads
The maximum number of Thread
private int
priority
The Thread Priority
private int
port
The port used.
private String
name
The name of this Pipeline
private boolean
isStarted
Has the pipeline already started
private int
firstReadTimeout
private int
keepAliveTimeoutInSeconds
protected ConcurrentHashMap
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.
private KeepAliveStats
keepAliveStats
The stats object used to gather statistics.
Constructors Summary
public KeepAlivePipeline()
Default constructor.



    // ----------------------------------------------- Constructor ----------//
    
           
     
        initPipeline();
    
Methods Summary
public voidaddTask(Task task)
Add an object to this pipeline

        throw new UnsupportedOperationException();
    
public booleandropConnection()
Return true if we need to close the connection just after the first request.

        return (keepAliveTimeoutInSeconds == 0 
                    || firstReadTimeout == 0 || maxKeepAliveRequests == 0);
    
public intgetCurrentThreadCount()
Return the current number of active threads.

        return 1;
    
public intgetCurrentThreadsBusy()
Return the current number of active threads.

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

return
Keep-alive timeout in number of seconds

        return keepAliveTimeoutInSeconds;
    
public intgetMaxKeepAliveRequests()
Return the maximum number of keep-alive requests per connection.

        return maxKeepAliveRequests;
    
public intgetMaxSpareThreads()
Return the maximum spare thread.

        return 0;
    
public intgetMaxThreads()
Return the number of threads used by this pipeline.

        return maxThreads;
    
public intgetMinSpareThreads()
Return the minimum spare thread.

        throw new UnsupportedOperationException();
    
public java.lang.StringgetName()
Return the name of this Pipeline

return
the name of this Pipeline

        return name+port;
    
public PipelineStatisticgetPipelineStatistic()
Return the PipelineStatistic object used to gather statistic;

        return pipelineStat;
    
public TaskgetTask()
Return a SelectionKey object available in the pipeline. All Threads will synchronize on that method

Return
null This pipeline doesn't supports this method.

        return null;
    
public intgetWaitingThread()
Return the number of waiting threads.

        return 0;
    
public voidinitPipeline()
Init the Pipeline by initializing the required WorkerThread.

        if (isStarted){
            return;
        }
        isStarted = true;
        keepAliveCounts = new ConcurrentHashMap<SelectionKey,Integer>();     
    
public booleaninterruptThread(long threadId)
Interrupt the Thread using it thread id

        return false;
    
public booleanisKeepAlive(java.nio.channels.SelectionKey key)
Is the SelectionKey already added to the keep-alive mechanism.

        return (keepAliveCounts.get(key) != null);
    
voidsetKeepAliveStats(KeepAliveStats keepAliveStats)
Sets the given KeepAliveStats, which is responsible for storing keep-alive statistics.

param
keepAliveStats The KeepAliveStats object responsible for storing keep-alive statistics

        this.keepAliveStats = keepAliveStats;
    
public voidsetKeepAliveTimeoutInSeconds(int keepAliveTimeout)
Sets the number of seconds before a keep-alive connection that has been idle times out and is closed.

param
keepAliveTimeout Keep-alive timeout in number of seconds

        this.keepAliveTimeoutInSeconds = keepAliveTimeout;
    
public voidsetMaxKeepAliveRequests(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.

        this.maxKeepAliveRequests = maxKeepAliveRequests;
    
public voidsetMaxThreads(int maxThreads)
Set the number of threads used by this pipeline.

        this.maxThreads = maxThreads;
    
public voidsetMinSpareThreads(int minSpareThreads)
Set the minimum space thread this Pipeline can handle.

        throw new UnsupportedOperationException();
    
public voidsetMinThreads(int minThreads)
Set the minimum thread this Pipeline will creates when initializing.

param
minThreads the minimum number of threads.

        throw new UnsupportedOperationException();
    
public voidsetName(java.lang.String name)
Set the name of this Pipeline

        this.name = name;
    
public voidsetPipelineStatistic(PipelineStatistic pipelineStatistic)
Set the PipelineStatistic object used to gather statistic;

        this.pipelineStat = pipelineStatistic;
    
public voidsetPort(int port)
Set the port used by this Pipeline

param
port the port used by this Pipeline

        this.port = port;
    
public voidsetPriority(int priority)
Set the thread priority of the Pipeline

        this.priority = priority;
    
public voidsetQueueSizeInBytes(int maxQueueSizeInBytes)
Set the maximum pending connection this Pipeline can handle.

        throw new UnsupportedOperationException(); 
    
public voidsetThreadsIncrement(int threadsIncrement)

       throw new UnsupportedOperationException();
    
public voidsetThreadsTimeout(int threadsTimeout)

        this.firstReadTimeout = threadsTimeout;
    
public intsize()
Returns the number of tasks in this Pipeline.

return
Number of tasks in this Pipeline.

        return 0;
    
public voidstartPipeline()
Start the Pipeline and all associated WorkerThread

        if (isStarted){
            return;
        }
        ; // Do nothing
    
public voidstopPipeline()
Stop the Pipeline and all associated WorkerThread

        if (!isStarted){
            return;
        }
        isStarted = false;
        keepAliveCounts.clear();
    
public java.lang.StringtoString()

       return "name: " + name + " maxThreads: " + maxThreads ;        
    
public booleantrap(java.nio.channels.SelectionKey key)
Monitor keep-alive request count for the given connection.

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

        if ( maxKeepAliveRequests == -1) return true;
        
        Integer count = keepAliveCounts.get(key);
        if ( count == null ){
            count = 0;
            if (keepAliveStats != null) {
                keepAliveStats.incrementCountConnections();
            }
        }
        
        if ((count+1) > maxKeepAliveRequests){
            if (keepAliveStats != null) {
                keepAliveStats.incrementCountRefusals();
            }
            return false;
        }

        count++;
        keepAliveCounts.put(key, count);
        if (keepAliveStats != null) {
            keepAliveStats.incrementCountHits();
        }

        return true;
    
public voiduntrap(java.nio.channels.SelectionKey key)
Stop monitoring keep-alive request count for the given connection.

        if ( maxKeepAliveRequests == -1) return;
        
        keepAliveCounts.remove(key);