org.d_haven.event.impl

Class RateLimitingPredicate

public class RateLimitingPredicate extends Object implements EnqueuePredicate

This enqueue predicate implements input rate policing.

Version: $Revision: 1.11 $

Author: schierma

Field Summary
intm_depth
longm_lastTime
doublem_regenTimeMs
doublem_targetRate
intm_tokenCount
static doubleSECOND
Constructor Summary
RateLimitingPredicate(int depth)
Create a new RateLimitingPredicate for the given sink, bucket depth and no rate limit.
RateLimitingPredicate(double targetRate, int depth)
Create a new RateLimitingPredicate for the given sink, targetRate, and token bucket depth.
Method Summary
booleanaccept(Object element, Sink sink)
booleanaccept(Object[] elements, Sink sink)
intgetBucketSize()
Returns the number of tokens currently in the bucket.
intgetDepth()
Returns the current depth.
doublegetTargetRate()
Returns the current rate limit.
voidsetDepth(int depth)
Allows to set the bucket depth.
voidsetTargetRate(double targetRate)
Allows to set the rate limit.
booleantestRate(int tokenCount)
StringtoString()

Field Detail

m_depth

private int m_depth

m_lastTime

private long m_lastTime

m_regenTimeMs

private double m_regenTimeMs

m_targetRate

private double m_targetRate

m_tokenCount

private int m_tokenCount

SECOND

private static final double SECOND

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(Object element, Sink sink)

accept

public boolean accept(Object[] elements, Sink sink)

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

getDepth

public int getDepth()
Returns the current depth.

Returns: int The current bucket depth.

Since: May 15, 2002

getTargetRate

public double getTargetRate()
Returns the current rate limit.

Returns: double the current target rate

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

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

testRate

private boolean testRate(int tokenCount)

toString

public String toString()