Class EnvoyRateLimiterFactory

java.lang.Object
org.apache.beam.sdk.io.components.ratelimiter.EnvoyRateLimiterFactory
All Implemented Interfaces:
Serializable, AutoCloseable, RateLimiterFactory

public class EnvoyRateLimiterFactory extends Object implements RateLimiterFactory
A RateLimiterFactory for Envoy Rate Limit Service.
See Also:
  • Constructor Details

  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • getLimiter

      public RateLimiter getLimiter(RateLimiterContext context)
      Description copied from interface: RateLimiterFactory
      Creates a lightweight ratelimiter handle bound to a specific context.

      Use this when passing ratelimiter to IO components, which doesn't need to know about the configuration or the underlying ratelimiter service details. This is also useful in DoFns when you want to use the ratelimiter in a static way based on the compile time context.

      Specified by:
      getLimiter in interface RateLimiterFactory
      Parameters:
      context - The context for the ratelimit.
      Returns:
      A RateLimiter handle.
    • allow

      public boolean allow(RateLimiterContext context, int permits) throws IOException, InterruptedException
      Description copied from interface: RateLimiterFactory
      Blocks until the specified number of permits are acquired and returns true if the request was allowed or false if the request was rejected.

      Use this for when the ratelimit namespace or descriptors are not known at compile time. allows you to use the ratelimiter in a dynamic way based on the runtime data.

      Specified by:
      allow in interface RateLimiterFactory
      Parameters:
      context - The context for the ratelimit.
      permits - Number of permits to acquire.
      Returns:
      true if the request is allowed, false if rejected.
      Throws:
      IOException - if there is an error communicating with the ratelimiter service.
      InterruptedException - if the thread is interrupted while waiting.