Class WebSocketSession
- All Implemented Interfaces:
Closeable, AutoCloseable, Dumpable, Configurable, Session
-
Nested Class Summary
Nested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface Session
Session.Listener -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionWebSocketSession(WebSocketContainer container, CoreSession coreSession, JettyWebSocketFrameHandler frameHandler) -
Method Summary
Modifier and TypeMethodDescriptionvoidSends a websocket CLOSE frame, with status code and reason, notifying the given callback when the frame send is completed, either successfully or with a failure.voiddemand()Explicitly demands for WebSocket events.voidAbruptly closes the WebSocket connection without sending a CLOSE frame.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.longGet the maximum size of a binary message during parsing.longThe maximum payload size of any WebSocket Frame which can be received.intGet the maximum number of data frames allowed to be waiting to be sent at any one time.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.booleanIf true, frames are automatically fragmented to respect the maximum frame size.booleanisOpen()booleanisSecure()voidsendBinary(ByteBuffer buffer, Callback callback) Initiates the asynchronous send of a BINARY message, notifying the given callback when the message send is completed, either successfully or with a failure.voidsendPartialBinary(ByteBuffer buffer, boolean last, Callback callback) Initiates the asynchronous send of a BINARY frame, possibly part of a larger binary message, notifying the given callback when the frame send is completed, either successfully or with a failure.voidsendPartialText(String text, boolean last, Callback callback) Initiates the asynchronous send of a TEXT frame, possibly part of a larger binary message, notifying the given callback when the frame send is completed, either successfully or with a failure.voidsendPing(ByteBuffer applicationData, Callback callback) Initiates the asynchronous send of a PING frame, notifying the given callback when the frame send is completed, either successfully or with a failure.voidsendPong(ByteBuffer applicationData, Callback callback) Initiates the asynchronous send of a PONG frame, notifying the given callback when the frame send is completed, either successfully or with a failure.voidInitiates the asynchronous send of a TEXT message, notifying the given callback when the message send is completed, either successfully or with a failure.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.voidsetMaxOutgoingFrames(int maxOutgoingFrames) Set the maximum number of data frames allowed to be waiting to be sent at any one time.voidsetMaxTextMessageSize(long size) The maximum size of a text message during parsing/generating.voidsetOutputBufferSize(int size) The output (write to network layer) buffer size.toString()
-
Constructor Details
-
WebSocketSession
public WebSocketSession(WebSocketContainer container, CoreSession coreSession, JettyWebSocketFrameHandler frameHandler)
-
-
Method Details
-
demand
public void demand()Description copied from interface:SessionExplicitly demands for WebSocket events.
This method should be called only when the WebSocket endpoint is not demanding automatically, as defined by
WebSocket.autoDemand()andSession.Listener.AutoDemanding.In general, invoking this method results in a listener method or an annotated method to be called when the corresponding event is ready to be delivered.
For WebSocket endpoints that wants to receive frame events (for example by overriding
Session.Listener.onWebSocketFrame(Frame, Callback)), invoking this method will result in a frame event being delivered to the listener/annotated method when a new frame is received.For WebSocket endpoints that want to receive whole message events (for example by overriding
Session.Listener.onWebSocketText(String)), invoking this method will result in a message event being delivered to the listener/annotated method when a new message is received. The implementation will automatically demand for more frames until a whole message is assembled and then deliver the whole message as event.Note that even when the WebSocket endpoint is interested in whole messages, calling this method is necessary not only to possibly receive the next whole message, but also to receive control frames (such as PING or CLOSE frames). Failing to call this method after receiving a whole message results in the CLOSE frame event to not be processed, and therefore for the endpoint to not notice when the other peer closed the WebSocket communication.
-
sendBinary
Description copied from interface:SessionInitiates the asynchronous send of a BINARY message, notifying the given callback when the message send is completed, either successfully or with a failure.
- Specified by:
sendBinaryin interfaceSession- Parameters:
buffer- the message bytes to sendcallback- callback to notify when the send operation is complete
-
sendPartialBinary
Description copied from interface:SessionInitiates the asynchronous send of a BINARY frame, possibly part of a larger binary message, notifying the given callback when the frame send is completed, either successfully or with a failure.
Non-final frames must be sent with the parameter
last=false. The final frame must be sent withlast=true.- Specified by:
sendPartialBinaryin interfaceSession- Parameters:
buffer- the frame bytes to sendlast- whether this is the last frame of the messagecallback- callback to notify when the send operation is complete
-
sendText
Description copied from interface:SessionInitiates the asynchronous send of a TEXT message, notifying the given callback when the message send is completed, either successfully or with a failure.
-
sendPartialText
Description copied from interface:SessionInitiates the asynchronous send of a TEXT frame, possibly part of a larger binary message, notifying the given callback when the frame send is completed, either successfully or with a failure.
Non-final frames must be sent with the parameter
last=false. The final frame must be sent withlast=true.- Specified by:
sendPartialTextin interfaceSession- Parameters:
text- the frame text to sendlast- whether this is the last frame of the messagecallback- callback to notify when the send operation is complete
-
sendPing
Description copied from interface:SessionInitiates the asynchronous send of a PING frame, notifying the given callback when the frame send is completed, either successfully or with a failure.
-
sendPong
Description copied from interface:SessionInitiates the asynchronous send of a PONG frame, notifying the given callback when the frame send is completed, either successfully or with a failure.
-
close
Description copied from interface:SessionSends a websocket CLOSE frame, with status code and reason, notifying the given callback when the frame send is completed, either successfully or with a failure.
-
getIdleTimeout
Description copied from interface:ConfigurableThe duration that a websocket may be idle before being closed by the implementation- Specified by:
getIdleTimeoutin interfaceConfigurable- Returns:
- the timeout duration
-
setIdleTimeout
Description copied from interface:ConfigurableThe duration that a websocket may be idle before being closed by the implementation- Specified by:
setIdleTimeoutin interfaceConfigurable- Parameters:
duration- the timeout duration (may not be null or negative)
-
getInputBufferSize
public int getInputBufferSize()Description copied from interface:ConfigurableThe 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 interfaceConfigurable- Returns:
- the raw network buffer input size.
-
setInputBufferSize
public void setInputBufferSize(int size) Description copied from interface:ConfigurableThe input (read from network layer) buffer size.- Specified by:
setInputBufferSizein interfaceConfigurable- Parameters:
size- the size in bytes
-
getOutputBufferSize
public int getOutputBufferSize()Description copied from interface:ConfigurableThe 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 interfaceConfigurable- Returns:
- the raw network buffer output size.
-
setOutputBufferSize
public void setOutputBufferSize(int size) Description copied from interface:ConfigurableThe output (write to network layer) buffer size.- Specified by:
setOutputBufferSizein interfaceConfigurable- Parameters:
size- the size in bytes
-
getMaxBinaryMessageSize
public long getMaxBinaryMessageSize()Description copied from interface:ConfigurableGet 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 interfaceConfigurable- Returns:
- the maximum size of a binary message
-
setMaxBinaryMessageSize
public void setMaxBinaryMessageSize(long size) Description copied from interface:ConfigurableThe 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 interfaceConfigurable- Parameters:
size- the maximum allowed size of a binary message.
-
getMaxTextMessageSize
public long getMaxTextMessageSize()Description copied from interface:ConfigurableGet 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 interfaceConfigurable- Returns:
- the maximum size of a text message.
-
setMaxTextMessageSize
public void setMaxTextMessageSize(long size) Description copied from interface:ConfigurableThe 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 interfaceConfigurable- Parameters:
size- the maximum allowed size of a text message.
-
getMaxFrameSize
public long getMaxFrameSize()Description copied from interface:ConfigurableThe maximum payload size of any WebSocket Frame which can be received.- Specified by:
getMaxFrameSizein interfaceConfigurable- Returns:
- the maximum size of a WebSocket Frame.
-
setMaxFrameSize
public void setMaxFrameSize(long maxFrameSize) Description copied from interface:ConfigurableThe 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 interfaceConfigurable- Parameters:
maxFrameSize- the maximum allowed size of a WebSocket Frame.
-
isAutoFragment
public boolean isAutoFragment()Description copied from interface:ConfigurableIf true, frames are automatically fragmented to respect the maximum frame size.- Specified by:
isAutoFragmentin interfaceConfigurable- Returns:
- whether to automatically fragment incoming WebSocket Frames.
-
setAutoFragment
public void setAutoFragment(boolean autoFragment) Description copied from interface:ConfigurableIf set to true, frames are automatically fragmented to respect the maximum frame size.- Specified by:
setAutoFragmentin interfaceConfigurable- Parameters:
autoFragment- whether to automatically fragment incoming WebSocket Frames.
-
getMaxOutgoingFrames
public int getMaxOutgoingFrames()Description copied from interface:ConfigurableGet 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 aWritePendingExceptionbut the connection is not failed and will remain open.- Specified by:
getMaxOutgoingFramesin interfaceConfigurable- Returns:
- the max number of frames.
-
setMaxOutgoingFrames
public void setMaxOutgoingFrames(int maxOutgoingFrames) Description copied from interface:ConfigurableSet 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 aWritePendingExceptionbut the connection is not failed and will remain open.- Specified by:
setMaxOutgoingFramesin interfaceConfigurable- Parameters:
maxOutgoingFrames- the max number of 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-Versionheader used in theupgrade request.- Specified by:
getProtocolVersionin interfaceSession- Returns:
- the WebSocket protocol version
-
isOpen
-
isSecure
-
disconnect
public void disconnect()Description copied from interface:SessionAbruptly closes the WebSocket connection without sending a CLOSE frame.
- Specified by:
disconnectin interfaceSession- See Also:
-
getLocalSocketAddress
- Specified by:
getLocalSocketAddressin interfaceSession- Returns:
- the local SocketAddress for the connection, if available
-
getRemoteSocketAddress
- Specified by:
getRemoteSocketAddressin interfaceSession- Returns:
- the remote SocketAddress for the connection, if available
-
getUpgradeRequest
- Specified by:
getUpgradeRequestin interfaceSession- Returns:
- the UpgradeRequest used to create this session
-
getUpgradeResponse
- Specified by:
getUpgradeResponsein interfaceSession- Returns:
- the UpgradeResponse used to create this session
-
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
-