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>
public final class LimitingConnectionFactoryFilter<ResolvedAddress,C extends ListenableAsyncCloseable> extends java.lang.Object implements ConnectionFactoryFilter<ResolvedAddress,C>
AConnectionFactory
that limits the total number of active connections created using thisConnectionFactory
. A connection is considered active ifListenableAsyncCloseable.onClose()
has not yet terminated.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
LimitingConnectionFactoryFilter.ConnectionLimiter<ResolvedAddress,C extends ListenableAsyncCloseable>
A contract to limit number of connections created byLimitingConnectionFactoryFilter
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ConnectionFactory<ResolvedAddress,C>
create(ConnectionFactory<ResolvedAddress,C> original)
Decorates the passedoriginal
ConnectionFactory
to add the filtering logic.static <A,C extends ListenableAsyncCloseable>
ConnectionFactoryFilter<A,C>with(LimitingConnectionFactoryFilter.ConnectionLimiter<A,C> limiter)
Create a newConnectionFactory
that limits the created connections using the passedLimitingConnectionFactoryFilter.ConnectionLimiter
.static <A,C extends ListenableAsyncCloseable>
ConnectionFactoryFilter<A,C>withMax(int maxConnections)
Create a newConnectionFactory
that only creates a maximum ofmaxConnections
active connections.-
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.ConnectionFactoryFilter
append
-
-
-
-
Method Detail
-
withMax
public static <A,C extends ListenableAsyncCloseable> ConnectionFactoryFilter<A,C> withMax(int maxConnections)
Create a newConnectionFactory
that only creates a maximum ofmaxConnections
active connections.- 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
ConnectionFactory
that limits the number of active connections.
-
with
public static <A,C extends ListenableAsyncCloseable> ConnectionFactoryFilter<A,C> with(LimitingConnectionFactoryFilter.ConnectionLimiter<A,C> limiter)
Create a newConnectionFactory
that 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.ConnectionLimiter
to use.- Returns:
- A new
ConnectionFactory
that limits the number of active connections.
-
create
public ConnectionFactory<ResolvedAddress,C> create(ConnectionFactory<ResolvedAddress,C> original)
Description copied from interface:ConnectionFactoryFilter
Decorates the passedoriginal
ConnectionFactory
to add the filtering logic.- Specified by:
create
in interfaceConnectionFactoryFilter<ResolvedAddress,C extends ListenableAsyncCloseable>
- Parameters:
original
-ConnectionFactory
to filter.- Returns:
- Decorated
ConnectionFactory
that contains the filtering logic.
-
-