Top Description Inners Fields Constructors Methods
org.eclipse.jetty.websocket.server

public Class ServerWebSocketContainer

extends ContainerLifeCycle
implements WebSocketContainer, Configurable, Invocable, Handler
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.server.Request.Handler, org.eclipse.jetty.util.thread.Invocable, org.eclipse.jetty.websocket.api.Configurable, org.eclipse.jetty.websocket.api.WebSocketContainer
Imports
java.time.Duration, java.util.ArrayList, .Collection, .List, java.util.concurrent.Executor, java.util.function.Consumer, org.eclipse.jetty.http.pathmap.PathSpec, org.eclipse.jetty.server.Context, .Handler, .Request, .Response, .Server, org.eclipse.jetty.server.handler.ContextHandler, org.eclipse.jetty.util.Callback, org.eclipse.jetty.util.component.ContainerLifeCycle, org.eclipse.jetty.util.thread.Invocable, org.eclipse.jetty.websocket.api.Configurable, .Session, .WebSocketContainer, .WebSocketSessionListener, org.eclipse.jetty.websocket.common.SessionTracker, org.eclipse.jetty.websocket.core.WebSocketComponents, org.eclipse.jetty.websocket.core.exception.WebSocketException, org.eclipse.jetty.websocket.core.server.FrameHandlerFactory, .WebSocketMappings, .WebSocketNegotiator, .WebSocketServerComponents, org.eclipse.jetty.websocket.server.internal.ServerFrameHandlerFactory, .ServerUpgradeRequestDelegate, .ServerUpgradeResponseDelegate, org.slf4j.Logger, .LoggerFactory

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 and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final ServerWebSocketContainer.Configuration
private final FrameHandlerFactory
private Invocable.InvocationType
private final List<WebSocketSessionListener>
private static final Logger
private final WebSocketMappings
private final SessionTracker

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
addMapping(String
the pathSpec to associate to the creator
pathSpec
,
WebSocketCreator
the creator of WebSocket endpoints
creator
)

Maps the given pathSpec to the creator of WebSocket endpoints.

public void
addMapping(PathSpec
the pathSpec to associate to the creator
pathSpec
,
WebSocketCreator
the creator of WebSocket endpoints
creator
)

Maps the given pathSpec to the creator of WebSocket endpoints.

public void
addSessionListener(WebSocketSessionListener
the listener
listener
)

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.addSessionListener.

Register a WebSocketSessionListener with the container

public static ServerWebSocketContainer

Returns:

a non-null ServerWebSocketContainer
ensure
(Server
the Server object used to lookup common WebSocket components
server
,
ContextHandler contextHandler)

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

public static ServerWebSocketContainer

Returns:

the ServerWebSocketContainer stored as an attribute, or null if no such attribute is present
get
(Context
the Context to look for the attribute
context
)

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

public Executor
public Duration
getIdleTimeout()

Implements org.eclipse.jetty.websocket.api.Configurable.getIdleTimeout.

The duration that a websocket may be idle before being closed by the implementation

public int
getInputBufferSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getInputBufferSize.

The input (read from network layer) buffer size.

public Invocable.InvocationType
getInvocationType()

Overrides default org.eclipse.jetty.util.thread.Invocable.getInvocationType, org.eclipse.jetty.server.Request.Handler.getInvocationType.

Returns: the invocation type, typically blocking or non-blocking, of this container

public long
getMaxBinaryMessageSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxBinaryMessageSize.

Get the maximum size of a binary message during parsing.

public long
getMaxFrameSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxFrameSize.

The maximum payload size of any WebSocket Frame which can be received.

public int
getMaxOutgoingFrames()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxOutgoingFrames.

Get the maximum number of data frames allowed to be waiting to be sent at any one time.

public long
getMaxTextMessageSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxTextMessageSize.

Get the maximum size of a text message during parsing.

public Collection<Session>
getOpenSessions()

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.getOpenSessions.

Get the collection of open Sessions being tracked by this container

public int
getOutputBufferSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getOutputBufferSize.

The output (write to network layer) buffer size.

public boolean

Returns:

true in case of WebSocket upgrades or failures, false if the request was not handled
handle
(Request
the request to handle, possibly a WebSocket upgrade request
request
,
Response
the response to handle
response
,
Callback
the callback to complete when the handling is complete
callback
)

Implements org.eclipse.jetty.server.Request.Handler.handle.

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

public boolean
isAutoFragment()

Implements org.eclipse.jetty.websocket.api.Configurable.isAutoFragment.

If true, frames are automatically fragmented to respect the maximum frame size.

