com.sun.slamd.example
Class RateLimiter

java.lang.Object
  extended bycom.sun.slamd.example.RateLimiter

public class RateLimiter
extends java.lang.Object

This class defines a utility that can be used to limit the rate at which operations are performed. It works by setting a countdown timer to a given length of time in milliseconds, starting the timer, allowing the caller to perform an operation, and then sleeping for any remaining length of time. If the operation performed takes longer than the specified duration, then it will not sleep at all.


Constructor Summary
RateLimiter(int duration)
          Creates the rate limiter with the specified duration.
 
Method Summary
 int getDuration()
          Retrieves the configured duration for this rate limiter.
 void setDuration(int duration)
          Specifies the duration for this rate limiter.
 void sleepForRemainingTime()
          Sleeps for whatever time is remaining on the timer.
 void startTimer()
          Resets and starts the timer for this rate limiter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RateLimiter

public RateLimiter(int duration)
Creates the rate limiter with the specified duration.

Parameters:
duration - The total length of time in milliseconds that should elapse between the start of the timer and the limiter should stop sleeping.
Method Detail

getDuration

public int getDuration()
Retrieves the configured duration for this rate limiter.

Returns:
The configured duration for this rate limiter.

setDuration

public void setDuration(int duration)
Specifies the duration for this rate limiter.

Parameters:
duration - The duration for this rate limiter.

startTimer

public void startTimer()
Resets and starts the timer for this rate limiter.


sleepForRemainingTime

public void sleepForRemainingTime()
Sleeps for whatever time is remaining on the timer.