Class ClientConnection

java.lang.Object
net.carcdr.yhocuspocus.core.ClientConnection
All Implemented Interfaces:
AutoCloseable, ReceiveListener

public class ClientConnection extends Object implements ReceiveListener, AutoCloseable
Manages a client transport connection.

Handles authentication, message routing, and document multiplexing over a single transport connection. Transport-agnostic design allows use with WebSocket, HTTP, or other protocols.

Key responsibilities:

  • Authentication flow per document
  • Message queueing during authentication
  • Document multiplexing (multiple documents per connection)
  • Clean shutdown and resource cleanup

Note: Keepalive/ping mechanisms are handled by the transport layer (e.g., WebSocket ping/pong) to maintain transport-agnostic design.

  • Method Details

    • onMessage

      public void onMessage(byte[] data)
      Called by the transport when a binary message is received.

      Implements ReceiveListener.onMessage(byte[]).

      Specified by:
      onMessage in interface ReceiveListener
      Parameters:
      data - the raw message data
    • send

      public void send(byte[] message)
      Sends a message via transport.
      Parameters:
      message - the message bytes
    • close

      public void close(int code, String reason)
      Closes this connection.
      Parameters:
      code - close code
      reason - close reason
    • close

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

      public String getConnectionId()
      Gets the connection ID.
      Returns:
      connection ID
    • getContext

      public Map<String,Object> getContext()
      Gets the connection context.
      Returns:
      mutable context map
    • getTransport

      public Transport getTransport()
      Gets the transport.
      Returns:
      transport instance