Class CopilotWebSocketHandler

java.lang.Object
com.github.copilot.CopilotWebSocketHandler
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
CopilotWebSocketForwarder

public abstract class CopilotWebSocketHandler extends Object implements AutoCloseable
A per-connection WebSocket handler returned by CopilotRequestHandler.openWebSocket(CopilotRequestContext).

The default implementation is CopilotWebSocketForwarder, which dials the real upstream and transparently relays messages in both directions. A full transport replacement subclasses this type directly and brings its own transport and receive loop, forwarding upstream-to-runtime messages by calling sendResponseMessage(CopilotWebSocketMessage) and finishing with close(CopilotWebSocketCloseStatus).

Since:
1.0.0
  • Field Details

    • context

      protected final CopilotRequestContext context
      The request context for this WebSocket connection.
  • Constructor Details

    • CopilotWebSocketHandler

      protected CopilotWebSocketHandler(CopilotRequestContext context)
      Initializes a per-connection handler for the supplied request context.
      Parameters:
      context - the per-request context
  • Method Details

    • sendRequestMessage

      public abstract void sendRequestMessage(CopilotWebSocketMessage message) throws Exception
      Sends a message from the runtime to the upstream connection.
      Parameters:
      message - the message to forward upstream
      Throws:
      Exception - if the message could not be forwarded
    • sendResponseMessage

      public void sendResponseMessage(CopilotWebSocketMessage message) throws Exception
      Sends a message from the upstream connection back to the runtime. Override to mutate or duplicate messages; call super to emit.
      Parameters:
      message - the upstream-to-runtime message
      Throws:
      Exception - if the message could not be delivered
    • close

      public void close(CopilotWebSocketCloseStatus status) throws Exception
      Closes the connection and finalises the runtime-facing response. Idempotent.
      Parameters:
      status - the terminal status; a non-null CopilotWebSocketCloseStatus.error() surfaces a transport failure, otherwise a clean end-of-stream
      Throws:
      Exception - if the terminal frame could not be delivered
    • close

      public void close()
      Tears down the connection, finalising with a normal closure unless the connection has already been closed or close-on-dispose was suppressed.
      Specified by:
      close in interface AutoCloseable