Class EnvoyRateLimiterFactory

    • Constructor Detail

    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface java.lang.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 java.io.IOException,
                             java.lang.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:
        java.io.IOException - if there is an error communicating with the ratelimiter service.
        java.lang.InterruptedException - if the thread is interrupted while waiting.