Class RateLimitedExecutor

java.lang.Object
uk.ac.ebi.utils.runcontrol.RateLimitedExecutor
All Implemented Interfaces:
Executor
Direct Known Subclasses:
DynamicRateExecutor

public class RateLimitedExecutor extends Object implements Executor
A rate limiting executor, based on RateLimiter.
Author:
brandizi
Date:
5 Oct 2015
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.google.common.util.concurrent.RateLimiter
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    RateLimitedExecutor(double requestsPerSecond)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    execute(Runnable action)
    Controls the execution of the action in such a way that it is run at no more than getRate() speed within a given JVM.
    double
    The maximum speed allowed by this executor, in actions received per second. 0 means no limit is applied.
    void
    setRate(double requestsPerSecond)
    Note that the new actual rate might be slightly different than the passed parameters, depends on how RateLimiter is implemented.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • rateLimiter

      protected com.google.common.util.concurrent.RateLimiter rateLimiter
  • Constructor Details

    • RateLimitedExecutor

      public RateLimitedExecutor(double requestsPerSecond)
      See Also:
  • Method Details

    • execute

      public void execute(Runnable action)
      Controls the execution of the action in such a way that it is run at no more than getRate() speed within a given JVM. This is useful when you have a service that is hurt if hammered too fast.
      Specified by:
      execute in interface Executor
    • getRate

      public double getRate()
      The maximum speed allowed by this executor, in actions received per second. 0 means no limit is applied.
    • setRate

      public void setRate(double requestsPerSecond)
      Note that the new actual rate might be slightly different than the passed parameters, depends on how RateLimiter is implemented.