Class SessionPool
- All Implemented Interfaces:
AutoCloseable
Session
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 Supplier
, ensuring that
each session slot is kept active unless the pool is shutting down or explicitly closed.
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 sessions are closed when close()
is called.
Note: This class is used by Flux WebSocket clients such as AbstractWebsocketClient
to
manage their underlying connections to the Flux platform.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
SessionPool
-
-
Method Details
-
get
public jakarta.websocket.Session get() -
get
-
get
protected jakarta.websocket.Session get(int index) -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-