Class 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
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.StopExceptionNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainerNested 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.TaskNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.ListenerNested 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, STOPPINGFields inherited from interface org.eclipse.jetty.util.component.Dumpable
KEYFields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking, NOOP -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMapping(String pathSpec, WebSocketCreator creator) Maps the givenpathSpecto the creator of WebSocket endpoints.voidaddMapping(org.eclipse.jetty.http.pathmap.PathSpec pathSpec, WebSocketCreator creator) Maps the givenpathSpecto the creator of WebSocket endpoints.voidaddSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener) static ServerWebSocketContainerensure(org.eclipse.jetty.server.Server server) Returns theServerWebSocketContainer, ensuring that it is available viaget(Context).static ServerWebSocketContainerensure(org.eclipse.jetty.server.Server server, org.eclipse.jetty.server.handler.ContextHandler contextHandler) Returns theServerWebSocketContainer, ensuring that it is available viaget(Context).static ServerWebSocketContainerget(org.eclipse.jetty.server.Context context) Returns theServerWebSocketContainerpresent as the context attribute under the name corresponding to the full qualified name of classWebSocketContainer.intorg.eclipse.jetty.util.thread.Invocable.InvocationTypelonglongintlongCollection<org.eclipse.jetty.websocket.api.Session> intbooleanhandle(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback) Matches the givenrequestagainst existing WebSocket mappings, upgrading to WebSocket if there is a match.booleanvoidnotifySessionListeners(Consumer<org.eclipse.jetty.websocket.api.WebSocketSessionListener> consumer) booleanremoveSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener) voidsetAutoFragment(boolean autoFragment) voidsetIdleTimeout(Duration duration) voidsetInputBufferSize(int size) voidsetInvocationType(org.eclipse.jetty.util.thread.Invocable.InvocationType invocationType) Sets the invocation type of this container.voidsetMaxBinaryMessageSize(long size) voidsetMaxFrameSize(long maxFrameSize) voidsetMaxOutgoingFrames(int maxOutgoingFrames) voidsetMaxTextMessageSize(long size) voidsetOutputBufferSize(int size) booleanupgrade(WebSocketCreator creator, org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback) Upgrades the givenrequestwithout 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, updateBeansMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListenersMethods inherited from interface org.eclipse.jetty.util.component.Dumpable
dumpSelfMethods 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 viaget(Context).If the
ServerWebSocketContaineris not already available, an instance is created, stored to be available viaget(Context)and returned.This method should be invoked during the setup of the
Handlerhierarchy.- Parameters:
server- theServerobject used to lookup common WebSocket componentscontextHandler- theContextHandlerused to store theServerWebSocketContainer- Returns:
- a non-
nullServerWebSocketContainer
-
ensure
Returns the
ServerWebSocketContainer, ensuring that it is available viaget(Context).If the
ServerWebSocketContaineris not already available, an instance is created, stored to be available viaget(Context)and returned.This method should be invoked during the setup of the
Handlerhierarchy.- Parameters:
server- theServerobject used to lookup common WebSocket components and store theServerWebSocketContainer- Returns:
- a non-
nullServerWebSocketContainer
-
get
Returns the
ServerWebSocketContainerpresent as the context attribute under the name corresponding to the full qualified name of classWebSocketContainer.- Parameters:
context- theContextto look for the attribute- Returns:
- the
ServerWebSocketContainerstored as an attribute, ornullif no such attribute is present
-
getExecutor
- Specified by:
getExecutorin interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
getOpenSessions
- Specified by:
getOpenSessionsin interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
addSessionListener
public void addSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener) - Specified by:
addSessionListenerin interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
removeSessionListener
public boolean removeSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener) - Specified by:
removeSessionListenerin interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
notifySessionListeners
public void notifySessionListeners(Consumer<org.eclipse.jetty.websocket.api.WebSocketSessionListener> consumer) - Specified by:
notifySessionListenersin interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
getIdleTimeout
- Specified by:
getIdleTimeoutin interfaceorg.eclipse.jetty.websocket.api.Configurable
-
setIdleTimeout
- Specified by:
setIdleTimeoutin interfaceorg.eclipse.jetty.websocket.api.Configurable
-
getInputBufferSize
public int getInputBufferSize()- Specified by:
getInputBufferSizein interfaceorg.eclipse.jetty.websocket.api.Configurable
-
setInputBufferSize
public void setInputBufferSize(int size) - Specified by:
setInputBufferSizein interfaceorg.eclipse.jetty.websocket.api.Configurable
-
getOutputBufferSize
public int getOutputBufferSize()- Specified by:
getOutputBufferSizein interfaceorg.eclipse.jetty.websocket.api.Configurable
-
setOutputBufferSize
public void setOutputBufferSize(int size) - Specified by:
setOutputBufferSizein interfaceorg.eclipse.jetty.websocket.api.Configurable
-
getMaxBinaryMessageSize
public long getMaxBinaryMessageSize()- Specified by:
getMaxBinaryMessageSizein interfaceorg.eclipse.jetty.websocket.api.Configurable
-
setMaxBinaryMessageSize
public void setMaxBinaryMessageSize(long size) - Specified by:
setMaxBinaryMessageSizein interfaceorg.eclipse.jetty.websocket.api.Configurable
-
getMaxTextMessageSize
public long getMaxTextMessageSize()- Specified by:
getMaxTextMessageSizein interfaceorg.eclipse.jetty.websocket.api.Configurable
-
setMaxTextMessageSize
public void setMaxTextMessageSize(long size) - Specified by:
setMaxTextMessageSizein interfaceorg.eclipse.jetty.websocket.api.Configurable
-
getMaxFrameSize
public long getMaxFrameSize()- Specified by:
getMaxFrameSizein interfaceorg.eclipse.jetty.websocket.api.Configurable
-
setMaxFrameSize
public void setMaxFrameSize(long maxFrameSize) - Specified by:
setMaxFrameSizein interfaceorg.eclipse.jetty.websocket.api.Configurable
-
isAutoFragment
public boolean isAutoFragment()- Specified by:
isAutoFragmentin interfaceorg.eclipse.jetty.websocket.api.Configurable
-
setAutoFragment
public void setAutoFragment(boolean autoFragment) - Specified by:
setAutoFragmentin interfaceorg.eclipse.jetty.websocket.api.Configurable
-
getMaxOutgoingFrames
public int getMaxOutgoingFrames()- Specified by:
getMaxOutgoingFramesin interfaceorg.eclipse.jetty.websocket.api.Configurable
-
setMaxOutgoingFrames
public void setMaxOutgoingFrames(int maxOutgoingFrames) - Specified by:
setMaxOutgoingFramesin interfaceorg.eclipse.jetty.websocket.api.Configurable
-
addMapping
Maps the given
pathSpecto the creator of WebSocket endpoints.The
pathSpecformat is that supported byWebSocketMappings.parsePathSpec(String).- Parameters:
pathSpec- thepathSpecto associate to the creatorcreator- the creator of WebSocket endpoints
-
addMapping
Maps the given
pathSpecto the creator of WebSocket endpoints.- Parameters:
pathSpec- thepathSpecto associate to the creatorcreator- 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
requestagainst 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
trueis returned, a response has been sent to the client and thecallbackhas been completed; either because of a successful WebSocket upgrade, or because an error has occurred.When
falseis returned, a response has not been sent to the client, and thecallbackhas not been completed; typically because the request path does not match any existing WebSocket mappings, so that the request can be handled by otherHandlers.- Specified by:
handlein interfaceorg.eclipse.jetty.server.Request.Handler- Parameters:
request- the request to handle, possibly a WebSocket upgrade requestresponse- the response to handlecallback- the callback to complete when the handling is complete- Returns:
truein case of WebSocket upgrades or failures,falseif 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
requestwithout matching against the WebSocket mappings.When
trueis returned, a response has been sent to the client and thecallbackhas been completed; either because of a successful WebSocket upgrade, or because an error has occurred.When
falseis returned, a response has not been sent to the client, and thecallbackhas 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 endpointrequest- the request to upgrade, possibly a WebSocket upgrade requestresponse- the responsecallback- the callback to complete when the upgrade is complete- Returns:
truein case of WebSocket upgrades or failures,falseif 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:
getInvocationTypein interfaceorg.eclipse.jetty.util.thread.Invocable- Specified by:
getInvocationTypein interfaceorg.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_BLOCKINGwhen 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.BLOCKINGis returned, assuming that application code in the WebSocket endpoint uses blocking APIs.- Parameters:
invocationType- the invocation type of this container
-