Module lettuce.core
Package io.lettuce.core.internal
Class AsyncConnectionProvider<K,T extends AsyncCloseable,F extends CompletionStage<T>>
java.lang.Object
io.lettuce.core.internal.AsyncConnectionProvider<K,T,F>
- Type Parameters:
T- connection type.K- connection key type.F- type of theCompletionStagehandle of the connection progress.
public class AsyncConnectionProvider<K,T extends AsyncCloseable,F extends CompletionStage<T>> extends Object
Non-blocking provider for connection objects. This connection provider is typed with a connection type and connection key
type.
getConnection(Object) Connection requests} are synchronized with a shared synchronzer object per
ConnectionKey. Multiple threads requesting a connection for the same ConnectionKey share the same
synchronizer and are not required to wait until a previous asynchronous connection is established but participate in existing
connection initializations. Shared synchronization leads to a fair synchronization amongst multiple threads waiting to obtain
a connection.
- Since:
- 5.1
- Author:
- Mark Paluch
-
Constructor Summary
Constructors Constructor Description AsyncConnectionProvider(Function<? extends K,? extends F> connectionFactory)Create a newAsyncConnectionProvider. -
Method Summary
Modifier and Type Method Description CompletableFuture<Void>close()Close all connections.voidclose(K key)Close a connection by its connectionkey.voidforEach(BiConsumer<? super K,? super T> action)Execute an action for all established and pendingAsyncCloseables.voidforEach(Consumer<? super T> action)Execute an action for all established and pending connections.FgetConnection(K key)Request a connection for the given the connectionkeyand return aCompletionStagethat is notified about the connection outcome.intgetConnectionCount()voidregister(K key, T connection)Register a connection identified bykey.
-
Constructor Details
-
AsyncConnectionProvider
Create a newAsyncConnectionProvider.- Parameters:
connectionFactory- must not benull.
-
-
Method Details
-
getConnection
Request a connection for the given the connectionkeyand return aCompletionStagethat is notified about the connection outcome.- Parameters:
key- the connectionkey, must not benull.- Returns:
-
register
Register a connection identified bykey. Overwrites existing entries.- Parameters:
key- the connectionkey.connection- the connection object.
-
getConnectionCount
public int getConnectionCount()- Returns:
- number of established connections.
-
close
Close all connections. Pending connections are closed using future chaining. -
close
Close a connection by its connectionkey. Pending connections are closed using future chaining.- Parameters:
key- the connectionkey, must not benull.
-
forEach
Execute an action for all established and pending connections.- Parameters:
action- the action.
-
forEach
Execute an action for all established and pendingAsyncCloseables.- Parameters:
action- the action.
-