org.d_haven.event.impl
Class RateLimitingPredicate

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

public class RateLimitingPredicate
extends java.lang.Object
implements EnqueuePredicate

This enqueue predicate implements input rate policing.

Version:
$Revision: 1.11 $
Author:
schierma

Field Summary
private  int m_depth
           
private  long m_lastTime
           
private  double m_regenTimeMs
           
private  double m_targetRate
           
private  int m_tokenCount
           
private static double SECOND
           
 
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, Sink sink)
          Tests the given element for acceptance onto the m_sink.
 boolean accept(java.lang.Object element, Sink sink)
          Tests the given element for acceptance onto the m_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.
private  boolean testRate(int tokenCount)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SECOND

private static final double SECOND
See Also:
Constant Field Values

m_targetRate

private double m_targetRate

m_depth

private int m_depth

m_tokenCount

private int m_tokenCount

m_lastTime

private long m_lastTime

m_regenTimeMs

private double m_regenTimeMs
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,
                      Sink sink)
Description copied from interface: EnqueuePredicate
Tests the given element for acceptance onto the m_sink.

Specified by:
accept in interface EnqueuePredicate
Parameters:
element - The element to enqueue
sink - The sink that is used for this predicate
Returns:
true if the sink accepts the element; false otherwise.

testRate

private boolean testRate(int tokenCount)

accept

public boolean accept(java.lang.Object[] elements,
                      Sink sink)
Description copied from interface: EnqueuePredicate
Tests the given element for acceptance onto the m_sink.

Specified by:
accept in interface EnqueuePredicate
Parameters:
elements - The array of elements to enqueue
sink - The sink that is used for this predicate
Returns:
true if the sink accepts all the elements; false otherwise.

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object