Package io.grpc.util
Class HealthProducerHelper
java.lang.Object
io.grpc.LoadBalancer.Helper
io.grpc.util.ForwardingLoadBalancerHelper
io.grpc.util.HealthProducerHelper
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);
}
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a Subchannel, which is a logical connection to the given group of addresses which are considered equivalent.protected LoadBalancer.Helperdelegate()Returns the underlying helper.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, updateBalancingState, updateOobChannelAddresses, updateOobChannelAddresses
-
Field Details
-
delegate
-
-
Constructor Details
-
HealthProducerHelper
-
-
Method Details
-
createSubchannel
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
Description copied from class:ForwardingLoadBalancerHelperReturns the underlying helper.- Specified by:
delegatein classForwardingLoadBalancerHelper
-