Enum Class ConnectionState

java.lang.Object
java.lang.Enum<ConnectionState>
express.mvp.myra.transport.lifecycle.ConnectionState
All Implemented Interfaces:
Serializable, Comparable<ConnectionState>, Constable

public enum ConnectionState extends Enum<ConnectionState>
Represents the states of a transport connection.

The connection state machine tracks the lifecycle of a connection from creation through disconnection. State transitions follow a defined pattern with specific allowed transitions.

State Diagram

                       ┌────────────────────────────────────┐
                       │                                    │
                       ▼                                    │
┌────────┐  connect()  ┌────────────┐  success  ┌──────────┐│
│  NEW   │────────────▶│ CONNECTING │──────────▶│CONNECTED ││
└────────┘             └────────────┘           └──────────┘│
                              │                      │      │
                              │ failure              │      │
                              ▼                      │      │
                       ┌────────────┐                │      │
                       │  FAILED    │                │      │
                       └────────────┘                │      │
                              │                      │      │
                              │ reconnect()          │ close()
                              │                      │      │
                              ▼                      ▼      │
                       ┌────────────────────────────────────┘
                       │                                    
                       ▼                                    
    ┌────────────┐  drain complete  ┌────────────┐
    │  CLOSING   │─────────────────▶│  CLOSED    │
    └────────────┘                  └────────────┘

State Descriptions

  • NEW: Initial state - connection not yet initiated
  • CONNECTING: Connection attempt in progress
  • CONNECTED: Actively connected and ready for I/O
  • FAILED: Connection attempt failed (may retry)
  • CLOSING: Graceful close in progress
  • CLOSED: Terminal state - connection fully closed
See Also:
  • Enum Constant Details

    • NEW

      public static final ConnectionState NEW
      Initial state before any connection attempt.

      Allowed transitions:

    • CONNECTING

      public static final ConnectionState CONNECTING
      Connection attempt in progress.

      This state indicates an asynchronous connection operation is pending. The transition out of this state depends on the result:

    • CONNECTED

      public static final ConnectionState CONNECTED
      Actively connected and ready for I/O operations.

      In this state, send and receive operations can proceed.

      Allowed transitions:

      • CLOSING - when close() is called
      • FAILED - on I/O error (connection reset, etc.)
    • FAILED

      public static final ConnectionState FAILED
      Connection failed or was lost.

      This state can be entered from:

      Allowed transitions:

    • CLOSING

      public static final ConnectionState CLOSING
      Graceful close in progress.

      During this state:

      • No new operations are accepted
      • In-flight operations may complete
      • Connection is being drained

      Allowed transitions:

      • CLOSED - when close completes
    • CLOSED

      public static final ConnectionState CLOSED
      Terminal state - connection fully closed.

      No transitions are allowed from this state. The connection object cannot be reused.

  • Method Details

    • values

      public static ConnectionState[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static ConnectionState valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • order

      public int order()
      Returns the numeric order of this state.
      Returns:
      the state order
    • displayName

      public String displayName()
      Returns a human-readable name for this state.
      Returns:
      the display name
    • isActive

      public boolean isActive()
      Checks if the connection is active and can perform I/O.
      Returns:
      true only in CONNECTED state
    • isTerminalOrClosing

      public boolean isTerminalOrClosing()
      Checks if this is a terminal state (CLOSING or CLOSED).
      Returns:
      true if no more operations should be attempted
    • canReconnect

      public boolean canReconnect()
      Checks if the connection can be reconnected.
      Returns:
      true if in FAILED state
    • canConnect

      public boolean canConnect()
      Checks if a connect operation can be initiated.
      Returns:
      true if in NEW or FAILED state
    • isConnecting

      public boolean isConnecting()
      Checks if the connection is in the process of establishing.
      Returns:
      true if in CONNECTING state
    • isClosed

      public boolean isClosed()
      Checks if this is a final state with no possible transitions.
      Returns:
      true only in CLOSED state
    • toString

      public String toString()
      Overrides:
      toString in class Enum<ConnectionState>