|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.univocity.api.io.RateLimiter
public class RateLimiter
A very simple method call rate limiter, based on a time interval. Users can call waitAndGo()
or waitAndGo(long) to block the current thread before performing an operation that is potentially costly
on other resources (such as HTTP requests to remote servers).
| Constructor Summary | |
|---|---|
RateLimiter(long interval)
Creates a new rate limiter configured to allow for a given interval of time to elapse before allowing a process to continue. |
|
RateLimiter(String name,
long interval)
Creates a new rate limiter configured to allow for a given interval of time to elapse before allowing a process to continue. |
|
| Method Summary | |
|---|---|
void |
decreaseWaitTime(long timeToDecrease)
Decreases the wait time of the next process that will be put to wait. |
long |
getInterval()
Returns the current rate interval |
String |
getName()
Returns the name associated with this rate limiter, used for logging. |
long |
getWaitingCount()
Returns the number of threads blocked and waiting for their turn to execute |
void |
increaseWaitTime(long timeToIncrease)
Increases the wait time of the next process that will be put to wait. |
void |
setInterval(long interval)
Modifies the rate interval |
long |
waitAndGo()
Blocks the current process if the previous call to this method happened at a time less than the configured interval. |
long |
waitAndGo(long timeout)
Blocks the current process if the previous call to this method happened at a time less than the configured interval. |
long |
waitAndGo(String action)
Blocks the current process if the previous call to this method happened at a time less than the configured interval. |
long |
waitAndGo(String action,
long timeout)
Blocks the current process if the previous call to this method happened at a time less than the configured interval. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public RateLimiter(long interval)
interval - the interval to wait between each call to waitAndGo()
public RateLimiter(String name,
long interval)
name - a name for the rate limiter, used for logginginterval - the interval to wait between each call to waitAndGo()| Method Detail |
|---|
public String getName()
public final long getInterval()
public void setInterval(long interval)
interval - the new intervalpublic final long getWaitingCount()
public final long waitAndGo(long timeout)
throws TimeoutException
timeout - the maximum length of time the process is allowed to wait. A TimeoutException will
be thrown if the process got locked up for too long.
TimeoutException - if the wait time exceeds the given timeout. Will only be thrown after the process
gets unblocked - at some time potentially much longer than the given timeout.
public final long waitAndGo(String action,
long timeout)
throws TimeoutException
action - description of the action to be performed after the wait time is over. Used for logging.timeout - the maximum length of time the process is allowed to wait. A TimeoutException will
be thrown if the process got locked up for too long.
TimeoutException - if the wait time exceeds the given timeout. Will only be thrown after the process
gets unblocked - at some time potentially much longer than the given timeout.public final long waitAndGo()
public final long waitAndGo(String action)
action - description of the action to be performed after the wait time is over. Used for logging.
public final void decreaseWaitTime(long timeToDecrease)
timeToDecrease - length of time to decrease from the configured interval.public final void increaseWaitTime(long timeToIncrease)
timeToIncrease - length of time add to the configured interval.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||