org.apache.excalibur.event.impl
Class RateLimitingPredicate

java.lang.Object
  extended byorg.apache.excalibur.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.5 $
Author:
Avalon Development Team

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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.
See Also:
EnqueuePredicate.accept(Object, Sink)

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.
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


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.