org.apache.excalibur.event.impl
Class RateLimitingPredicate

java.lang.Object
  extended by org.apache.excalibur.event.impl.RateLimitingPredicate
All Implemented Interfaces:
org.apache.excalibur.event.EnqueuePredicate

public class RateLimitingPredicate
extends java.lang.Object
implements org.apache.excalibur.event.EnqueuePredicate

This enqueue predicate implements input rate policing.

Version:
$Revision: 1.5 $
Author:
Avalon Development Team

Field Summary
private  int m_depth
          The depth of the token bucket
private  long m_lastTime
           
private  double m_regenTimeMs
           
private  double m_targetRate
          The rate to which the enqueuing should be limited
private  int m_tokenCount
           
private static long MIN_REGENERATION_TIME
          Number of milliseconds between regenerations
 
Constructor Summary
RateLimitingPredicate(double targetRate, int depth)
          Create a new RateLimitingPredicate for the given sink, targetRate, and token bucket depth.
RateLimitingPredicate(int depth)
          Create a new RateLimitingPredicate for the given sink, bucket depth and no rate limit.
 
Method Summary
 boolean accept(java.lang.Object[] elements, org.apache.excalibur.event.Sink sink)
           
 boolean accept(java.lang.Object element, org.apache.excalibur.event.Sink sink)
           
 int getBucketSize()
          Returns the number of tokens currently in the bucket.
 int getDepth()
          Returns the current depth.
 double getTargetRate()
          Returns the current rate limit.
 void setDepth(int depth)
          Allows to set the bucket depth.
 void setTargetRate(double targetRate)
          Allows to set the rate limit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_targetRate

private double m_targetRate
The rate to which the enqueuing should be limited


m_depth

private int m_depth
The depth of the token bucket


m_tokenCount

private int m_tokenCount

m_lastTime

private long m_lastTime

m_regenTimeMs

private double m_regenTimeMs

MIN_REGENERATION_TIME

private static final long MIN_REGENERATION_TIME
Number of milliseconds between regenerations

See Also:
Constant Field Values
Constructor Detail

RateLimitingPredicate

public RateLimitingPredicate(int depth)
Create a new RateLimitingPredicate for the given sink, bucket depth and no rate limit.

Parameters:
depth - The token bucket depth.
Since:
May 15, 2002

RateLimitingPredicate

public RateLimitingPredicate(double targetRate,
                             int depth)
Create a new RateLimitingPredicate for the given sink, targetRate, and token bucket depth. A rate of -1.0 indicates no rate limit.

Parameters:
targetRate - The rate that is the target for this predicate
depth - The token bucket depth.
Since:
May 15, 2002
Method Detail

accept

public boolean accept(java.lang.Object element,
                      org.apache.excalibur.event.Sink sink)
Specified by:
accept in interface org.apache.excalibur.event.EnqueuePredicate
See Also:
EnqueuePredicate.accept(Object, Sink)

accept

public boolean accept(java.lang.Object[] elements,
                      org.apache.excalibur.event.Sink sink)
Specified by:
accept in interface org.apache.excalibur.event.EnqueuePredicate
See Also:
EnqueuePredicate.accept(Object, Sink)

getTargetRate

public double getTargetRate()
Returns the current rate limit.

Returns:
double the current target rate
Since:
May 15, 2002

getDepth

public int getDepth()
Returns the current depth.

Returns:
int The current bucket depth.
Since:
May 15, 2002

getBucketSize

public int getBucketSize()
Returns the number of tokens currently in the bucket.

Returns:
int the number of tokens currently in the bucket.
Since:
May 15, 2002

setTargetRate

public void setTargetRate(double targetRate)
Allows to set the rate limit. A limit of -1.0 indicates no rate limit.

Parameters:
targetRate - the current rate limit.
Since:
May 15, 2002

setDepth

public void setDepth(int depth)
Allows to set the bucket depth.

Parameters:
depth - The bucket depth as an integer.
Since:
May 15, 2002