private WebSocketCreator
public void
notifySessionListeners(Consumer<WebSocketSessionListener>
the consumer to call for each tracked listener
consumer
)

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.notifySessionListeners.

Notify the Session Listeners of an event.

public boolean
removeSessionListener(WebSocketSessionListener
the listener
listener
)

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.removeSessionListener.

Remove a WebSocketSessionListener from the container

public void
setAutoFragment(boolean
whether to automatically fragment incoming WebSocket Frames.
autoFragment
)

Implements org.eclipse.jetty.websocket.api.Configurable.setAutoFragment.

If set to true, frames are automatically fragmented to respect the maximum frame size.

public void
setIdleTimeout(Duration
the timeout duration (may not be null or negative)
duration
)

Implements org.eclipse.jetty.websocket.api.Configurable.setIdleTimeout.

The duration that a websocket may be idle before being closed by the implementation

public void
setInputBufferSize(int
the size in bytes
size
)

Implements org.eclipse.jetty.websocket.api.Configurable.setInputBufferSize.

The input (read from network layer) buffer size.

public void
setInvocationType(Invocable.InvocationType
the invocation type of this container
invocationType
)

Sets the invocation type of this container.

public void
setMaxBinaryMessageSize(long
the maximum allowed size of a binary message.
size
)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxBinaryMessageSize.

The maximum size of a binary message during parsing/generating.

public void
setMaxFrameSize(long
the maximum allowed size of a WebSocket Frame.
maxFrameSize
)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxFrameSize.

The maximum payload size of any WebSocket Frame which can be received.

public void
setMaxOutgoingFrames(int
the max number of frames.
maxOutgoingFrames
)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxOutgoingFrames.

Set the maximum number of data frames allowed to be waiting to be sent at any one time.

public void
setMaxTextMessageSize(long
the maximum allowed size of a text message.
size
)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxTextMessageSize.

The maximum size of a text message during parsing/generating.

public void
setOutputBufferSize(int
the size in bytes
size
)

Implements org.eclipse.jetty.websocket.api.Configurable.setOutputBufferSize.

The output (write to network layer) buffer size.

public boolean

Returns:

true in case of WebSocket upgrades or failures, false if the request was not upgraded
upgrade
(WebSocketCreator
the creator of the WebSocket endpoint
creator
,
Request
the request to upgrade, possibly a WebSocket upgrade request
request
,
Response
the response
response
,
Callback
the callback to complete when the upgrade is complete
callback
)

Upgrades the given request without matching against the WebSocket mappings.

Inherited from org.eclipse.jetty.util.component.ContainerLifeCycle:
addBeanaddBeanaddEventListeneraddManagedcontainsdestroydoStartdoStopdumpdumpdumpdumpObjectsdumpStdErrgetBeangetBeansgetBeansgetContainedBeansgetContainedBeansisAutoisManagedisUnmanagedmanageremoveBeanremoveBeansremoveEventListenersetBeansstartstopunmanageupdateBeanupdateBeanupdateBeansupdateBeans

Field Detail

configurationback to summary
private final ServerWebSocketContainer.Configuration configuration
factoryback to summary
private final FrameHandlerFactory factory
invocationTypeback to summary
private Invocable.InvocationType invocationType
listenersback to summary
private final List<WebSocketSessionListener> listeners
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.util.component.ContainerLifeCycle.LOG.

mappingsback to summary
private final WebSocketMappings mappings
sessionTrackerback to summary
private final SessionTracker sessionTracker

Constructor Detail

ServerWebSocketContainerback to summary
pack-priv ServerWebSocketContainer(WebSocketMappings mappings)

Method Detail

addMappingback to summary
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:String

the pathSpec to associate to the creator

creator:WebSocketCreator

the creator of WebSocket endpoints

addMappingback to summary
public void addMapping(PathSpec pathSpec, WebSocketCreator creator)

Maps the given pathSpec to the creator of WebSocket endpoints.

Parameters
pathSpec:PathSpec

the pathSpec to associate to the creator

creator:WebSocketCreator

the creator of WebSocket endpoints

addSessionListenerback to summary
public void addSessionListener(WebSocketSessionListener listener)

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.addSessionListener.

Doc from org.eclipse.jetty.websocket.api.WebSocketContainer.addSessionListener.

Register a WebSocketSessionListener with the container

Parameters
listener:WebSocketSessionListener

the listener

