Class HealthProducerHelper
- java.lang.Object
-
- io.grpc.LoadBalancer.Helper
-
- io.grpc.util.ForwardingLoadBalancerHelper
-
- io.grpc.util.HealthProducerHelper
-
@Internal public final class HealthProducerHelper extends ForwardingLoadBalancerHelper
A newLoadBalancer.Helperused by health producer systems to build health notification chain, viaLoadBalancer.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 theLoadBalancer.CreateSubchannelArgsfor 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); } } }
-
-
Constructor Summary
Constructors Constructor Description HealthProducerHelper(LoadBalancer.Helper helper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LoadBalancer.SubchannelcreateSubchannel(LoadBalancer.CreateSubchannelArgs args)Creates a Subchannel, which is a logical connection to the given group of addresses which are considered equivalent.protected LoadBalancer.Helperdelegate()Returns the underlying helper.voidupdateBalancingState(ConnectivityState newState, LoadBalancer.SubchannelPicker newPicker)Set a new state with a new picker to the channel.-
Methods inherited from class io.grpc.util.ForwardingLoadBalancerHelper
createOobChannel, createOobChannel, createResolvingOobChannel, createResolvingOobChannelBuilder, createResolvingOobChannelBuilder, getAuthority, getChannelCredentials, getChannelLogger, getChannelTarget, getMetricRecorder, getNameResolverArgs, getNameResolverRegistry, getScheduledExecutorService, getSynchronizationContext, getUnsafeChannelCredentials, ignoreRefreshNameResolutionCheck, refreshNameResolution, toString, updateOobChannelAddresses, updateOobChannelAddresses
-
-
-
-
Constructor Detail
-
HealthProducerHelper
public HealthProducerHelper(LoadBalancer.Helper helper)
-
-
Method Detail
-
createSubchannel
public LoadBalancer.Subchannel createSubchannel(LoadBalancer.CreateSubchannelArgs args)
Description copied from class:LoadBalancer.HelperCreates a Subchannel, which is a logical connection to the given group of addresses which are considered equivalent. Theattrsare custom attributes associated with this Subchannel, and can be accessed later throughSubchannel.getAttributes().The LoadBalancer is responsible for closing unused Subchannels, and closing all Subchannels within
LoadBalancer.shutdown().It must be called from
the Synchronization Context- Overrides:
createSubchannelin classForwardingLoadBalancerHelper- Returns:
- Must return a valid Subchannel object, may not return null.
-
delegate
protected LoadBalancer.Helper delegate()
Description copied from class:ForwardingLoadBalancerHelperReturns the underlying helper.- Specified by:
delegatein classForwardingLoadBalancerHelper
-
updateBalancingState
public void updateBalancingState(ConnectivityState newState, LoadBalancer.SubchannelPicker newPicker)
Description copied from class:LoadBalancer.HelperSet a new state with a new picker to the channel.When a new picker is provided via
updateBalancingState(), the channel will apply the picker on all buffered RPCs, by callingLoadBalancer.SubchannelPicker.pickSubchannel( LoadBalancer.PickSubchannelArgs).The channel will hold the picker and use it for all RPCs, until
updateBalancingState()is called again and a new picker replaces the old one. IfupdateBalancingState()has never been called, the channel will buffer all RPCs until a picker is provided.It should be called from the Synchronization Context. Currently will log a warning if violated. It will become an exception eventually. See #5015 for the background.
The passed state will be the channel's new state. The SHUTDOWN state should not be passed and its behavior is undefined.
- Overrides:
updateBalancingStatein classForwardingLoadBalancerHelper
-
-