Class WebSocketSession
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Dumpable
,Configurable
,Session
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
Nested classes/interfaces inherited from interface org.eclipse.jetty.websocket.api.Session
Session.Listener
-
Field Summary
-
Constructor Summary
ConstructorDescriptionWebSocketSession
(WebSocketContainer container, CoreSession coreSession, JettyWebSocketFrameHandler frameHandler) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Sends 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.void
demand()
Explicitly demands for WebSocket events.void
Abruptly closes the WebSocket connection without sending a CLOSE frame.void
dump
(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 implementationint
The input (read from network layer) buffer size.long
Get the maximum size of a binary message during parsing.long
The maximum payload size of any WebSocket Frame which can be received.int
Get the maximum number of data frames allowed to be waiting to be sent at any one time.long
Get the maximum size of a text message during parsing.int
The output (write to network layer) buffer size.Returns the version of the WebSocket protocol currently being used.boolean
If true, frames are automatically fragmented to respect the maximum frame size.boolean
isOpen()
boolean
isSecure()
void
sendBinary
(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.void
sendPartialBinary
(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.void
sendPartialText
(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.void
sendPing
(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.void
sendPong
(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.void
Initiates the asynchronous send of a TEXT message, notifying the given callback when the message send is completed, either successfully or with a failure.void
setAutoFragment
(boolean autoFragment) If set to true, frames are automatically fragmented to respect the maximum frame size.void
setIdleTimeout
(Duration duration) The duration that a websocket may be idle before being closed by the implementationvoid
setInputBufferSize
(int size) The input (read from network layer) buffer size.void
setMaxBinaryMessageSize
(long size) The maximum size of a binary message during parsing/generating.void
setMaxFrameSize
(long maxFrameSize) The maximum payload size of any WebSocket Frame which can be received.void
setMaxOutgoingFrames
(int maxOutgoingFrames) Set the maximum number of data frames allowed to be waiting to be sent at any one time.void
setMaxTextMessageSize
(long size) The maximum size of a text message during parsing/generating.void
setOutputBufferSize
(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:Session
Explicitly 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:Session
Initiates 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:
sendBinary
in interfaceSession
- Parameters:
buffer
- the message bytes to sendcallback
- callback to notify when the send operation is complete
-
sendPartialBinary
Description copied from interface:Session
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.
Non-final frames must be sent with the parameter
last=false
. The final frame must be sent withlast=true
.- Specified by:
sendPartialBinary
in 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:Session
Initiates 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:Session
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.
Non-final frames must be sent with the parameter
last=false
. The final frame must be sent withlast=true
.- Specified by:
sendPartialText
in 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:Session
Initiates 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:Session
Initiates 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:Session
Sends 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:Configurable
The duration that a websocket may be idle before being closed by the implementation- Specified by:
getIdleTimeout
in interfaceConfigurable
- Returns:
- the timeout duration
-
setIdleTimeout
Description copied from interface:Configurable
The duration that a websocket may be idle before being closed by the implementation- Specified by:
setIdleTimeout
in interfaceConfigurable
- Parameters:
duration
- the timeout duration (may not be null or negative)
-
getInputBufferSize
public int getInputBufferSize()Description copied from interface:Configurable
The input (read from network layer) buffer size.This is the raw read operation buffer size, before the parsing of the websocket frames.
- Specified by:
getInputBufferSize
in interfaceConfigurable
- Returns:
- the raw network buffer input size.
-
setInputBufferSize
public void setInputBufferSize(int size) Description copied from interface:Configurable
The input (read from network layer) buffer size.- Specified by:
setInputBufferSize
in interfaceConfigurable
- Parameters:
size
- the size in bytes
-
getOutputBufferSize
public int getOutputBufferSize()Description copied from interface:Configurable
The 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:
getOutputBufferSize
in interfaceConfigurable
- Returns:
- the raw network buffer output size.
-
setOutputBufferSize
public void setOutputBufferSize(int size) Description copied from interface:Configurable
The output (write to network layer) buffer size.- Specified by:
setOutputBufferSize
in interfaceConfigurable
- Parameters:
size
- the size in bytes
-
getMaxBinaryMessageSize
public long getMaxBinaryMessageSize()Description copied from interface:Configurable
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
- Specified by:
getMaxBinaryMessageSize
in interfaceConfigurable
- Returns:
- the maximum size of a binary message
-
setMaxBinaryMessageSize
public void setMaxBinaryMessageSize(long size) Description copied from interface:Configurable
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
- Specified by:
setMaxBinaryMessageSize
in interfaceConfigurable
- Parameters:
size
- the maximum allowed size of a binary message.
-
getMaxTextMessageSize
public long getMaxTextMessageSize()Description copied from interface:Configurable
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
- Specified by:
getMaxTextMessageSize
in interfaceConfigurable
- Returns:
- the maximum size of a text message.
-
setMaxTextMessageSize
public void setMaxTextMessageSize(long size) Description copied from interface:Configurable
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
- Specified by:
setMaxTextMessageSize
in interfaceConfigurable
- Parameters:
size
- the maximum allowed size of a text message.
-
getMaxFrameSize
public long getMaxFrameSize()Description copied from interface:Configurable
The maximum payload size of any WebSocket Frame which can be received.- Specified by:
getMaxFrameSize
in interfaceConfigurable
- Returns:
- the maximum size of a WebSocket Frame.
-
setMaxFrameSize
public void setMaxFrameSize(long maxFrameSize) Description copied from interface:Configurable
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
- Specified by:
setMaxFrameSize
in interfaceConfigurable
- Parameters:
maxFrameSize
- the maximum allowed size of a WebSocket Frame.
-
isAutoFragment
public boolean isAutoFragment()Description copied from interface:Configurable
If true, frames are automatically fragmented to respect the maximum frame size.- Specified by:
isAutoFragment
in interfaceConfigurable
- Returns:
- whether to automatically fragment incoming WebSocket Frames.
-
setAutoFragment
public void setAutoFragment(boolean autoFragment) Description copied from interface:Configurable
If set to true, frames are automatically fragmented to respect the maximum frame size.- Specified by:
setAutoFragment
in interfaceConfigurable
- Parameters:
autoFragment
- whether to automatically fragment incoming WebSocket Frames.
-
getMaxOutgoingFrames
public int getMaxOutgoingFrames()Description copied from interface:Configurable
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 aWritePendingException
but the connection is not failed and will remain open.- Specified by:
getMaxOutgoingFrames
in interfaceConfigurable
- Returns:
- the max number of frames.
-
setMaxOutgoingFrames
public void setMaxOutgoingFrames(int maxOutgoingFrames) Description copied from interface:Configurable
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 aWritePendingException
but the connection is not failed and will remain open.- Specified by:
setMaxOutgoingFrames
in interfaceConfigurable
- Parameters:
maxOutgoingFrames
- the max number of frames.
-
getProtocolVersion
Description copied from interface:Session
Returns the version of the WebSocket protocol currently being used.
This is taken as the value of the
Sec-WebSocket-Version
header used in theupgrade request
.- Specified by:
getProtocolVersion
in interfaceSession
- Returns:
- the WebSocket protocol version
-
isOpen
public boolean isOpen() -
isSecure
public boolean isSecure() -
disconnect
public void disconnect()Description copied from interface:Session
Abruptly closes the WebSocket connection without sending a CLOSE frame.
- Specified by:
disconnect
in interfaceSession
- See Also:
-
getLocalSocketAddress
- Specified by:
getLocalSocketAddress
in interfaceSession
- Returns:
- the local SocketAddress for the connection, if available
-
getRemoteSocketAddress
- Specified by:
getRemoteSocketAddress
in interfaceSession
- Returns:
- the remote SocketAddress for the connection, if available
-
getUpgradeRequest
- Specified by:
getUpgradeRequest
in interfaceSession
- Returns:
- the UpgradeRequest used to create this session
-
getUpgradeResponse
- Specified by:
getUpgradeResponse
in interfaceSession
- Returns:
- the UpgradeResponse used to create this session
-
getCoreSession
-
dump
Description copied from interface:Dumpable
Dump 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:
dump
in 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:Dumpable
The 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
-