Class RateLimiterClientCache


  • public class RateLimiterClientCache
    extends java.lang.Object
    A static cache for ManagedChannels to Rate Limit Service.

    This class ensures that multiple DoFn instances (threads) in the same Worker sharing the same RLS address will share a single ManagedChannel.

    It uses reference counting to close the channel when it is no longer in use by any RateLimiter instance.

    • Method Detail

      • getOrCreate

        public static RateLimiterClientCache getOrCreate​(java.lang.String address)
        Gets or creates a cached client for the given address. Increments the reference count. Synchronized on the class to prevent race conditions when multiple instances call getOrCreate() simultaneously
      • getChannel

        public io.grpc.ManagedChannel getChannel()
      • release

        public void release()
        Releases the client. Decrements the reference count. If reference count reaches 0, the channel is shut down and removed from the cache. Synchronized on the class to prevent race conditions when multiple threads call release() simultaneously and to prevent race conditions between getOrCreate() and release() calls.