Annotations
@Override
ensureback to summary
public static ServerWebSocketContainer ensure(Server server, 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:Server

the Server object used to lookup common WebSocket components

contextHandler:ContextHandler

the ContextHandler used to store the ServerWebSocketContainer

Returns:ServerWebSocketContainer

a non-null ServerWebSocketContainer

getback to summary
public static ServerWebSocketContainer get(Context context)

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

Parameters
context:Context

the Context to look for the attribute

Returns:ServerWebSocketContainer

the ServerWebSocketContainer stored as an attribute, or null if no such attribute is present

getExecutorback to summary
public Executor getExecutor()

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.getExecutor.

Doc from org.eclipse.jetty.websocket.api.WebSocketContainer.getExecutor.

The Container provided Executor.

Annotations
@Override
getIdleTimeoutback to summary
public Duration getIdleTimeout()

Implements org.eclipse.jetty.websocket.api.Configurable.getIdleTimeout.

Doc from org.eclipse.jetty.websocket.api.Configurable.getIdleTimeout.

The duration that a websocket may be idle before being closed by the implementation

Returns:Duration

the timeout duration

Annotations
@Override
getInputBufferSizeback to summary
public int getInputBufferSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getInputBufferSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.getInputBufferSize.

The input (read from network layer) buffer size.

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

Returns:int

the raw network buffer input size.

Annotations
@Override
getInvocationTypeback to summary
public Invocable.InvocationType getInvocationType()

Overrides default org.eclipse.jetty.util.thread.Invocable.getInvocationType, org.eclipse.jetty.server.Request.Handler.getInvocationType.

Returns:Invocable.InvocationType

the invocation type, typically blocking or non-blocking, of this container

Annotations
@Override
See Also
setInvocationType(InvocationType)
getMaxBinaryMessageSizeback to summary
public long getMaxBinaryMessageSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxBinaryMessageSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.getMaxBinaryMessageSize.

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

Returns:long

the maximum size of a binary message

Annotations
@Override
getMaxFrameSizeback to summary
public long getMaxFrameSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxFrameSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.getMaxFrameSize.

The maximum payload size of any WebSocket Frame which can be received.

Returns:long

the maximum size of a WebSocket Frame.

Annotations
@Override
getMaxOutgoingFramesback to summary
public int getMaxOutgoingFrames()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxOutgoingFrames.

Doc from org.eclipse.jetty.websocket.api.Configurable.getMaxOutgoingFrames.

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 java.nio.channels.WritePendingException but the connection is not failed and will remain open.

Returns:int

the max number of frames.

Annotations
@Override
getMaxTextMessageSizeback to summary
public long getMaxTextMessageSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxTextMessageSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.getMaxTextMessageSize.

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

Returns:long

the maximum size of a text message.

Annotations
@Override
getOpenSessionsback to summary
public Collection<Session> getOpenSessions()

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.getOpenSessions.

Doc from org.eclipse.jetty.websocket.api.WebSocketContainer.getOpenSessions.

Get the collection of open Sessions being tracked by this container

Returns:Collection<Session>

the collection of open sessions

Annotations
@Override
getOutputBufferSizeback to summary
public int getOutputBufferSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getOutputBufferSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.getOutputBufferSize.

The output (write to network layer) buffer size.

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

Returns:int

the raw network buffer output size.

Annotations
@Override
handleback to summary
public boolean handle(Request request, Response response, Callback callback) throws WebSocketException

Implements org.eclipse.jetty.server.Request.Handler.handle.

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.

Parameters
request:Request

the request to handle, possibly a WebSocket upgrade request

response:Response

the response to handle

callback:Callback

the callback to complete when the handling is complete

Returns:boolean

true in case of WebSocket upgrades or failures, false if the request was not handled

Annotations
@Override
Exceptions
WebSocketException:
there is an error during the upgrade
See Also
addMapping(PathSpec, WebSocketCreator), upgrade(WebSocketCreator, Request, Response, Callback)
isAutoFragmentback to summary
public boolean isAutoFragment()

Implements org.eclipse.jetty.websocket.api.Configurable.isAutoFragment.

Doc from org.eclipse.jetty.websocket.api.Configurable.isAutoFragment.

If true, frames are automatically fragmented to respect the maximum frame size.

Returns:boolean

whether to automatically fragment incoming WebSocket Frames.

Annotations
@Override
newWebSocketCreatorback to summary
private WebSocketCreator newWebSocketCreator(WebSocketCreator creator)
notifySessionListenersback to summary
public void notifySessionListeners(Consumer<WebSocketSessionListener> consumer)

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.notifySessionListeners.

Doc from org.eclipse.jetty.websocket.api.WebSocketContainer.notifySessionListeners.

Notify the Session Listeners of an event.

Parameters
consumer:Consumer<WebSocketSessionListener>

the consumer to call for each tracked listener

Annotations
@Override
removeSessionListenerback to summary
public boolean removeSessionListener(WebSocketSessionListener listener)

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.removeSessionListener.

Doc from org.eclipse.jetty.websocket.api.WebSocketContainer.removeSessionListener.

Remove a WebSocketSessionListener from the container

Parameters
listener:WebSocketSessionListener

the listener

Returns:boolean

true if listener was present and removed

Annotations
@Override
setAutoFragmentback to summary
public void setAutoFragment(boolean autoFragment)

Implements org.eclipse.jetty.websocket.api.Configurable.setAutoFragment.

Doc from org.eclipse.jetty.websocket.api.Configurable.setAutoFragment.

If set to true, frames are automatically fragmented to respect the maximum frame size.

Parameters
autoFragment:boolean

whether to automatically fragment incoming WebSocket Frames.

Annotations
@Override
setIdleTimeoutback to summary
public void setIdleTimeout(Duration duration)

Implements org.eclipse.jetty.websocket.api.Configurable.setIdleTimeout.

Doc from org.eclipse.jetty.websocket.api.Configurable.setIdleTimeout.

The duration that a websocket may be idle before being closed by the implementation

Parameters
duration:Duration

the timeout duration (may not be null or negative)

Annotations
@Override
setInputBufferSizeback to summary
public void setInputBufferSize(int size)

Implements org.eclipse.jetty.websocket.api.Configurable.setInputBufferSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.setInputBufferSize.

The input (read from network layer) buffer size.

Parameters
size:int

the size in bytes

Annotations
@Override
setInvocationTypeback to summary
public void setInvocationType(Invocable.InvocationType invocationType)

Sets the invocation type of this container.

The invocation type may be set to 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 InvocationType#NON_BLOCKING, but then using blocking APIs in the WebSocket endpoint may result in a server lockup.

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

Parameters
invocationType:Invocable.InvocationType

the invocation type of this container

setMaxBinaryMessageSizeback to summary
public void setMaxBinaryMessageSize(long size)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxBinaryMessageSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.setMaxBinaryMessageSize.

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

Parameters
size:long

the maximum allowed size of a binary message.

Annotations
@Override
setMaxFrameSizeback to summary
public void setMaxFrameSize(long maxFrameSize)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxFrameSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.setMaxFrameSize.

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

Parameters
maxFrameSize:long

the maximum allowed size of a WebSocket Frame.

Annotations
@Override
setMaxOutgoingFramesback to summary
public void setMaxOutgoingFrames(int maxOutgoingFrames)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxOutgoingFrames.

Doc from org.eclipse.jetty.websocket.api.Configurable.setMaxOutgoingFrames.

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 java.nio.channels.WritePendingException but the connection is not failed and will remain open.

Parameters
maxOutgoingFrames:int

the max number of frames.

Annotations
@Override
setMaxTextMessageSizeback to summary
public void setMaxTextMessageSize(long size)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxTextMessageSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.setMaxTextMessageSize.

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

Parameters
size:long

the maximum allowed size of a text message.

Annotations
@Override
setOutputBufferSizeback to summary
public void setOutputBufferSize(int size)

Implements org.eclipse.jetty.websocket.api.Configurable.setOutputBufferSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.setOutputBufferSize.

The output (write to network layer) buffer size.

Parameters
size:int

the size in bytes

Annotations
@Override
upgradeback to summary
public boolean upgrade(WebSocketCreator creator, Request request, Response response, Callback callback) throws WebSocketException

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:WebSocketCreator

the creator of the WebSocket endpoint

request:Request

the request to upgrade, possibly a WebSocket upgrade request

response:Response

the response

callback:Callback

the callback to complete when the upgrade is complete

Returns:boolean

true in case of WebSocket upgrades or failures, false if the request was not upgraded

Exceptions
WebSocketException:
there is an error during the upgrade
See Also
handle(Request, Response, Callback)
org.eclipse.jetty.websocket.server back to summary

private Class ServerWebSocketContainer.Configuration

extends ConfigurationCustomizer
implements Configurable
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.websocket.api.Configurable

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from org.eclipse.jetty.websocket.core.Configuration.ConfigurationCustomizer:
customizegetIdleTimeoutgetInputBufferSizegetMaxBinaryMessageSizegetMaxFrameSizegetMaxOutgoingFramesgetMaxTextMessageSizegetOutputBufferSizegetWriteTimeoutisAutoFragmentsetAutoFragmentsetIdleTimeoutsetInputBufferSizesetMaxBinaryMessageSizesetMaxFrameSizesetMaxOutgoingFramessetMaxTextMessageSizesetOutputBufferSizesetWriteTimeouttoString

Constructor Detail

Configurationback to summary
private Configuration()