Class Throttle

java.lang.Object
com.northconcepts.datapipeline.throttle.Throttle

public class Throttle extends Object
Limits the average rate measured by a Meter by making the calling thread sleep while the count is ahead of the allowed rate.
  • Constructor Details

    • Throttle

      public Throttle(Meter meter, int unitsPerSecond)
  • Method Details

    • getMeter

      public Meter getMeter()
    • getUnitsPerSecond

      public int getUnitsPerSecond()
      Returns the maximum average rate, in the meter's units per second, that throttle() enforces.
    • setUnitsPerSecond

      public void setUnitsPerSecond(int unitsPerSecond)
      Sets the maximum average rate, in the meter's units per second, that throttle() enforces.
    • getPeekUnitsPerSecond

      public double getPeekUnitsPerSecond()
      Returns the highest rate (units per second) the meter reported when throttle() was called.
    • throttle

      public void throttle() throws InterruptedException
      Sleeps the calling thread long enough to bring the meter's average rate back down to the limit; waits under 10 milliseconds are skipped.
      Throws:
      InterruptedException
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Adds this throttle's limit, peak rate and meter state to the given exception and returns it.