Class SessionPool

java.lang.Object
io.fluxzero.sdk.common.websocket.SessionPool
All Implemented Interfaces:
AutoCloseable

public class SessionPool extends Object implements AutoCloseable
A thread-safe pool of reusable 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 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 Fluxzero WebSocket clients such as AbstractWebsocketClient to manage their underlying connections to the Fluxzero Runtime.

See Also: