java.lang.Object
io.fluxcapacitor.javaclient.common.websocket.SessionPool
All Implemented Interfaces:
AutoCloseable

public class SessionPool extends Object implements AutoCloseable
A thread-safe pool of reusable WebSocket 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 Details

    • SessionPool

      public SessionPool(int size, Supplier<jakarta.websocket.Session> sessionFactory)
  • Method Details

    • get

      public jakarta.websocket.Session get()
    • get

      public jakarta.websocket.Session get(String routingKey)
    • get

      protected jakarta.websocket.Session get(int index)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable