-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
In hierarchical LoadBalancers (e.g., XdsLoadBalancer) or wrapped LoadBalancers (e.g., HealthCheckingLoadBalancerFactory, the top-level LoadBalancer receives Subchannel state updates from the Channel impl, and they almost always pass it down to its children LoadBalancers.
Sometimes the children LoadBalancers are not directly created by the parent, thus requires whatever API in the middle to also pass Subchannel state updates, complicating that API. For example, the proposed RequestDirector includes handleSubchannelState() solely to plumb state updates to where they are used.
If we instead pass a listener when creating a Subchannel to accept state updates, those updates could be directly passed to where the Subchannel is created, skipping the explicit chaining in the middle:
abstract class SubchannelStateListener {
void onSubchannelState(ConnectivityStateInfo newState);
}
abstract class LoadBalancer.Helper {
abstract Subchannel createSubchannel(
List<EquivalentAddressGroup> addrs, Attributes attrs, SubchannelStateListener stateListener);
}If a wrapping LoadBalancer wants to look at or alter the Subchannel state updates for its delegate (like in HealthCheckingLoadBalancerFactory), it can still do so in the wrapping LoadBalancer.Helper passed to the delegate, by intercepting the SubchannelStateListener.