Package io.servicetalk.http.api
Class DefaultHttpLoadBalancerFactory<ResolvedAddress>
java.lang.Object
io.servicetalk.http.api.DefaultHttpLoadBalancerFactory<ResolvedAddress>
- Type Parameters:
ResolvedAddress
- The type of address after resolution.
- All Implemented Interfaces:
LoadBalancerFactory<ResolvedAddress,
,FilterableStreamingHttpLoadBalancedConnection> HttpLoadBalancerFactory<ResolvedAddress>
,ExecutionStrategyInfluencer<ExecutionStrategy>
public final class DefaultHttpLoadBalancerFactory<ResolvedAddress>
extends Object
implements HttpLoadBalancerFactory<ResolvedAddress>
Default implementation of
HttpLoadBalancerFactory
.-
Constructor Summary
ConstructorDescriptionDefaultHttpLoadBalancerFactory
(LoadBalancerFactory<ResolvedAddress, FilterableStreamingHttpLoadBalancedConnection> rawFactory) Creates a new instance with execution strategy adapted from the underlying factory. -
Method Summary
Modifier and TypeMethodDescriptionnewLoadBalancer
(Publisher<? extends Collection<? extends ServiceDiscovererEvent<ResolvedAddress>>> eventPublisher, ConnectionFactory<ResolvedAddress, FilterableStreamingHttpLoadBalancedConnection> connectionFactory, String targetResource) Create a newLoadBalancer
.<T extends FilterableStreamingHttpLoadBalancedConnection>
LoadBalancer<T>newLoadBalancer
(String targetResource, Publisher<? extends Collection<? extends ServiceDiscovererEvent<ResolvedAddress>>> eventPublisher, ConnectionFactory<ResolvedAddress, T> connectionFactory) Create a newLoadBalancer
.Return anExecutionStrategy
that describes the offloads required by the influencer.Converts the passedFilterableStreamingHttpConnection
to aFilterableStreamingHttpLoadBalancedConnection
.toLoadBalancedConnection
(FilterableStreamingHttpConnection connection, ReservableRequestConcurrencyController concurrencyController, ContextMap context) Converts the passedFilterableStreamingHttpConnection
to aFilterableStreamingHttpLoadBalancedConnection
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.servicetalk.client.api.LoadBalancerFactory
newLoadBalancer
-
Constructor Details
-
DefaultHttpLoadBalancerFactory
public DefaultHttpLoadBalancerFactory(LoadBalancerFactory<ResolvedAddress, FilterableStreamingHttpLoadBalancedConnection> rawFactory) Creates a new instance with execution strategy adapted from the underlying factory.- Parameters:
rawFactory
-LoadBalancerFactory
to use
-
-
Method Details
-
newLoadBalancer
public <T extends FilterableStreamingHttpLoadBalancedConnection> LoadBalancer<T> newLoadBalancer(String targetResource, Publisher<? extends Collection<? extends ServiceDiscovererEvent<ResolvedAddress>>> eventPublisher, ConnectionFactory<ResolvedAddress, T> connectionFactory) Description copied from interface:LoadBalancerFactory
Create a newLoadBalancer
.- Specified by:
newLoadBalancer
in interfaceLoadBalancerFactory<ResolvedAddress,
FilterableStreamingHttpLoadBalancedConnection> - Type Parameters:
T
- Type of connections created by the passedConnectionFactory
.- Parameters:
targetResource
- AString
representation of the target resource for which the created instance will perform load balancing. Bear in mind, load balancing is performed over the a collection of hosts provided via theeventPublisher
which may not correspond directly to a single unresolved address, but potentially a merged collection.eventPublisher
- A stream ofCollection
<ServiceDiscovererEvent
> which theLoadBalancer
can use to connect to physical hosts. Typically generated fromServiceDiscoverer
.connectionFactory
-ConnectionFactory
that the returnedLoadBalancer
will use to generate new connections. ReturnedLoadBalancer
will own the responsibility for thisConnectionFactory
and hence will callAsyncCloseable.closeAsync()
whenAsyncCloseable.closeAsync()
is called.- Returns:
- a new
LoadBalancer
.
-
newLoadBalancer
public LoadBalancer<FilterableStreamingHttpLoadBalancedConnection> newLoadBalancer(Publisher<? extends Collection<? extends ServiceDiscovererEvent<ResolvedAddress>>> eventPublisher, ConnectionFactory<ResolvedAddress, FilterableStreamingHttpLoadBalancedConnection> connectionFactory, String targetResource) Description copied from interface:LoadBalancerFactory
Create a newLoadBalancer
.- Specified by:
newLoadBalancer
in interfaceLoadBalancerFactory<ResolvedAddress,
FilterableStreamingHttpLoadBalancedConnection> - Parameters:
eventPublisher
- A stream ofCollection
<ServiceDiscovererEvent
> which theLoadBalancer
can use to connect to physical hosts. Typically generated fromServiceDiscoverer
.connectionFactory
-ConnectionFactory
that the returnedLoadBalancer
will use to generate new connections. ReturnedLoadBalancer
will own the responsibility for thisConnectionFactory
and hence will callAsyncCloseable.closeAsync()
whenAsyncCloseable.closeAsync()
is called.targetResource
- AString
representation of the target resource for which the created instance will perform load balancing. Bear in mind, load balancing is performed over the collection of hosts provided via theeventPublisher
which may not correspond directly to a single unresolved address, but potentially a merged collection.- Returns:
- a new
LoadBalancer
.
-
toLoadBalancedConnection
public FilterableStreamingHttpLoadBalancedConnection toLoadBalancedConnection(FilterableStreamingHttpConnection connection) Description copied from interface:HttpLoadBalancerFactory
Converts the passedFilterableStreamingHttpConnection
to aFilterableStreamingHttpLoadBalancedConnection
.- Specified by:
toLoadBalancedConnection
in interfaceHttpLoadBalancerFactory<ResolvedAddress>
- Parameters:
connection
-FilterableStreamingHttpConnection
to convert- Returns:
FilterableStreamingHttpLoadBalancedConnection
for the passedFilterableStreamingHttpConnection
-
toLoadBalancedConnection
public FilterableStreamingHttpLoadBalancedConnection toLoadBalancedConnection(FilterableStreamingHttpConnection connection, ReservableRequestConcurrencyController concurrencyController, @Nullable ContextMap context) Description copied from interface:HttpLoadBalancerFactory
Converts the passedFilterableStreamingHttpConnection
to aFilterableStreamingHttpLoadBalancedConnection
.- Specified by:
toLoadBalancedConnection
in interfaceHttpLoadBalancerFactory<ResolvedAddress>
- Parameters:
connection
-FilterableStreamingHttpConnection
to convertconcurrencyController
-ReservableRequestConcurrencyController
to control access to the connectioncontext
- Acontext
of the caller (e.g. request/LB context) ornull
if no context- Returns:
FilterableStreamingHttpLoadBalancedConnection
for the passedFilterableStreamingHttpConnection
.
-
requiredOffloads
Description copied from interface:ExecutionStrategyInfluencer
Return anExecutionStrategy
that describes the offloads required by the influencer.- Specified by:
requiredOffloads
in interfaceExecutionStrategyInfluencer<ResolvedAddress>
- Specified by:
requiredOffloads
in interfaceHttpLoadBalancerFactory<ResolvedAddress>
- Specified by:
requiredOffloads
in interfaceLoadBalancerFactory<ResolvedAddress,
FilterableStreamingHttpLoadBalancedConnection> - Returns:
- the
ExecutionStrategy
required by the influencer.
-