Class ConnectionLifecycleManager

java.lang.Object
com.lucimber.dbus.connection.ConnectionLifecycleManager

public class ConnectionLifecycleManager extends Object
Manages the lifecycle of a connection including connect, disconnect, and state transitions. This class encapsulates connection state management and ensures thread-safe state transitions.
  • Constructor Details

    • ConnectionLifecycleManager

      public ConnectionLifecycleManager(ConnectionConfig config, String connectionId)
      Creates a new connection lifecycle manager.
      Parameters:
      config - the connection configuration
      connectionId - unique identifier for this connection
  • Method Details

    • connect

      Initiates a connection attempt.
      Parameters:
      connectionSupplier - supplier that performs the actual connection
      Returns:
      completion stage that completes when connection is established
    • disconnect

      public CompletionStage<Void> disconnect(ConnectionLifecycleManager.DisconnectionSupplier disconnectionSupplier)
      Initiates disconnection.
      Parameters:
      disconnectionSupplier - supplier that performs the actual disconnection
      Returns:
      completion stage that completes when disconnection is done
    • getState

      public ConnectionState getState()
      Gets the current connection state.
      Returns:
      current connection state
    • isConnected

      public boolean isConnected()
      Checks if the connection is currently connected.
      Returns:
      true if connected, false otherwise
    • isConnecting

      public boolean isConnecting()
      Checks if a connection attempt is in progress.
      Returns:
      true if connecting, false otherwise
    • isClosing

      public boolean isClosing()
      Checks if disconnection is in progress.
      Returns:
      true if closing, false otherwise
    • getErrorRecoveryManager

      public ErrorRecoveryManager getErrorRecoveryManager()
      Gets the error recovery manager.
      Returns:
      error recovery manager
    • getConnectionCircuitBreaker

      public ErrorRecoveryManager.CircuitBreaker getConnectionCircuitBreaker()
      Gets the connection circuit breaker.
      Returns:
      circuit breaker for connection operations