Package io.servicetalk.client.api
Interface LimitingConnectionFactoryFilter.ConnectionLimiter<ResolvedAddress,C extends ListenableAsyncCloseable>
- Type Parameters:
ResolvedAddress
- The type of a resolved address that can be used for connecting.C
- The type of connections created by this factory.
- Enclosing class:
- LimitingConnectionFactoryFilter<ResolvedAddress,
C extends ListenableAsyncCloseable>
public static interface LimitingConnectionFactoryFilter.ConnectionLimiter<ResolvedAddress,C extends ListenableAsyncCloseable>
A contract to limit number of connections created by
LimitingConnectionFactoryFilter
.
The following rules apply:
isConnectAllowed(Object)
MUST be called before callingonConnectionClose(Object)
.onConnectionClose(Object)
MAY be called at most once for each call toisConnectAllowed(Object)
.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
isConnectAllowed
(ResolvedAddress target) Requests permission to create a single connection to the passedtarget address
.default Throwable
Create aThrowable
representing a connection attempt refused, typically as a result of returningfalse
fromisConnectAllowed(Object)
.void
onConnectionClose
(ResolvedAddress target) Callback invoked when a connection created after getting permission fromisConnectAllowed(Object)
is closed.
-
Method Details
-
isConnectAllowed
Requests permission to create a single connection to the passedtarget address
. If this method returnstrue
thenonConnectionClose(Object)
will be called when the connection created by the caller is closed.A simple counting implementation will typically increment the count in this method and decrement it in
onConnectionClose(Object)
.- Parameters:
target
-LimitingConnectionFactoryFilter.ConnectionLimiter
for which connection is requested.- Returns:
true
if connection is allowed.
-
onConnectionClose
Callback invoked when a connection created after getting permission fromisConnectAllowed(Object)
is closed.- Parameters:
target
-LimitingConnectionFactoryFilter.ConnectionLimiter
to which connection was created.
-
newConnectionRefusedException
Create aThrowable
representing a connection attempt refused, typically as a result of returningfalse
fromisConnectAllowed(Object)
.The default and recommended exception type is
ConnectionLimitReachedException
.- Parameters:
target
-LimitingConnectionFactoryFilter.ConnectionLimiter
for which connection was refused.- Returns:
Throwable
representing a connection attempt was refused.
-