Package io.servicetalk.http.utils
Class CacheConnectionHttpLoadBalanceFactory<ResolvedAddress>
java.lang.Object
io.servicetalk.http.utils.CacheConnectionHttpLoadBalanceFactory<ResolvedAddress>
- Type Parameters:
ResolvedAddress
- The resolved address type.
- All Implemented Interfaces:
LoadBalancerFactory<ResolvedAddress,
,FilterableStreamingHttpLoadBalancedConnection> HttpLoadBalancerFactory<ResolvedAddress>
,ExecutionStrategyInfluencer<ExecutionStrategy>
public final class CacheConnectionHttpLoadBalanceFactory<ResolvedAddress>
extends Object
implements HttpLoadBalancerFactory<ResolvedAddress>
A
HttpLoadBalancerFactory
that will cache successive connection creation attempts and return the same
Single
instead of creating a new connection each time. This is useful when a spike of connections occurs
instead of creating a new connection for each request, if the underlying protocol version supports concurrency
(pipelining, multiplexing) a single connection creation attempt can be used before the connection is actually
established, which will reduce the overall number of connectiosn required.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.servicetalk.http.api.HttpLoadBalancerFactory
HttpLoadBalancerFactory.DefaultFilterableStreamingHttpLoadBalancedConnection
-
Constructor Summary
ConstructorsConstructorDescriptionCacheConnectionHttpLoadBalanceFactory
(HttpLoadBalancerFactory<ResolvedAddress> delegate, ToIntFunction<ResolvedAddress> maxConcurrencyFunc) Create a new instance. -
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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.servicetalk.http.api.HttpLoadBalancerFactory
toLoadBalancedConnection, toLoadBalancedConnection
Methods inherited from interface io.servicetalk.client.api.LoadBalancerFactory
newLoadBalancer
-
Constructor Details
-
CacheConnectionHttpLoadBalanceFactory
public CacheConnectionHttpLoadBalanceFactory(HttpLoadBalancerFactory<ResolvedAddress> delegate, ToIntFunction<ResolvedAddress> maxConcurrencyFunc) Create a new instance.- Parameters:
delegate
- TheLoadBalancerFactory
to delegate to.maxConcurrencyFunc
- The default number of maximum concurrency requests per each address.
-
-
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
.
-
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.
-