Enum Class ConnectionState
- All Implemented Interfaces:
Serializable, Comparable<ConnectionState>, Constable
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
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if a connect operation can be initiated.booleanChecks if the connection can be reconnected.Returns a human-readable name for this state.booleanisActive()Checks if the connection is active and can perform I/O.booleanisClosed()Checks if this is a final state with no possible transitions.booleanChecks if the connection is in the process of establishing.booleanChecks if this is a terminal state (CLOSING or CLOSED).intorder()Returns the numeric order of this state.toString()static ConnectionStateReturns the enum constant of this class with the specified name.static ConnectionState[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
NEW
Initial state before any connection attempt.Allowed transitions:
CONNECTING- when connect() is calledCLOSED- if closed before connecting
-
CONNECTING
-
CONNECTED
-
FAILED
Connection failed or was lost.This state can be entered from:
CONNECTING- connection attempt failedCONNECTED- connection lost during operation
Allowed transitions:
CONNECTING- on reconnect attemptCLOSED- if close() called or no retry
-
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
Terminal state - connection fully closed.No transitions are allowed from this state. The connection object cannot be reused.
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
order
public int order()Returns the numeric order of this state.- Returns:
- the state order
-
displayName
-
isActive
public boolean isActive()Checks if the connection is active and can perform I/O.- Returns:
- true only in
CONNECTEDstate
-
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
FAILEDstate
-
canConnect
-
isConnecting
public boolean isConnecting()Checks if the connection is in the process of establishing.- Returns:
- true if in
CONNECTINGstate
-
isClosed
public boolean isClosed()Checks if this is a final state with no possible transitions.- Returns:
- true only in
CLOSEDstate
-
toString
- Overrides:
toStringin classEnum<ConnectionState>
-