Class SessionPool
- All Implemented Interfaces:
AutoCloseable
WebsocketSession objects, supporting concurrent access and routing.
This class provides a mechanism to manage multiple active WebSocket sessions, either round-robin or keyed by a
routingKey. It lazily initializes sessions on demand using a configurable factory, ensuring that each
session slot is kept active unless the pool is shutting down or explicitly closed. A replacement-aware factory
receives the previous closed session so a new handshake can identify which server-side session it supersedes.
The session pool is particularly useful in high-throughput scenarios, where multiple sessions are used to distribute load, improve parallelism, or isolate message streams.
Usage Modes:
- Round-robin: Calling
get()will return the next available session, cycling through the pool. - Hash-based routing: Calling
get(String)with a routing key returns the session consistently mapped to that key, based on consistent hashing.
If a session is closed or unavailable, it is automatically replaced using the provided sessionFactory.
All registered sessions are closed when close() is called. A connection attempt already in progress
is closed when it completes after shutdown and is not published to the pool.
Note: This class is used by Fluxzero WebSocket clients such as AbstractWebsocketClient to
manage their underlying connections to the Fluxzero Runtime.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()get()Returns an open session using round-robin slot selection, creating or replacing the selected session as needed.protected WebsocketSessionget(int index) Returns an open session selected by consistent hashing of the routing key; a null key uses round-robin selection.
-
Constructor Details
-
SessionPool
-
-
Method Details
-
get
Returns an open session using round-robin slot selection, creating or replacing the selected session as needed. Calls after shutdown fail withIllegalStateException. -
get
Returns an open session selected by consistent hashing of the routing key; a null key uses round-robin selection. Calls after shutdown fail withIllegalStateException. -
get
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-