java.lang.Object
io.helidon.webserver.websocket.WsConnection
All Implemented Interfaces:
ServerConnection, WsSession

public class WsConnection extends Object implements ServerConnection, WsSession
WebSocket connection, server side session implementation.
  • Method Details

    • create

      public static WsConnection create(ConnectionContext ctx, HttpPrologue prologue, Headers upgradeHeaders, String wsKey, WsListener wsListener)
      Create a new connection using a listener.
      Parameters:
      ctx - server connection context
      prologue - prologue of this request
      upgradeHeaders - headers for
      wsKey - ws key
      wsListener - a ws listener
      Returns:
      a new connection
    • create

      public static WsConnection create(ConnectionContext ctx, HttpPrologue prologue, Headers upgradeHeaders, String wsKey, WsRoute wsRoute)
      Create a new connection using a route.
      Parameters:
      ctx - server connection context
      prologue - prologue of this request
      upgradeHeaders - headers for
      wsKey - ws key
      wsRoute - route to use
      Returns:
      a new connection
    • handle

      public void handle(Semaphore requestSemaphore)
      Description copied from interface: ServerConnection
      Start handling the connection. Data is provided through ServerConnectionSelector.connection(io.helidon.webserver.ConnectionContext).
      Specified by:
      handle in interface ServerConnection
      Parameters:
      requestSemaphore - semaphore that is responsible for maximal concurrent request limit, the connection implementation is responsible for acquiring a permit from the semaphore for the duration of a request, and releasing it when the request ends; please be very careful, as this may lead to complete stop of the server if incorrectly implemented
    • handle

      public void handle(Limit limit)
      Description copied from interface: ServerConnection
      Start handling the connection. Data is provided through ServerConnectionSelector.connection(io.helidon.webserver.ConnectionContext).
      Specified by:
      handle in interface ServerConnection
      Parameters:
      limit - that is responsible for maximal concurrent request limit, the connection implementation is responsible invoking each request within the limit's LimitAlgorithm.invoke(java.util.concurrent.Callable)
    • send

      public WsSession send(String text, boolean last)
      Description copied from interface: WsSession
      Send text fragment.
      Specified by:
      send in interface WsSession
      Parameters:
      text - text to send
      last - if last fragment
      Returns:
      this instance
    • send

      public WsSession send(BufferData bufferData, boolean last)
      Description copied from interface: WsSession
      Send binary fragment.
      Specified by:
      send in interface WsSession
      Parameters:
      bufferData - buffer with data
      last - if last fragment
      Returns:
      this instance
    • ping

      public WsSession ping(BufferData bufferData)
      Description copied from interface: WsSession
      Send ping.
      Specified by:
      ping in interface WsSession
      Parameters:
      bufferData - buffer with data
      Returns:
      this instance
    • pong

      public WsSession pong(BufferData bufferData)
      Description copied from interface: WsSession
      Send pong.
      Specified by:
      pong in interface WsSession
      Parameters:
      bufferData - buffer with data
      Returns:
      this instance
    • close

      public WsSession close(int code, String reason)
      Description copied from interface: WsSession
      Close session.
      Specified by:
      close in interface WsSession
      Parameters:
      code - close code, may be one of WsCloseCodes
      reason - reason description
      Returns:
      this instance
    • terminate

      public WsSession terminate()
      Description copied from interface: WsSession
      Terminate session. Sends a close and closes the connection.
      Specified by:
      terminate in interface WsSession
      Returns:
      this instance
    • subProtocol

      public Optional<String> subProtocol()
      Description copied from interface: WsSession
      The WebSocket sub-protocol negotiated for this session.
      Specified by:
      subProtocol in interface WsSession
      Returns:
      sub-protocol negotiated, if any
    • socketContext

      public SocketContext socketContext()
      Description copied from interface: WsSession
      The underlying socket context.
      Specified by:
      socketContext in interface WsSession
      Returns:
      socket context
    • idleTime

      public Duration idleTime()
      Description copied from interface: ServerConnection
      How long is this connection idle. This is a duration from the last request to now.
      Specified by:
      idleTime in interface ServerConnection
      Returns:
      idle duration
    • close

      public void close(boolean interrupt)
      Description copied from interface: ServerConnection
      Close a connection. This may be called during shutdown of the server, or when idle timeout is reached.
      Specified by:
      close in interface ServerConnection
      Parameters:
      interrupt - whether to interrupt in progress requests (always interrupts idle requests waiting for initial request data)