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 byLimitingConnectionFactoryFilter
.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
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
isConnectAllowed(ResolvedAddress target)
Requests permission to create a single connection to the passedtarget address
.default java.lang.Throwable
newConnectionRefusedException(ResolvedAddress target)
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 Detail
-
isConnectAllowed
boolean isConnectAllowed(ResolvedAddress target)
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
void onConnectionClose(ResolvedAddress target)
Callback invoked when a connection created after getting permission fromisConnectAllowed(Object)
is closed.- Parameters:
target
-LimitingConnectionFactoryFilter.ConnectionLimiter
to which connection was created.
-
newConnectionRefusedException
default java.lang.Throwable newConnectionRefusedException(ResolvedAddress target)
Create aThrowable
representing a connection attempt refused, typically as a result of returningfalse
fromisConnectAllowed(Object)
.- Parameters:
target
-LimitingConnectionFactoryFilter.ConnectionLimiter
for which connection was refused.- Returns:
Throwable
representing a connection attempt was refused.
-
-