Package io.grpc.util
Class MultiChildLoadBalancer
- java.lang.Object
-
- io.grpc.LoadBalancer
-
- io.grpc.util.MultiChildLoadBalancer
-
- Direct Known Subclasses:
RoundRobinLoadBalancer
@Internal public abstract class MultiChildLoadBalancer extends LoadBalancer
A base load balancing policy for those policies which has multiple children such as ClusterManager or the petiole policies. For internal use only.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
MultiChildLoadBalancer.AcceptResolvedAddrRetVal
class
MultiChildLoadBalancer.ChildLbState
This represents the state of load balancer children.protected static class
MultiChildLoadBalancer.Endpoint
Endpoint is an optimization to quickly lookup and compare EquivalentAddressGroup address sets.-
Nested classes/interfaces inherited from class io.grpc.LoadBalancer
LoadBalancer.CreateSubchannelArgs, LoadBalancer.ErrorPicker, LoadBalancer.Factory, LoadBalancer.FixedResultPicker, LoadBalancer.Helper, LoadBalancer.PickDetailsConsumer, LoadBalancer.PickResult, LoadBalancer.PickSubchannelArgs, LoadBalancer.ResolvedAddresses, LoadBalancer.Subchannel, LoadBalancer.SubchannelPicker, LoadBalancer.SubchannelStateListener
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<MultiChildLoadBalancer.ChildLbState>
childLbStates
protected ConnectivityState
currentConnectivityState
private LoadBalancer.Helper
helper
private static java.util.logging.Logger
logger
protected LoadBalancerProvider
pickFirstLbProvider
protected boolean
resolvingAddresses
-
Fields inherited from class io.grpc.LoadBalancer
ATTR_HEALTH_CHECKING_CONFIG, DISABLE_SUBCHANNEL_RECONNECT_KEY, EMPTY_PICKER, HAS_HEALTH_PRODUCER_LISTENER_KEY, HEALTH_CONSUMER_LISTENER_ARG_KEY, IS_PETIOLE_POLICY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MultiChildLoadBalancer(LoadBalancer.Helper helper)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Status
acceptResolvedAddresses(LoadBalancer.ResolvedAddresses resolvedAddresses)
Override to completely replace the default logic or to do additional activities.protected MultiChildLoadBalancer.AcceptResolvedAddrRetVal
acceptResolvedAddressesInternal(LoadBalancer.ResolvedAddresses resolvedAddresses)
This does the work to update the child map and calculate which children have been removed.protected static ConnectivityState
aggregateState(ConnectivityState overallState, ConnectivityState childState)
protected java.util.Map<java.lang.Object,LoadBalancer.ResolvedAddresses>
createChildAddressesMap(LoadBalancer.ResolvedAddresses resolvedAddresses)
Override to utilize parsing of the policy configuration or alternative helper/lb generation.protected MultiChildLoadBalancer.ChildLbState
createChildLbState(java.lang.Object key)
Override to create an instance of a subclass.MultiChildLoadBalancer.ChildLbState
getChildLbState(java.lang.Object key)
MultiChildLoadBalancer.ChildLbState
getChildLbStateEag(EquivalentAddressGroup eag)
java.util.Collection<MultiChildLoadBalancer.ChildLbState>
getChildLbStates()
protected LoadBalancer.Helper
getHelper()
protected java.util.List<MultiChildLoadBalancer.ChildLbState>
getReadyChildren()
Filters out non-ready child load balancers (subchannels).void
handleNameResolutionError(Status error)
Handle the name resolution error.void
shutdown()
The channel asks the load-balancer to shutdown.protected void
shutdownRemoved(java.util.List<MultiChildLoadBalancer.ChildLbState> removedChildren)
private java.util.List<MultiChildLoadBalancer.ChildLbState>
updateChildrenWithResolvedAddresses(java.util.Map<java.lang.Object,LoadBalancer.ResolvedAddresses> newChildAddresses)
Returns removed children.protected abstract void
updateOverallBalancingState()
Using the state of all children will calculate the current connectivity state, update fields, generate a picker and then callLoadBalancer.Helper.updateBalancingState(ConnectivityState, SubchannelPicker)
.-
Methods inherited from class io.grpc.LoadBalancer
canHandleEmptyAddressListFromNameResolution, handleResolvedAddresses, handleSubchannelState, requestConnection
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
childLbStates
private java.util.List<MultiChildLoadBalancer.ChildLbState> childLbStates
-
helper
private final LoadBalancer.Helper helper
-
resolvingAddresses
protected boolean resolvingAddresses
-
pickFirstLbProvider
protected final LoadBalancerProvider pickFirstLbProvider
-
currentConnectivityState
protected ConnectivityState currentConnectivityState
-
-
Constructor Detail
-
MultiChildLoadBalancer
protected MultiChildLoadBalancer(LoadBalancer.Helper helper)
-
-
Method Detail
-
updateOverallBalancingState
protected abstract void updateOverallBalancingState()
Using the state of all children will calculate the current connectivity state, update fields, generate a picker and then callLoadBalancer.Helper.updateBalancingState(ConnectivityState, SubchannelPicker)
.
-
createChildAddressesMap
protected java.util.Map<java.lang.Object,LoadBalancer.ResolvedAddresses> createChildAddressesMap(LoadBalancer.ResolvedAddresses resolvedAddresses)
Override to utilize parsing of the policy configuration or alternative helper/lb generation. Override this if keys are not Endpoints or if child policies have configuration. Null map values preserve the child without delivering the child an update.
-
createChildLbState
protected MultiChildLoadBalancer.ChildLbState createChildLbState(java.lang.Object key)
Override to create an instance of a subclass.
-
acceptResolvedAddresses
public Status acceptResolvedAddresses(LoadBalancer.ResolvedAddresses resolvedAddresses)
Override to completely replace the default logic or to do additional activities.- Overrides:
acceptResolvedAddresses
in classLoadBalancer
- Parameters:
resolvedAddresses
- the resolved server addresses, attributes, and config.- Returns:
true
if the resolved addresses were accepted.false
if rejected.
-
handleNameResolutionError
public void handleNameResolutionError(Status error)
Handle the name resolution error. Override if you need special handling.- Specified by:
handleNameResolutionError
in classLoadBalancer
- Parameters:
error
- a non-OK status
-
shutdown
public void shutdown()
Description copied from class:LoadBalancer
The channel asks the load-balancer to shutdown. No more methods on this class will be called after this method. The implementation should shutdown all Subchannels and OOB channels, and do any other cleanup as necessary.- Specified by:
shutdown
in classLoadBalancer
-
acceptResolvedAddressesInternal
protected final MultiChildLoadBalancer.AcceptResolvedAddrRetVal acceptResolvedAddressesInternal(LoadBalancer.ResolvedAddresses resolvedAddresses)
This does the work to update the child map and calculate which children have been removed. You must callupdateOverallBalancingState()
to update the picker and callshutdownRemoved(List)
to shutdown the endpoints that have been removed.
-
updateChildrenWithResolvedAddresses
private java.util.List<MultiChildLoadBalancer.ChildLbState> updateChildrenWithResolvedAddresses(java.util.Map<java.lang.Object,LoadBalancer.ResolvedAddresses> newChildAddresses)
Returns removed children.
-
shutdownRemoved
protected final void shutdownRemoved(java.util.List<MultiChildLoadBalancer.ChildLbState> removedChildren)
-
aggregateState
@Nullable protected static ConnectivityState aggregateState(@Nullable ConnectivityState overallState, ConnectivityState childState)
-
getHelper
protected final LoadBalancer.Helper getHelper()
-
getChildLbStates
public final java.util.Collection<MultiChildLoadBalancer.ChildLbState> getChildLbStates()
-
getChildLbState
public final MultiChildLoadBalancer.ChildLbState getChildLbState(java.lang.Object key)
-
getChildLbStateEag
public final MultiChildLoadBalancer.ChildLbState getChildLbStateEag(EquivalentAddressGroup eag)
-
getReadyChildren
protected final java.util.List<MultiChildLoadBalancer.ChildLbState> getReadyChildren()
Filters out non-ready child load balancers (subchannels).
-
-