ch.bind.philib.util
Class LeakyBucket

java.lang.Object
  extended by ch.bind.philib.util.LeakyBucket

public final class LeakyBucket
extends Object

An implementation of the leaky bucket pattern for throughput control.

Author:
Philipp Meinen

Method Summary
 long canFill()
           
 void fill(long amount)
           
 long getCapacity()
           
 long nextFillMs()
           
 long nextFillNs()
           
 long nextFillUs()
           
 void sleepWhileNotFillable()
           
static LeakyBucket withLeakIntervalMs(long leakIntervalMs, long capacity)
           
static LeakyBucket withLeakIntervalNs(long leakIntervalNs, long capacity)
           
static LeakyBucket withLeakIntervalUs(long leakIntervalUs, long capacity)
           
static LeakyBucket withLeakPerSecond(double leakPerSecond, long capacity)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

withLeakPerSecond

public static LeakyBucket withLeakPerSecond(double leakPerSecond,
                                            long capacity)

withLeakIntervalMs

public static LeakyBucket withLeakIntervalMs(long leakIntervalMs,
                                             long capacity)

withLeakIntervalUs

public static LeakyBucket withLeakIntervalUs(long leakIntervalUs,
                                             long capacity)

withLeakIntervalNs

public static LeakyBucket withLeakIntervalNs(long leakIntervalNs,
                                             long capacity)

getCapacity

public long getCapacity()

fill

public void fill(long amount)

canFill

public long canFill()

nextFillNs

public long nextFillNs()

nextFillUs

public long nextFillUs()

nextFillMs

public long nextFillMs()

sleepWhileNotFillable

public void sleepWhileNotFillable()
                           throws InterruptedException
Throws:
InterruptedException


Copyright © 2013. All Rights Reserved.