Class WebSocketSession
- All Implemented Interfaces:
Closeable, AutoCloseable, Session, SuspendToken, WebSocketPolicy, Dumpable
-
Nested Class Summary
Nested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainer -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionWebSocketSession(WebSocketContainer container, CoreSession coreSession, JettyWebSocketFrameHandler frameHandler) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Request a close of the current conversation with a normal status code and no reason phrase.voidSend a websocket Close frame, with status code.voidclose(int statusCode, String reason, WriteCallback callback) Send a websocket Close frame, with status code.voidclose(CloseStatus closeStatus) Request Close the current conversation, giving a reason for the closure.voidIssue a harsh disconnect of the underlying connection.voiddump(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.dumpSelf()The description of this/self found in the dump.The duration that a websocket may be idle before being closed by the implementationintThe input (read from network layer) buffer size.The Local Socket Address for the active SessionlongGet the maximum size of a binary message during parsing.longThe maximum payload size of any WebSocket Frame which can be received.longGet the maximum size of a text message during parsing.intThe output (write to network layer) buffer size.Returns the version of the websocket protocol currently being used.Return a reference to the RemoteEndpoint object representing the other end of this conversation.The Remote Socket Address for the active SessionGet the UpgradeRequest used to create this sessionGet the UpgradeResponse used to create this sessionbooleanIf true, frames are automatically fragmented to respect the maximum frame size.booleanisOpen()Return true if and only if the underlying socket is open.booleanisSecure()Return true if and only if the underlying socket is using a secure transport.voidresume()Resume a previously suspended connection.voidsetAutoFragment(boolean autoFragment) If set to true, frames are automatically fragmented to respect the maximum frame size.voidsetIdleTimeout(Duration duration) The duration that a websocket may be idle before being closed by the implementationvoidsetInputBufferSize(int size) The input (read from network layer) buffer size.voidsetMaxBinaryMessageSize(long size) The maximum size of a binary message during parsing/generating.voidsetMaxFrameSize(long maxFrameSize) The maximum payload size of any WebSocket Frame which can be received.voidsetMaxTextMessageSize(long size) The maximum size of a text message during parsing/generating.voidsetOutputBufferSize(int size) The output (write to network layer) buffer size.suspend()Suspend the delivery of incoming WebSocket frames.toString()
-
Constructor Details
-
WebSocketSession
public WebSocketSession(WebSocketContainer container, CoreSession coreSession, JettyWebSocketFrameHandler frameHandler)
-
-
Method Details
-
close
public void close()Description copied from interface:SessionRequest a close of the current conversation with a normal status code and no reason phrase.This will enqueue a graceful close to the remote endpoint.
-
close
Description copied from interface:SessionRequest Close the current conversation, giving a reason for the closure. Note the websocket spec defines the acceptable uses of status codes and reason phrases.This will enqueue a graceful close to the remote endpoint.
-
close
Description copied from interface:SessionSend a websocket Close frame, with status code.This will enqueue a graceful close to the remote endpoint.
-
close
Description copied from interface:SessionSend a websocket Close frame, with status code.This will enqueue a graceful close to the remote endpoint.
-
getBehavior
- Specified by:
getBehaviorin interfaceWebSocketPolicy
-
getIdleTimeout
Description copied from interface:WebSocketPolicyThe duration that a websocket may be idle before being closed by the implementation- Specified by:
getIdleTimeoutin interfaceWebSocketPolicy- Returns:
- the timeout duration
-
getInputBufferSize
public int getInputBufferSize()Description copied from interface:WebSocketPolicyThe input (read from network layer) buffer size.This is the raw read operation buffer size, before the parsing of the websocket frames.
- Specified by:
getInputBufferSizein interfaceWebSocketPolicy- Returns:
- the raw network buffer input size.
-
getOutputBufferSize
public int getOutputBufferSize()Description copied from interface:WebSocketPolicyThe 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:
getOutputBufferSizein interfaceWebSocketPolicy- Returns:
- the raw network buffer output size.
-
getMaxBinaryMessageSize
public long getMaxBinaryMessageSize()Description copied from interface:WebSocketPolicyGet 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:
getMaxBinaryMessageSizein interfaceWebSocketPolicy- Returns:
- the maximum size of a binary message
-
getMaxTextMessageSize
public long getMaxTextMessageSize()Description copied from interface:WebSocketPolicyGet 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:
getMaxTextMessageSizein interfaceWebSocketPolicy- Returns:
- the maximum size of a text message.
-
getMaxFrameSize
public long getMaxFrameSize()Description copied from interface:WebSocketPolicyThe maximum payload size of any WebSocket Frame which can be received.- Specified by:
getMaxFrameSizein interfaceWebSocketPolicy- Returns:
- the maximum size of a WebSocket Frame.
-
isAutoFragment
public boolean isAutoFragment()Description copied from interface:WebSocketPolicyIf true, frames are automatically fragmented to respect the maximum frame size.- Specified by:
isAutoFragmentin interfaceWebSocketPolicy- Returns:
- whether to automatically fragment incoming WebSocket Frames.
-
setIdleTimeout
Description copied from interface:WebSocketPolicyThe duration that a websocket may be idle before being closed by the implementation- Specified by:
setIdleTimeoutin interfaceWebSocketPolicy- Parameters:
duration- the timeout duration (may not be null or negative)
-
setInputBufferSize
public void setInputBufferSize(int size) Description copied from interface:WebSocketPolicyThe input (read from network layer) buffer size.- Specified by:
setInputBufferSizein interfaceWebSocketPolicy- Parameters:
size- the size in bytes
-
setOutputBufferSize
public void setOutputBufferSize(int size) Description copied from interface:WebSocketPolicyThe output (write to network layer) buffer size.- Specified by:
setOutputBufferSizein interfaceWebSocketPolicy- Parameters:
size- the size in bytes
-
setMaxBinaryMessageSize
public void setMaxBinaryMessageSize(long size) Description copied from interface:WebSocketPolicyThe 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:
setMaxBinaryMessageSizein interfaceWebSocketPolicy- Parameters:
size- the maximum allowed size of a binary message.
-
setMaxTextMessageSize
public void setMaxTextMessageSize(long size) Description copied from interface:WebSocketPolicyThe 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:
setMaxTextMessageSizein interfaceWebSocketPolicy- Parameters:
size- the maximum allowed size of a text message.
-
setMaxFrameSize
public void setMaxFrameSize(long maxFrameSize) Description copied from interface:WebSocketPolicyThe 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:
setMaxFrameSizein interfaceWebSocketPolicy- Parameters:
maxFrameSize- the maximum allowed size of a WebSocket Frame.
-
setAutoFragment
public void setAutoFragment(boolean autoFragment) Description copied from interface:WebSocketPolicyIf set to true, frames are automatically fragmented to respect the maximum frame size.- Specified by:
setAutoFragmentin interfaceWebSocketPolicy- Parameters:
autoFragment- whether to automatically fragment incoming WebSocket Frames.
-
getProtocolVersion
Description copied from interface:SessionReturns the version of the websocket protocol currently being used. This is taken as the value of the Sec-WebSocket-Version header used in the opening handshake. i.e. "13".- Specified by:
getProtocolVersionin interfaceSession- Returns:
- the protocol version
-
getRemote
Description copied from interface:SessionReturn a reference to the RemoteEndpoint object representing the other end of this conversation. -
isOpen
-
isSecure
-
disconnect
public void disconnect()Description copied from interface:SessionIssue a harsh disconnect of the underlying connection.This will terminate the connection, without sending a websocket close frame.
Once called, any read/write activity on the websocket from this point will be indeterminate.
Once the underlying connection has been determined to be closed, the various onClose() events (either
WebSocketConnectionListener.onWebSocketClose(int, String)orOnWebSocketClose) will be called on your websocket.- Specified by:
disconnectin interfaceSession- See Also:
-
getLocalAddress
Description copied from interface:SessionThe Local Socket Address for the active SessionDo not assume that this will return a
InetSocketAddressin all cases. Use of various proxies, and even UnixSockets can result a SocketAddress being returned without supportingInetSocketAddress- Specified by:
getLocalAddressin interfaceSession- Returns:
- the SocketAddress for the local connection, or null if not supported by Session
-
getRemoteAddress
Description copied from interface:SessionThe Remote Socket Address for the active SessionDo not assume that this will return a
InetSocketAddressin all cases. Use of various proxies, and even UnixSockets can result a SocketAddress being returned without supportingInetSocketAddress- Specified by:
getRemoteAddressin interfaceSession- Returns:
- the SocketAddress for the remote connection, or null if not supported by Session
-
getUpgradeRequest
Description copied from interface:SessionGet the UpgradeRequest used to create this session- Specified by:
getUpgradeRequestin interfaceSession- Returns:
- the UpgradeRequest used to create this session
-
getUpgradeResponse
Description copied from interface:SessionGet the UpgradeResponse used to create this session- Specified by:
getUpgradeResponsein interfaceSession- Returns:
- the UpgradeResponse used to create this session
-
suspend
Description copied from interface:SessionSuspend the delivery of incoming WebSocket frames.If this is called from inside the scope of the message handler the suspend takes effect immediately. If suspend is called outside the scope of the message handler then the call may take effect after 1 more frame is delivered.
-
resume
public void resume()Description copied from interface:SuspendTokenResume a previously suspended connection.- Specified by:
resumein interfaceSuspendToken
-
getCoreSession
-
dump
Description copied from interface:DumpableDump 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:
dumpin interfaceDumpable- Parameters:
out- The appendable to dump toindent- The indent to apply after any new lines.- Throws:
IOException- if unable to write to Appendable
-
dumpSelf
Description copied from interface:DumpableThe description of this/self found in the dump. Allows for alternative representation of Object other then .toString() where the long form output of toString() is represented in a cleaner way within the dump infrastructure. -
toString
-