Package io.grpc.util

Class HealthProducerHelper


  • @Internal
    public final class HealthProducerHelper
    extends ForwardingLoadBalancerHelper
    A new LoadBalancer.Helper used by health producer systems to build health notification chain, via LoadBalancer.CreateSubchannelArgs. The leaf health consumer is pick first. Each health producer uses this helper. The health producers should make state listener a pass-through and manipulate the LoadBalancer.CreateSubchannelArgs for health notifications. The helper detects health listener parent. The root health producer in the chain will fan out the subchannel state change to both state listener and health listener.

    Example usage:

    
     class HealthProducerLB {
       private final LoadBalancer.Helper helper;
       public HealthProducer(Helper helper) {
         this.helper = new MyHelper(HealthCheckUtil.HealthCheckHelper(helper));
       }
       class MyHelper implements LoadBalancer.Helper {
         public void createSubchannel(CreateSubchannelArgs args) {
           SubchannelStateListener originalListener =
             args.getAttributes(HEALTH_CHECK_CONSUMER_LISTENER);
           if (hcListener != null) {
             // Implement a health listener that producers health check information.
             SubchannelStateListener myListener = MyHealthListener(originalListener);
             args = args.toBuilder.setOption(HEALTH_CHECK_CONSUMER_LISTENER, myListener);
           }
           return super.createSubchannel(args);
         }
       }
      }