LimeWire Collection Component API

org.limewire.collection
Class QueueCounter

java.lang.Object
  extended by org.limewire.collection.QueueCounter

public class QueueCounter
extends Object

Measures the average number of elements in a queueing system.

See Little's Law for more information.

    try{
        QueueCounter qc = new QueueCounter(10);
        System.out.println("Average size: " + qc.getAverageSize());
        for(int i = 0; i < 10; i++){
            qc.recordArrival();
            Thread.sleep( 1000 );
        }
        for(int i = 0; i < 10; i++)
            qc.recordDeparture();
        System.out.println("Average size: " + qc.getAverageSize());
    } catch(Exception e) {
        e.printStackTrace();
    }               

    Output:
        Average size: -1.0
        Average size: 5.500395106845166


Constructor Summary
QueueCounter(int historySize)
           
 
Method Summary
 double getAverageSize()
           
 boolean isStale()
           
 void recordArrival()
          record an arrival in the system
 void recordDeparture()
          record a departure from the system
 void reset()
          forgets all recorded data
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueueCounter

public QueueCounter(int historySize)
Method Detail

recordArrival

public void recordArrival()
record an arrival in the system


recordDeparture

public void recordDeparture()
record a departure from the system


getAverageSize

public double getAverageSize()
Returns:
the average number of elements in the system

isStale

public boolean isStale()
Returns:
if the system could be considered stale. More specifically, this returns true if all of the following are true: 1. we have enough historical data and 2. the system has been empty for longer than the period over which the historical data was recorded. Note that this is an arbitrary recommendation and may be completely irrelevant for some purposes.

reset

public void reset()
forgets all recorded data


LimeWire Collection Component API

Copyright © 2009 Lime Wire LLC. All Rights Reserved.