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 classMultiChildLoadBalancer.AcceptResolvedAddrRetValclassMultiChildLoadBalancer.ChildLbStateThis represents the state of load balancer children.protected static classMultiChildLoadBalancer.EndpointEndpoint 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>childLbStatesprotected ConnectivityStatecurrentConnectivityStateprivate LoadBalancer.Helperhelperprivate static java.util.logging.Loggerloggerprotected LoadBalancerProviderpickFirstLbProviderprotected booleanresolvingAddresses-
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 protectedMultiChildLoadBalancer(LoadBalancer.Helper helper)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description StatusacceptResolvedAddresses(LoadBalancer.ResolvedAddresses resolvedAddresses)Override to completely replace the default logic or to do additional activities.protected MultiChildLoadBalancer.AcceptResolvedAddrRetValacceptResolvedAddressesInternal(LoadBalancer.ResolvedAddresses resolvedAddresses)This does the work to update the child map and calculate which children have been removed.protected static ConnectivityStateaggregateState(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.ChildLbStatecreateChildLbState(java.lang.Object key)Override to create an instance of a subclass.MultiChildLoadBalancer.ChildLbStategetChildLbState(java.lang.Object key)MultiChildLoadBalancer.ChildLbStategetChildLbStateEag(EquivalentAddressGroup eag)java.util.Collection<MultiChildLoadBalancer.ChildLbState>getChildLbStates()protected LoadBalancer.HelpergetHelper()protected java.util.List<MultiChildLoadBalancer.ChildLbState>getReadyChildren()Filters out non-ready child load balancers (subchannels).voidhandleNameResolutionError(Status error)Handle the name resolution error.voidshutdown()The channel asks the load-balancer to shutdown.protected voidshutdownRemoved(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 voidupdateOverallBalancingState()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:
acceptResolvedAddressesin classLoadBalancer- Parameters:
resolvedAddresses- the resolved server addresses, attributes, and config.- Returns:
trueif the resolved addresses were accepted.falseif rejected.
-
handleNameResolutionError
public void handleNameResolutionError(Status error)
Handle the name resolution error. Override if you need special handling.- Specified by:
handleNameResolutionErrorin classLoadBalancer- Parameters:
error- a non-OK status
-
shutdown
public void shutdown()
Description copied from class:LoadBalancerThe 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:
shutdownin 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).
-
-