Module lettuce.core

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 the CompletionStage handle 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 Details

    • AsyncConnectionProvider

      public AsyncConnectionProvider​(Function<? extends K,​? extends F> connectionFactory)
      Parameters:
      connectionFactory - must not be null.
  • Method Details

    • getConnection

      public F getConnection​(K key)
      Request a connection for the given the connection key and return a CompletionStage that is notified about the connection outcome.
      Parameters:
      key - the connection key, must not be null.
      Returns:
    • register

      public void register​(K key, T connection)
      Register a connection identified by key. Overwrites existing entries.
      Parameters:
      key - the connection key.
      connection - the connection object.
    • getConnectionCount

      public int getConnectionCount()
      Returns:
      number of established connections.
    • close

      public CompletableFuture<Void> close()
      Close all connections. Pending connections are closed using future chaining.
    • close

      public void close​(K key)
      Close a connection by its connection key. Pending connections are closed using future chaining.
      Parameters:
      key - the connection key, must not be null.
    • forEach

      public void forEach​(Consumer<? super T> action)
      Execute an action for all established and pending connections.
      Parameters:
      action - the action.
    • forEach

      public void forEach​(BiConsumer<? super K,​? super T> action)
      Execute an action for all established and pending AsyncCloseables.
      Parameters:
      action - the action.