Class ServerWebSocketContainer

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.websocket.server.ServerWebSocketContainer
All Implemented Interfaces:
org.eclipse.jetty.server.Request.Handler, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle, org.eclipse.jetty.util.thread.Invocable, org.eclipse.jetty.websocket.api.Configurable, org.eclipse.jetty.websocket.api.WebSocketContainer

public class ServerWebSocketContainer extends org.eclipse.jetty.util.component.ContainerLifeCycle implements org.eclipse.jetty.websocket.api.WebSocketContainer, org.eclipse.jetty.websocket.api.Configurable, org.eclipse.jetty.util.thread.Invocable, org.eclipse.jetty.server.Request.Handler

A server-side WebSocket container that allows to map URI paths to WebSocket endpoints and configure WebSocket parameters such as idle timeouts, max WebSocket message sizes, etc.

Direct WebSocket upgrades not mapped to URI paths are possible via upgrade(WebSocketCreator, Request, Response, Callback).

  • Nested Class Summary

    Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container

    org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable

    org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable

    org.eclipse.jetty.util.thread.Invocable.Callable, org.eclipse.jetty.util.thread.Invocable.InvocationType, org.eclipse.jetty.util.thread.Invocable.ReadyTask, org.eclipse.jetty.util.thread.Invocable.Task

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

    org.eclipse.jetty.util.component.LifeCycle.Listener

    Nested classes/interfaces inherited from interface org.eclipse.jetty.server.Request.Handler

    org.eclipse.jetty.server.Request.Handler.AbortException
  • Field Summary

    Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    FAILED, STARTED, STARTING, STOPPED, STOPPING

    Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

    KEY

    Fields inherited from interface org.eclipse.jetty.util.thread.Invocable

    __nonBlocking, NOOP
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addMapping(String pathSpec, WebSocketCreator creator)
    Maps the given pathSpec to the creator of WebSocket endpoints.
    void
    addMapping(org.eclipse.jetty.http.pathmap.PathSpec pathSpec, WebSocketCreator creator)
    Maps the given pathSpec to the creator of WebSocket endpoints.
    void
    addSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener)
     
    ensure(org.eclipse.jetty.server.Server server)
    Returns the ServerWebSocketContainer, ensuring that it is available via get(Context).
    ensure(org.eclipse.jetty.server.Server server, org.eclipse.jetty.server.handler.ContextHandler contextHandler)
    Returns the ServerWebSocketContainer, ensuring that it is available via get(Context).
    get(org.eclipse.jetty.server.Context context)
    Returns the ServerWebSocketContainer present as the context attribute under the name corresponding to the full qualified name of class WebSocketContainer.
     
     
    int
     
    org.eclipse.jetty.util.thread.Invocable.InvocationType
     
    long
     
    long
     
    int
     
    long
     
    Collection<org.eclipse.jetty.websocket.api.Session>
     
    int
     
    boolean
    handle(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback)
    Matches the given request against existing WebSocket mappings, upgrading to WebSocket if there is a match.
    boolean
     
    void
    notifySessionListeners(Consumer<org.eclipse.jetty.websocket.api.WebSocketSessionListener> consumer)
     
    boolean
    removeSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener)
     
    void
    setAutoFragment(boolean autoFragment)
     
    void
     
    void
     
    void
    setInvocationType(org.eclipse.jetty.util.thread.Invocable.InvocationType invocationType)
    Sets the invocation type of this container.
    void
     
    void
    setMaxFrameSize(long maxFrameSize)
     
    void
    setMaxOutgoingFrames(int maxOutgoingFrames)
     
    void
     
    void
     
    boolean
    upgrade(WebSocketCreator creator, org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback)
    Upgrades the given request without matching against the WebSocket mappings.

    Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle

    addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, doStop, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans

    Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.jetty.util.component.Container

    getCachedBeans, getEventListeners

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

    dumpSelf

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    isDumpable
  • Method Details

    • ensure

      public static ServerWebSocketContainer ensure(org.eclipse.jetty.server.Server server, org.eclipse.jetty.server.handler.ContextHandler contextHandler)

      Returns the ServerWebSocketContainer, ensuring that it is available via get(Context).

      If the ServerWebSocketContainer is not already available, an instance is created, stored to be available via get(Context) and returned.

      This method should be invoked during the setup of the Handler hierarchy.

      Parameters:
      server - the Server object used to lookup common WebSocket components
      contextHandler - the ContextHandler used to store the ServerWebSocketContainer
      Returns:
      a non-null ServerWebSocketContainer
    • ensure

      public static ServerWebSocketContainer ensure(org.eclipse.jetty.server.Server server)

      Returns the ServerWebSocketContainer, ensuring that it is available via get(Context).

      If the ServerWebSocketContainer is not already available, an instance is created, stored to be available via get(Context) and returned.

      This method should be invoked during the setup of the Handler hierarchy.

      Parameters:
      server - the Server object used to lookup common WebSocket components and store the ServerWebSocketContainer
      Returns:
      a non-null ServerWebSocketContainer
    • get

      public static ServerWebSocketContainer get(org.eclipse.jetty.server.Context context)

      Returns the ServerWebSocketContainer present as the context attribute under the name corresponding to the full qualified name of class WebSocketContainer.

      Parameters:
      context - the Context to look for the attribute
      Returns:
      the ServerWebSocketContainer stored as an attribute, or null if no such attribute is present
    • getExecutor

      public Executor getExecutor()
      Specified by:
      getExecutor in interface org.eclipse.jetty.websocket.api.WebSocketContainer
    • getOpenSessions

      public Collection<org.eclipse.jetty.websocket.api.Session> getOpenSessions()
      Specified by:
      getOpenSessions in interface org.eclipse.jetty.websocket.api.WebSocketContainer
    • addSessionListener

      public void addSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener)
      Specified by:
      addSessionListener in interface org.eclipse.jetty.websocket.api.WebSocketContainer
    • removeSessionListener

      public boolean removeSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener)
      Specified by:
      removeSessionListener in interface org.eclipse.jetty.websocket.api.WebSocketContainer
    • notifySessionListeners

      public void notifySessionListeners(Consumer<org.eclipse.jetty.websocket.api.WebSocketSessionListener> consumer)
      Specified by:
      notifySessionListeners in interface org.eclipse.jetty.websocket.api.WebSocketContainer
    • getIdleTimeout

      public Duration getIdleTimeout()
      Specified by:
      getIdleTimeout in interface org.eclipse.jetty.websocket.api.Configurable
    • setIdleTimeout

      public void setIdleTimeout(Duration duration)
      Specified by:
      setIdleTimeout in interface org.eclipse.jetty.websocket.api.Configurable
    • getInputBufferSize

      public int getInputBufferSize()
      Specified by:
      getInputBufferSize in interface org.eclipse.jetty.websocket.api.Configurable
    • setInputBufferSize

      public void setInputBufferSize(int size)
      Specified by:
      setInputBufferSize in interface org.eclipse.jetty.websocket.api.Configurable
    • getOutputBufferSize

      public int getOutputBufferSize()
      Specified by:
      getOutputBufferSize in interface org.eclipse.jetty.websocket.api.Configurable
    • setOutputBufferSize

      public void setOutputBufferSize(int size)
      Specified by:
      setOutputBufferSize in interface org.eclipse.jetty.websocket.api.Configurable
    • getMaxBinaryMessageSize

      public long getMaxBinaryMessageSize()
      Specified by:
      getMaxBinaryMessageSize in interface org.eclipse.jetty.websocket.api.Configurable
    • setMaxBinaryMessageSize

      public void setMaxBinaryMessageSize(long size)
      Specified by:
      setMaxBinaryMessageSize in interface org.eclipse.jetty.websocket.api.Configurable
    • getMaxTextMessageSize

      public long getMaxTextMessageSize()
      Specified by:
      getMaxTextMessageSize in interface org.eclipse.jetty.websocket.api.Configurable
    • setMaxTextMessageSize

      public void setMaxTextMessageSize(long size)
      Specified by:
      setMaxTextMessageSize in interface org.eclipse.jetty.websocket.api.Configurable
    • getMaxFrameSize

      public long getMaxFrameSize()
      Specified by:
      getMaxFrameSize in interface org.eclipse.jetty.websocket.api.Configurable
    • setMaxFrameSize

      public void setMaxFrameSize(long maxFrameSize)
      Specified by:
      setMaxFrameSize in interface org.eclipse.jetty.websocket.api.Configurable
    • isAutoFragment

      public boolean isAutoFragment()
      Specified by:
      isAutoFragment in interface org.eclipse.jetty.websocket.api.Configurable
    • setAutoFragment

      public void setAutoFragment(boolean autoFragment)
      Specified by:
      setAutoFragment in interface org.eclipse.jetty.websocket.api.Configurable
    • getMaxOutgoingFrames

      public int getMaxOutgoingFrames()
      Specified by:
      getMaxOutgoingFrames in interface org.eclipse.jetty.websocket.api.Configurable
    • setMaxOutgoingFrames

      public void setMaxOutgoingFrames(int maxOutgoingFrames)
      Specified by:
      setMaxOutgoingFrames in interface org.eclipse.jetty.websocket.api.Configurable
    • addMapping

      public void addMapping(String pathSpec, WebSocketCreator creator)

      Maps the given pathSpec to the creator of WebSocket endpoints.

      The pathSpec format is that supported by WebSocketMappings.parsePathSpec(String).

      Parameters:
      pathSpec - the pathSpec to associate to the creator
      creator - the creator of WebSocket endpoints
    • addMapping

      public void addMapping(org.eclipse.jetty.http.pathmap.PathSpec pathSpec, WebSocketCreator creator)

      Maps the given pathSpec to the creator of WebSocket endpoints.

      Parameters:
      pathSpec - the pathSpec to associate to the creator
      creator - the creator of WebSocket endpoints
    • handle

      public boolean handle(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback)

      Matches the given request against existing WebSocket mappings, upgrading to WebSocket if there is a match.

      Direct upgrades without using WebSocket mappings may be performed via upgrade(WebSocketCreator, Request, Response, Callback).

      When true is returned, a response has been sent to the client and the callback has been completed; either because of a successful WebSocket upgrade, or because an error has occurred.

      When false is returned, a response has not been sent to the client, and the callback has not been completed; typically because the request path does not match any existing WebSocket mappings, so that the request can be handled by other Handlers.

      Specified by:
      handle in interface org.eclipse.jetty.server.Request.Handler
      Parameters:
      request - the request to handle, possibly a WebSocket upgrade request
      response - the response to handle
      callback - the callback to complete when the handling is complete
      Returns:
      true in case of WebSocket upgrades or failures, false if the request was not handled
      Throws:
      org.eclipse.jetty.websocket.core.exception.WebSocketException - there is an error during the upgrade
      See Also:
    • upgrade

      public boolean upgrade(WebSocketCreator creator, org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback)

      Upgrades the given request without matching against the WebSocket mappings.

      When true is returned, a response has been sent to the client and the callback has been completed; either because of a successful WebSocket upgrade, or because an error has occurred.

      When false is returned, a response has not been sent to the client, and the callback has not been completed; for example because the request is not a WebSocket upgrade; in this case the caller must arrange to send a response and complete the callback.

      Parameters:
      creator - the creator of the WebSocket endpoint
      request - the request to upgrade, possibly a WebSocket upgrade request
      response - the response
      callback - the callback to complete when the upgrade is complete
      Returns:
      true in case of WebSocket upgrades or failures, false if the request was not upgraded
      Throws:
      org.eclipse.jetty.websocket.core.exception.WebSocketException - there is an error during the upgrade
      See Also:
    • getInvocationType

      public org.eclipse.jetty.util.thread.Invocable.InvocationType getInvocationType()
      Specified by:
      getInvocationType in interface org.eclipse.jetty.util.thread.Invocable
      Specified by:
      getInvocationType in interface org.eclipse.jetty.server.Request.Handler
      Returns:
      the invocation type, typically blocking or non-blocking, of this container
      See Also:
    • setInvocationType

      public void setInvocationType(org.eclipse.jetty.util.thread.Invocable.InvocationType invocationType)

      Sets the invocation type of this container.

      The invocation type may be set to Invocable.InvocationType.NON_BLOCKING when it is known that application code in the listener methods or annotated methods of the WebSocket endpoint does not use blocking APIs.

      Setting the invocation type to Invocable.InvocationType.NON_BLOCKING, but then using blocking APIs in the WebSocket endpoint may result in a server lockup.

      By default Invocable.InvocationType.BLOCKING is returned, assuming that application code in the WebSocket endpoint uses blocking APIs.

      Parameters:
      invocationType - the invocation type of this container