public class RateLimitingPredicate
extends java.lang.Object
implements org.apache.excalibur.event.EnqueuePredicate
| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
private double m_targetRate
private int m_depth
private int m_tokenCount
private long m_lastTime
private double m_regenTimeMs
private static final long MIN_REGENERATION_TIME
public RateLimitingPredicate(int depth)
depth - The token bucket depth.public RateLimitingPredicate(double targetRate,
int depth)
targetRate - The rate that is the target for this predicatedepth - The token bucket depth.public boolean accept(java.lang.Object element,
org.apache.excalibur.event.Sink sink)
accept in interface org.apache.excalibur.event.EnqueuePredicateEnqueuePredicate.accept(Object, Sink)public boolean accept(java.lang.Object[] elements,
org.apache.excalibur.event.Sink sink)
accept in interface org.apache.excalibur.event.EnqueuePredicateEnqueuePredicate.accept(Object, Sink)public double getTargetRate()
public int getDepth()
public int getBucketSize()
public void setTargetRate(double targetRate)
targetRate - the current rate limit.public void setDepth(int depth)
depth - The bucket depth as an integer.