Package io.grpc

Class LoadBalancerRegistry


  • @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
    @ThreadSafe
    public final class LoadBalancerRegistry
    extends java.lang.Object
    Registry of LoadBalancerProviders. The default instance loads providers at runtime through the Java service provider mechanism.
    Since:
    1.17.0
    • Constructor Detail

      • LoadBalancerRegistry

        public LoadBalancerRegistry()
    • Method Detail

      • register

        public void register​(LoadBalancerProvider provider)
        Register a provider.

        If the provider's isAvailable() returns false, this method will throw IllegalArgumentException.

        If more than one provider with the same policy name are registered, the one with the highest priority will be effective. If there are more than one name-sake providers rank the highest priority, the one registered first will be effective.

      • deregister

        public void deregister​(LoadBalancerProvider provider)
        Deregisters a provider. No-op if the provider is not in the registry. If there are more than one providers with the same policy name as the deregistered one in the registry, one of them will become the effective provider for that policy, per the rule documented in register(io.grpc.LoadBalancerProvider).
        Parameters:
        provider - the provider that was added to the register via register(io.grpc.LoadBalancerProvider).
      • getDefaultRegistry

        public static LoadBalancerRegistry getDefaultRegistry()
        Returns the default registry that loads providers via the Java service loader mechanism.
      • getProvider

        @Nullable
        public LoadBalancerProvider getProvider​(java.lang.String policy)
        Returns the effective provider for the given load-balancing policy, or null if no suitable provider can be found. Each provider declares its policy name via LoadBalancerProvider.getPolicyName().