|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.slamd.example.RateLimiter
public class RateLimiter
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 |
|---|
public RateLimiter(int duration)
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 |
|---|
public int getDuration()
public void setDuration(int duration)
duration - The duration for this rate limiter.public void startTimer()
public void sleepForRemainingTime()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||