Class HealthCheckingLoadBalancerUtil


  • @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5025")
    public final class HealthCheckingLoadBalancerUtil
    extends java.lang.Object
    Utility for enabling client-side health checking for LoadBalancers.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static io.grpc.LoadBalancer newHealthCheckingLoadBalancer​(io.grpc.LoadBalancer.Factory factory, io.grpc.LoadBalancer.Helper helper)
      Creates a health-checking-capable LoadBalancer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • newHealthCheckingLoadBalancer

        public static io.grpc.LoadBalancer newHealthCheckingLoadBalancer​(io.grpc.LoadBalancer.Factory factory,
                                                                         io.grpc.LoadBalancer.Helper helper)
        Creates a health-checking-capable LoadBalancer. This method is used to implement health-checking-capable LoadBalancer.Factorys, which will typically written this way:
         public class HealthCheckingFooLbFactory extends LoadBalancer.Factory {
           // This is the original balancer implementation that doesn't have health checking
           private final LoadBalancer.Factory fooLbFactory;
        
           ...
        
           // Returns the health-checking-capable version of FooLb   
           public LoadBalancer newLoadBalancer(Helper helper) {
             return HealthCheckingLoadBalancerUtil.newHealthCheckingLoadBalancer(fooLbFactory, helper);
           }
         }
         

        As a requirement for the original LoadBalancer, it must call Helper.createSubchannel() from the Synchronization Context, or createSubchannel() will throw.

        Parameters:
        factory - the original factory that implements load-balancing logic without health checking
        helper - the helper passed to the resulting health-checking LoadBalancer.