FileDocCategorySizeDatePackage
PipelineStatistic.javaAPI DocGlassfish v2 API11022Fri May 04 22:37:04 BST 2007com.sun.enterprise.web.connector.grizzly

PipelineStatistic

public class PipelineStatistic extends Object
This class is a placeholde for gathering statistic from a Pipeline
author
Jean-Francois Arcand

Fields Summary
private int
port
The port of which we gather statistics
private boolean
started
Is this object started?
private int
maxQueueSizeInBytes
Maximum pending connection before refusing requests.
private int
totalCount
The total number of connections queued during the lifetime of the pipeline
private int
peakCount
The largest number of connections that have been in the pipeline simultaneouly
private int
overflowCount
Total number of pipeline overflows
private ScheduledThreadPoolExecutor
countAverageExecutor
The Thread Pool used when gathering count statistic.
private Statistic
lastMinuteStat
Average number of connection queued in that last 1 minute
private Statistic
lastFiveMinuteStat
Average number of connection queued in that last 5 minute
private Statistic
lastFifteenMinuteStat
Average number of connection queued in that last 15 minute
private ConcurrentHashMap
stats
Placeholder to gather statistics.
private Pipeline
processorPipeline
The pipelines whose stats are being collected
private Future[]
futures
Future instance in case we need to stop this object.
private int
totalAcceptCount
Total number of connections that have been accepted.
Constructors Summary
public PipelineStatistic(int port)
Constructor

param
port Port number for which pipeline (connection) stats will be gathered



    // -------------------------------------------------------------------//
    
    
                      
       
        this.port = port;
        
        countAverageExecutor = new ScheduledThreadPoolExecutor(3,
            new GrizzlyThreadFactory("GrizzlyPipelineStat",
                port,Thread.NORM_PRIORITY));        
    
Methods Summary
public booleangather(int queueLength)
Gather Pipeline statistic.

        if ( queueLength == maxQueueSizeInBytes){
            overflowCount++;
            return false;
        }
       
        if ( queueLength > 0 )
            totalCount++;
        
        // Track peak of this Pipeline
        if (queueLength > peakCount) {
            peakCount = queueLength;
        } 
        return true;
    
private intgetCountAverage(int minutes)
Gets the average number of connection queued in the last minutes minutes.

param
minutes The number of minutes for which the average number of connections queued is requested
return
Average number of connections queued

        Statistic stat = stats.get((minutes * 60));
        return (stat == null ? 0 : stat.average());
    
public intgetCountOverflows()
Total number of pipeline overflow

        return overflowCount;
    
public intgetCountQueued()
Gets the number of connections currently in the queue

return
Number of connections currently in the queue

        int size = 0;

        if (processorPipeline != null) {
            size += processorPipeline.size();
        }

        return size;
    
public intgetCountQueued15MinuteAverage()
Gets the average number of connections queued in the last 15 minutes

return
Average number of connections queued in the last 15 minutes

        return getCountAverage(15);
    
public intgetCountQueued1MinuteAverage()
Gets the average number of connections queued in the last 1 minute

return
Average number of connections queued in the last 1 minute

        return getCountAverage(1);
    
public intgetCountQueued5MinuteAverage()
Gets the average number of connections queued in the last 5 minutes

return
Average number of connections queued in the last 5 minutes

        return getCountAverage(5);
    
public intgetCountTotalConnections()
Gets the total number of connections that have been accepted.

return
Total number of connections that have been accepted.

        return totalAcceptCount;
    
public intgetCountTotalQueued()
Gets the total number of connections that have been queued. A given connection may be queued multiple times, so counttotalqueued may be greater than or equal to counttotalconnections.

return
Total number of connections that have been queued

        return totalCount;
    
public intgetMaxQueued()
Gets the maximum size of the connection queue

return
Maximum size of the connection queue

        return maxQueueSizeInBytes;
    
public intgetPeakQueued()
Gets the largest number of connections that were in the queue simultaneously.

return
Largest number of connections that were in the queue simultaneously

       return peakCount;
    
public intgetQueueSizeInBytes()
Get the maximum pending connection this Pipeline can handle.

        return maxQueueSizeInBytes;
    
public intgetTicksTotalQueued()
Gets the total number of ticks that connections have spent in the queue. A tick is a system-dependent unit of time.

return
Total number of ticks that connections have spent in the queue

        return -1; // Not supported
    
public voidincrementTotalAcceptCount()

        totalAcceptCount++;
    
voidsetProcessorPipeline(Pipeline processorPipeline)

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

        this.maxQueueSizeInBytes = maxQueueSizeInBytesCount;
    
public voidstart()
Start gathering statistics.

    
        if ( started ) return;
        
        futures[0] = countAverageExecutor.scheduleAtFixedRate(lastMinuteStat, 1 , 
                lastMinuteStat.getSeconds(), TimeUnit.SECONDS);
        futures[1] = countAverageExecutor.scheduleAtFixedRate(lastFiveMinuteStat, 1 , 
                lastFiveMinuteStat.getSeconds(), TimeUnit.SECONDS);
        futures[2] = countAverageExecutor.scheduleAtFixedRate(lastFifteenMinuteStat, 1 , 
                lastFifteenMinuteStat.getSeconds(), TimeUnit.SECONDS);    
        
        stats.put(lastMinuteStat.getSeconds(), lastMinuteStat);
        stats.put(lastFiveMinuteStat.getSeconds(), lastFiveMinuteStat);
        stats.put(lastFifteenMinuteStat.getSeconds(), lastFifteenMinuteStat);
        
        started = true;
    
public voidstop()
Stop gathering statistics.

        if ( !started ) return;
        
        for (Future future: futures){
            future.cancel(true);
        }
               
        stats.clear();
        started = false;