ch.bind.philib.util
Class LeakyBucket
java.lang.Object
ch.bind.philib.util.LeakyBucket
public final class LeakyBucket
- extends Object
An implementation of the leaky bucket pattern for throughput control.
- Author:
- Philipp Meinen
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
withTakesPerSecond
public static LeakyBucket withTakesPerSecond(double takesPerSecond,
long capacity)
withTakeIntervalMs
public static LeakyBucket withTakeIntervalMs(long takeIntervalMs,
long capacity)
withTakeIntervalUs
public static LeakyBucket withTakeIntervalUs(long takeIntervalUs,
long capacity)
withTakeIntervalNs
public static LeakyBucket withTakeIntervalNs(long takeIntervalNs,
long capacity)
getCapacity
public long getCapacity()
take
public void take(long amount)
take
public void take(long amount,
long timeNs)
canTake
public long canTake()
canTake
public long canTake(long timeNs)
- Parameters:
timeNs - a relative timestamp as provided by System.nanoTime() and not
System.currentTimeMillis().
- Returns:
nextTakeNs
public long nextTakeNs()
nextTakeNs
public long nextTakeNs(long timeNs)
- Parameters:
timeNs - a relative timestamp as provided by System.nanoTime() and not
System.currentTimeMillis().
- Returns:
nextTakeUs
public long nextTakeUs()
nextTakeMs
public long nextTakeMs()
sleepUntilAvailable
public void sleepUntilAvailable()
throws InterruptedException
- Throws:
InterruptedException
Copyright © 2013. All Rights Reserved.