Package io.servicetalk.client.api
Class LimitingConnectionFactoryFilter<ResolvedAddress,C extends ListenableAsyncCloseable>
java.lang.Object
io.servicetalk.client.api.LimitingConnectionFactoryFilter<ResolvedAddress,C>
- Type Parameters:
ResolvedAddress- The type of a resolved address that can be used for connecting.C- The type of connections created by this factory.
- All Implemented Interfaces:
ConnectionFactoryFilter<ResolvedAddress,,C> ExecutionStrategyInfluencer<ExecutionStrategy>
public final class LimitingConnectionFactoryFilter<ResolvedAddress,C extends ListenableAsyncCloseable>
extends Object
implements ConnectionFactoryFilter<ResolvedAddress,C>
A
ConnectionFactory that limits the total number of active connections created using this
ConnectionFactory. A connection is considered active if ListenableAsyncCloseable.onClose() has
not yet terminated.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceLimitingConnectionFactoryFilter.ConnectionLimiter<ResolvedAddress,C extends ListenableAsyncCloseable> A contract to limit number of connections created byLimitingConnectionFactoryFilter. -
Method Summary
Modifier and TypeMethodDescriptioncreate(ConnectionFactory<ResolvedAddress, C> original) Decorates the passedoriginalConnectionFactoryto add the filtering logic.Return anExecutionStrategythat describes the offloads required by the influencer.static <A,C extends ListenableAsyncCloseable>
ConnectionFactoryFilter<A,C> with(LimitingConnectionFactoryFilter.ConnectionLimiter<A, C> limiter) Create a newConnectionFactorythat limits the created connections using the passedLimitingConnectionFactoryFilter.ConnectionLimiter.static <A,C extends ListenableAsyncCloseable>
ConnectionFactoryFilter<A,C> withMax(int maxConnections) Create a newConnectionFactorythat only creates a maximum ofmaxConnectionsactive connections.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.servicetalk.client.api.ConnectionFactoryFilter
append
-
Method Details
-
requiredOffloads
Description copied from interface:ConnectionFactoryFilterReturn anExecutionStrategythat describes the offloads required by the influencer.If the returned strategy extends
ConnectExecutionStrategythen the connection creation or accept may be offloaded.If the returned strategy extends
HttpExecutionStrategythen the HTTP execution strategy will be applied to the connections created.A utility class provides the ability to combine connect and HTTP execution strategies,
io.servicetalk.http.api.ConnectAndHttpExecutionStrategy.- Specified by:
requiredOffloadsin interfaceConnectionFactoryFilter<ResolvedAddress,C extends ListenableAsyncCloseable> - Specified by:
requiredOffloadsin interfaceExecutionStrategyInfluencer<ResolvedAddress>- Returns:
- the
ExecutionStrategyrequired by the influencer.
-
withMax
public static <A,C extends ListenableAsyncCloseable> ConnectionFactoryFilter<A,C> withMax(int maxConnections) Create a newConnectionFactorythat only creates a maximum ofmaxConnectionsactive connections.When the limit is reached,
ConnectionLimitReachedExceptionwill be thrown.- Type Parameters:
A- The type of a resolved address that can be used for connecting.C- The type of connections created by the returned factory.- Parameters:
maxConnections- Maximum number of active connections to create.- Returns:
- A new
ConnectionFactorythat limits the number of active connections.
-
with
public static <A,C extends ListenableAsyncCloseable> ConnectionFactoryFilter<A,C> with(LimitingConnectionFactoryFilter.ConnectionLimiter<A, C> limiter) Create a newConnectionFactorythat limits the created connections using the passedLimitingConnectionFactoryFilter.ConnectionLimiter.- Type Parameters:
A- The type of a resolved address that can be used for connecting.C- The type of connections created by the returned factory.- Parameters:
limiter-LimitingConnectionFactoryFilter.ConnectionLimiterto use.- Returns:
- A new
ConnectionFactorythat limits the number of active connections.
-
create
Description copied from interface:ConnectionFactoryFilterDecorates the passedoriginalConnectionFactoryto add the filtering logic.- Specified by:
createin interfaceConnectionFactoryFilter<ResolvedAddress,C extends ListenableAsyncCloseable> - Parameters:
original-ConnectionFactoryto filter.- Returns:
- Decorated
ConnectionFactorythat contains the filtering logic.
-