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 connections 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 anExecutionStrategythat describes the offloads required by the influencer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.servicetalk.http.api.HttpLoadBalancerFactory
toLoadBalancedConnection, toLoadBalancedConnectionMethods 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- TheLoadBalancerFactoryto 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:LoadBalancerFactoryCreate a newLoadBalancer.- Specified by:
newLoadBalancerin interfaceLoadBalancerFactory<ResolvedAddress,FilterableStreamingHttpLoadBalancedConnection> - Type Parameters:
T- Type of connections created by the passedConnectionFactory.- Parameters:
targetResource- AStringrepresentation 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 theeventPublisherwhich may not correspond directly to a single unresolved address, but potentially a merged collection.eventPublisher- A stream ofCollection<ServiceDiscovererEvent> which theLoadBalancercan use to connect to physical hosts. Typically generated fromServiceDiscoverer.connectionFactory-ConnectionFactorythat the returnedLoadBalancerwill use to generate new connections. ReturnedLoadBalancerwill own the responsibility for thisConnectionFactoryand 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:LoadBalancerFactoryCreate a newLoadBalancer.- Specified by:
newLoadBalancerin interfaceLoadBalancerFactory<ResolvedAddress,FilterableStreamingHttpLoadBalancedConnection> - Parameters:
eventPublisher- A stream ofCollection<ServiceDiscovererEvent> which theLoadBalancercan use to connect to physical hosts. Typically generated fromServiceDiscoverer.connectionFactory-ConnectionFactorythat the returnedLoadBalancerwill use to generate new connections. ReturnedLoadBalancerwill own the responsibility for thisConnectionFactoryand hence will callAsyncCloseable.closeAsync()whenAsyncCloseable.closeAsync()is called.targetResource- AStringrepresentation 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 theeventPublisherwhich may not correspond directly to a single unresolved address, but potentially a merged collection.- Returns:
- a new
LoadBalancer.
-
requiredOffloads
Description copied from interface:ExecutionStrategyInfluencerReturn anExecutionStrategythat describes the offloads required by the influencer.- Specified by:
requiredOffloadsin interfaceExecutionStrategyInfluencer<ResolvedAddress>- Specified by:
requiredOffloadsin interfaceHttpLoadBalancerFactory<ResolvedAddress>- Specified by:
requiredOffloadsin interfaceLoadBalancerFactory<ResolvedAddress,FilterableStreamingHttpLoadBalancedConnection> - Returns:
- the
ExecutionStrategyrequired by the influencer.
-