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);
}
}
}
-
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.Helper
delegate()
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
-
Constructor Details
-
HealthProducerHelper
-
-
Method Details
-
createSubchannel
Description copied from class:LoadBalancer.Helper
Creates a Subchannel, which is a logical connection to the given group of addresses which are considered equivalent. Theattrs
are 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:
createSubchannel
in classForwardingLoadBalancerHelper
- Returns:
- Must return a valid Subchannel object, may not return null.
-
delegate
Description copied from class:ForwardingLoadBalancerHelper
Returns the underlying helper.- Specified by:
delegate
in classForwardingLoadBalancerHelper
-