Class JettyWebSocketServerContainer

All Implemented Interfaces:
EventListener, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, LifeCycle.Listener, Configurable, WebSocketContainer

public class JettyWebSocketServerContainer extends ContainerLifeCycle implements WebSocketContainer, Configurable, LifeCycle.Listener
  • Field Details

    • JETTY_WEBSOCKET_CONTAINER_ATTRIBUTE

      public static final String JETTY_WEBSOCKET_CONTAINER_ATTRIBUTE
  • Method Details

    • getContainer

      public static JettyWebSocketServerContainer getContainer(jakarta.servlet.ServletContext servletContext)
    • ensureContainer

      public static JettyWebSocketServerContainer ensureContainer(jakarta.servlet.ServletContext servletContext)
    • addMapping

      public void addMapping(String pathSpec, JettyWebSocketCreator creator)
    • addMapping

      public void addMapping(String pathSpec, Class<?> endpointClass)
    • upgrade

      public boolean upgrade(JettyWebSocketCreator creator, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException
      An immediate programmatic WebSocket upgrade that does not register a mapping or create a WebSocketUpgradeFilter.

      A return value of true means the connection was Upgraded to WebSocket or an error response is being generated. A return value of false means that it was a bad upgrade request and couldn't be upgraded to WebSocket and the caller is responsible for generating the response.

      Parameters:
      creator - the WebSocketCreator to use.
      request - the HttpServletRequest.
      response - the HttpServletResponse.
      Returns:
      true if the connection could be upgraded or an error was sent.
      Throws:
      IOException - if an I/O error occurs.
    • getExecutor

      public Executor getExecutor()
      Description copied from interface: WebSocketContainer
      The Container provided Executor.
      Specified by:
      getExecutor in interface WebSocketContainer
    • addSessionListener

      public void addSessionListener(WebSocketSessionListener listener)
      Description copied from interface: WebSocketContainer
      Register a WebSocketSessionListener with the container
      Specified by:
      addSessionListener in interface WebSocketContainer
      Parameters:
      listener - the listener
    • removeSessionListener

      public boolean removeSessionListener(WebSocketSessionListener listener)
      Description copied from interface: WebSocketContainer
      Remove a WebSocketSessionListener from the container
      Specified by:
      removeSessionListener in interface WebSocketContainer
      Parameters:
      listener - the listener
      Returns:
      true if listener was present and removed
    • notifySessionListeners

      public void notifySessionListeners(Consumer<WebSocketSessionListener> consumer)
      Description copied from interface: WebSocketContainer
      Notify the Session Listeners of an event.
      Specified by:
      notifySessionListeners in interface WebSocketContainer
      Parameters:
      consumer - the consumer to call for each tracked listener
    • getOpenSessions

      public Collection<Session> getOpenSessions()
      Description copied from interface: WebSocketContainer
      Get the collection of open Sessions being tracked by this container
      Specified by:
      getOpenSessions in interface WebSocketContainer
      Returns:
      the collection of open sessions
    • getIdleTimeout

      public Duration getIdleTimeout()
      Description copied from interface: Configurable
      The duration that a websocket may be idle before being closed by the implementation
      Specified by:
      getIdleTimeout in interface Configurable
      Returns:
      the timeout duration
    • setIdleTimeout

      public void setIdleTimeout(Duration duration)
      Description copied from interface: Configurable
      The duration that a websocket may be idle before being closed by the implementation
      Specified by:
      setIdleTimeout in interface Configurable
      Parameters:
      duration - the timeout duration (may not be null or negative)
    • getInputBufferSize

      public int getInputBufferSize()
      Description copied from interface: Configurable
      The input (read from network layer) buffer size.

      This is the raw read operation buffer size, before the parsing of the websocket frames.

      Specified by:
      getInputBufferSize in interface Configurable
      Returns:
      the raw network buffer input size.
    • setInputBufferSize

      public void setInputBufferSize(int size)
      Description copied from interface: Configurable
      The input (read from network layer) buffer size.
      Specified by:
      setInputBufferSize in interface Configurable
      Parameters:
      size - the size in bytes
    • getOutputBufferSize

      public int getOutputBufferSize()
      Description copied from interface: Configurable
      The output (write to network layer) buffer size.

      This is the raw write operation buffer size and has no relationship to the websocket frame.

      Specified by:
      getOutputBufferSize in interface Configurable
      Returns:
      the raw network buffer output size.
    • setOutputBufferSize

      public void setOutputBufferSize(int size)
      Description copied from interface: Configurable
      The output (write to network layer) buffer size.
      Specified by:
      setOutputBufferSize in interface Configurable
      Parameters:
      size - the size in bytes
    • getMaxBinaryMessageSize

      public long getMaxBinaryMessageSize()
      Description copied from interface: Configurable
      Get the maximum size of a binary message during parsing.

      This is a memory conservation option, memory over this limit will not be allocated by Jetty for handling binary messages. This applies to individual frames, whole message handling, and partial message handling.

      Binary messages over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

      Specified by:
      getMaxBinaryMessageSize in interface Configurable
      Returns:
      the maximum size of a binary message
    • setMaxBinaryMessageSize

      public void setMaxBinaryMessageSize(long size)
      Description copied from interface: Configurable
      The maximum size of a binary message during parsing/generating.

      Binary messages over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

      Specified by:
      setMaxBinaryMessageSize in interface Configurable
      Parameters:
      size - the maximum allowed size of a binary message.
    • getMaxTextMessageSize

      public long getMaxTextMessageSize()
      Description copied from interface: Configurable
      Get the maximum size of a text message during parsing.

      This is a memory conservation option, memory over this limit will not be allocated by Jetty for handling text messages. This applies to individual frames, whole message handling, and partial message handling.

      Text messages over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

      Specified by:
      getMaxTextMessageSize in interface Configurable
      Returns:
      the maximum size of a text message.
    • setMaxTextMessageSize

      public void setMaxTextMessageSize(long size)
      Description copied from interface: Configurable
      The maximum size of a text message during parsing/generating.

      Text messages over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

      Specified by:
      setMaxTextMessageSize in interface Configurable
      Parameters:
      size - the maximum allowed size of a text message.
    • getMaxFrameSize

      public long getMaxFrameSize()
      Description copied from interface: Configurable
      The maximum payload size of any WebSocket Frame which can be received.
      Specified by:
      getMaxFrameSize in interface Configurable
      Returns:
      the maximum size of a WebSocket Frame.
    • setMaxFrameSize

      public void setMaxFrameSize(long maxFrameSize)
      Description copied from interface: Configurable
      The maximum payload size of any WebSocket Frame which can be received.

      WebSocket Frames over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

      Specified by:
      setMaxFrameSize in interface Configurable
      Parameters:
      maxFrameSize - the maximum allowed size of a WebSocket Frame.
    • isAutoFragment

      public boolean isAutoFragment()
      Description copied from interface: Configurable
      If true, frames are automatically fragmented to respect the maximum frame size.
      Specified by:
      isAutoFragment in interface Configurable
      Returns:
      whether to automatically fragment incoming WebSocket Frames.
    • setAutoFragment

      public void setAutoFragment(boolean autoFragment)
      Description copied from interface: Configurable
      If set to true, frames are automatically fragmented to respect the maximum frame size.
      Specified by:
      setAutoFragment in interface Configurable
      Parameters:
      autoFragment - whether to automatically fragment incoming WebSocket Frames.
    • getMaxOutgoingFrames

      public int getMaxOutgoingFrames()
      Description copied from interface: Configurable
      Get the maximum number of data frames allowed to be waiting to be sent at any one time. The default value is -1, this indicates there is no limit on how many frames can be queued to be sent by the implementation. If the limit is exceeded, subsequent frames sent are failed with a WritePendingException but the connection is not failed and will remain open.
      Specified by:
      getMaxOutgoingFrames in interface Configurable
      Returns:
      the max number of frames.
    • setMaxOutgoingFrames

      public void setMaxOutgoingFrames(int maxOutgoingFrames)
      Description copied from interface: Configurable
      Set the maximum number of data frames allowed to be waiting to be sent at any one time. The default value is -1, this indicates there is no limit on how many frames can be queued to be sent by the implementation. If the limit is exceeded, subsequent frames sent are failed with a WritePendingException but the connection is not failed and will remain open.
      Specified by:
      setMaxOutgoingFrames in interface Configurable
      Parameters:
      maxOutgoingFrames - the max number of frames.
    • dump

      public void dump(Appendable out, String indent) throws IOException
      Description copied from interface: Dumpable
      Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
      Specified by:
      dump in interface Dumpable
      Overrides:
      dump in class ContainerLifeCycle
      Parameters:
      out - The appendable to dump to
      indent - The indent to apply after any new lines.
      Throws:
      IOException - if unable to write to Appendable