Package io.servicetalk.loadbalancer
Interface LoadBalancerBuilder<ResolvedAddress,C extends LoadBalancedConnection>
- Type Parameters:
ResolvedAddress
- The resolved address type.C
- The type of connection.
- All Known Implementing Classes:
DelegatingLoadBalancerBuilder
public interface LoadBalancerBuilder<ResolvedAddress,C extends LoadBalancedConnection>
Builder for
LoadBalancerFactory
that creates LoadBalancer
instances based upon the configuration.
The addresses are provided via the published
events
that signal the host's status
.
Instances returned handle ServiceDiscovererEvent.Status.AVAILABLE
,
ServiceDiscovererEvent.Status.EXPIRED
, and ServiceDiscovererEvent.Status.UNAVAILABLE
event statuses.
The created instances have the following behaviour:
- Host selection is performed based upon the provided
LoadBalancingPolicy
. If no policy is provided the default policy is round-robin. While it can be policy specific, most policies will avoid unhealthy hosts. - Host health is determined by the configured
OutlierDetectorConfig
. This is inferred from the results of requests and from actively probing for connectivity in accordance with the config. - Connections are created lazily, without any concurrency control on their creation. This can lead to over-provisioning connections when dealing with a requests surge.
- Existing connections are reused unless a selector passed to
LoadBalancer.selectConnection(Predicate, ContextMap)
suggests otherwise. This can lead to situations where connections will be used to their maximum capacity (for example in the context of pipelining) before new connections are created. - Closed connections are automatically pruned.
- When
Publisher
<ServiceDiscovererEvent
> delivers events withServiceDiscovererEvent.status()
of valueServiceDiscovererEvent.Status.UNAVAILABLE
, connections are immediately closed (gracefully) for the associatedServiceDiscovererEvent.address()
. In case ofServiceDiscovererEvent.Status.EXPIRED
, already established connections toServiceDiscovererEvent.address()
continue to be used for requests, but no new connections are created. In case the address' connections are busy, another host is tried. If all hosts are busy based on the selection mechanism of theLoadBalancingPolicy
, selection fails with aNoActiveHostException
.
-
Method Summary
Modifier and TypeMethodDescriptionbackgroundExecutor
(Executor backgroundExecutor) Set the backgroundExecutor
to use for determining time and scheduling background tasks such as those associated with outlier detection.build()
Builds theLoadBalancerFactory
configured by this builder.connectionSelectorPolicy
(ConnectionSelectorPolicy<C> connectionSelectorPolicy) Set theConnectionSelectorPolicy
to use with this load balancer.loadBalancerObserver
(LoadBalancerObserverFactory loadBalancerObserverFactory) Set theLoadBalancerObserverFactory
to use with this load balancer.loadBalancingPolicy
(LoadBalancingPolicy<ResolvedAddress, C> loadBalancingPolicy) Set theloadBalancingPolicy
to use with this load balancer.outlierDetectorConfig
(OutlierDetectorConfig outlierDetectorConfig) Set theOutlierDetectorConfig
to use with this load balancer.
-
Method Details
-
loadBalancingPolicy
LoadBalancerBuilder<ResolvedAddress,C> loadBalancingPolicy(LoadBalancingPolicy<ResolvedAddress, C> loadBalancingPolicy) Set theloadBalancingPolicy
to use with this load balancer.- Parameters:
loadBalancingPolicy
- theloadBalancingPolicy
to use- Returns:
this
-
loadBalancerObserver
LoadBalancerBuilder<ResolvedAddress,C> loadBalancerObserver(@Nullable LoadBalancerObserverFactory loadBalancerObserverFactory) Set theLoadBalancerObserverFactory
to use with this load balancer.- Parameters:
loadBalancerObserverFactory
- theLoadBalancerObserverFactory
to use, ornull
to not use an observer.- Returns:
- {code this}
-
outlierDetectorConfig
LoadBalancerBuilder<ResolvedAddress,C> outlierDetectorConfig(OutlierDetectorConfig outlierDetectorConfig) Set theOutlierDetectorConfig
to use with this load balancer.The outlier detection system works in conjunction with the load balancing policy to attempt to avoid hosts that have been determined to be unhealthy or slow. The details of the selection process are determined by the
LoadBalancingPolicy
while the health status is determined by the outlier detection configuration.- Parameters:
outlierDetectorConfig
- theOutlierDetectorConfig
to use, ornull
to use the default outlier detection.- Returns:
- {code this}
- See Also:
-
connectionSelectorPolicy
LoadBalancerBuilder<ResolvedAddress,C> connectionSelectorPolicy(ConnectionSelectorPolicy<C> connectionSelectorPolicy) Set theConnectionSelectorPolicy
to use with this load balancer.- Parameters:
connectionSelectorPolicy
- the factory of connection selection strategies to use.- Returns:
this
-
backgroundExecutor
Set the backgroundExecutor
to use for determining time and scheduling background tasks such as those associated with outlier detection.- Parameters:
backgroundExecutor
-Executor
to use as a time source and for scheduling background tasks.- Returns:
this
.
-
build
LoadBalancerFactory<ResolvedAddress,C> build()Builds theLoadBalancerFactory
configured by this builder.- Returns:
- a new instance of
LoadBalancerFactory
with settings from this builder.
-