Top Fields Constructors Methods
org.eclipse.jetty.websocket.common

public Class WebSocketSession

extends Object
implements Session, Dumpable
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.websocket.api.Session, java.io.Closeable, java.lang.AutoCloseable, org.eclipse.jetty.websocket.api.Configurable
Imports
java.io.IOException, java.net.SocketAddress, java.nio.ByteBuffer, java.time.Duration, java.util.Objects, org.eclipse.jetty.util.BufferUtil, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.websocket.api.Callback, .Session, .UpgradeRequest, .UpgradeResponse, .WebSocketContainer, org.eclipse.jetty.websocket.core.CoreSession, .Frame, .OpCode, org.eclipse.jetty.websocket.core.exception.ProtocolException

Field Summary

Modifier and TypeField and Description
private final CoreSession
private final JettyWebSocketFrameHandler
private byte
private final UpgradeRequest
private final UpgradeResponse

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close(int
the status code
statusCode
,
String
the (optional) reason
reason
,
Callback
callback to notify when the send operation is complete
callback
)

Implements org.eclipse.jetty.websocket.api.Session.close.

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.

public void
demand()

Implements org.eclipse.jetty.websocket.api.Session.demand.

Explicitly demands for WebSocket events.

public void
disconnect()

Implements org.eclipse.jetty.websocket.api.Session.disconnect.

Abruptly closes the WebSocket connection without sending a CLOSE frame.

public void
dump(Appendable
The appendable to dump to
out
,
String
The indent to apply after any new lines.
indent
)

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines.

public String
dumpSelf()

Overrides default org.eclipse.jetty.util.component.Dumpable.dumpSelf.

The description of this/self found in the dump.

public CoreSession
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 SocketAddress
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 int
getOutputBufferSize()

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

The output (write to network layer) buffer size.

public String
getProtocolVersion()

Implements org.eclipse.jetty.websocket.api.Session.getProtocolVersion.

Returns the version of the WebSocket protocol currently being used.

public SocketAddress
public UpgradeRequest
public UpgradeResponse
public boolean
isAutoFragment()

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

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

public boolean
public boolean
public void
sendBinary(ByteBuffer
the message bytes to send
buffer
,
Callback
callback to notify when the send operation is complete
callback
)

Implements org.eclipse.jetty.websocket.api.Session.sendBinary.

Initiates the asynchronous send of a BINARY message, notifying the given callback when the message send is completed, either successfully or with a failure.

public void
sendPartialBinary(ByteBuffer
the frame bytes to send
buffer
,
boolean
whether this is the last frame of the message
last
,
Callback
callback to notify when the send operation is complete
callback
)

Implements org.eclipse.jetty.websocket.api.Session.sendPartialBinary.

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.

public void
sendPartialText(String
the frame text to send
text
,
boolean
whether this is the last frame of the message
last
,
Callback
callback to notify when the send operation is complete
callback
)

Implements org.eclipse.jetty.websocket.api.Session.sendPartialText.

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.

public void
sendPing(ByteBuffer
the data to be carried in the PING frame
applicationData
,
Callback
callback to notify when the send operation is complete
callback
)

Implements org.eclipse.jetty.websocket.api.Session.sendPing.

Initiates the asynchronous send of a PING frame, notifying the given callback when the frame send is completed, either successfully or with a failure.

public void
sendPong(ByteBuffer
the data to be carried in the PONG frame
applicationData
,
Callback
callback to notify when the send operation is complete
callback
)

Implements org.eclipse.jetty.websocket.api.Session.sendPong.

Initiates the asynchronous send of a PONG frame, notifying the given callback when the frame send is completed, either successfully or with a failure.

public void
sendText(String
the message text to send
text
,
Callback
callback to notify when the send operation is complete
callback
)

Implements org.eclipse.jetty.websocket.api.Session.sendText.

Initiates the asynchronous send of a TEXT message, notifying the given callback when the message send is completed, either successfully or with a failure.

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
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 String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

coreSessionback to summary
private final CoreSession coreSession
frameHandlerback to summary
private final JettyWebSocketFrameHandler frameHandler
messageTypeback to summary
private byte messageType
upgradeRequestback to summary
private final UpgradeRequest upgradeRequest
upgradeResponseback to summary
private final UpgradeResponse upgradeResponse

Constructor Detail

WebSocketSessionback to summary
public WebSocketSession(WebSocketContainer container, CoreSession coreSession, JettyWebSocketFrameHandler frameHandler)

Method Detail

closeback to summary
public void close(int statusCode, String reason, Callback callback)

Implements org.eclipse.jetty.websocket.api.Session.close.

Doc from org.eclipse.jetty.websocket.api.Session.close.

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.

Parameters
statusCode:int

the status code

reason:String

the (optional) reason

callback:Callback

callback to notify when the send operation is complete

Annotations
@Override
demandback to summary
public void demand()

Implements org.eclipse.jetty.websocket.api.Session.demand.

Doc from org.eclipse.jetty.websocket.api.Session.demand.

Explicitly demands for WebSocket events.

This method should be called only when the WebSocket endpoint is not demanding automatically, as defined by WebSocket#autoDemand() and 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 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 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.

Annotations
@Override
disconnectback to summary
public void disconnect()

Implements org.eclipse.jetty.websocket.api.Session.disconnect.

Doc from org.eclipse.jetty.websocket.api.Session.disconnect.

Abruptly closes the WebSocket connection without sending a CLOSE frame.

Annotations
@Override
dumpback to summary
public void dump(Appendable out, String indent) throws IOException

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Doc from org.eclipse.jetty.util.component.Dumpable.dump.

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.

Parameters
out:Appendable

The appendable to dump to

indent:String

The indent to apply after any new lines.

Annotations
@Override
Exceptions
IOException:
if unable to write to Appendable
dumpSelfback to summary
public String dumpSelf()

Overrides default org.eclipse.jetty.util.component.Dumpable.dumpSelf.

Doc from org.eclipse.jetty.util.component.Dumpable.dumpSelf.

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.

Returns:String

the representation of self

Annotations
@Override
getCoreSessionback to summary
public CoreSession getCoreSession()
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
getLocalSocketAddressback to summary
public SocketAddress getLocalSocketAddress()

Implements org.eclipse.jetty.websocket.api.Session.getLocalSocketAddress.

Returns:SocketAddress

Doc from org.eclipse.jetty.websocket.api.Session.getLocalSocketAddress.

the local SocketAddress for the connection, if available

Annotations
@Override
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
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
getProtocolVersionback to summary
public String getProtocolVersion()

Implements org.eclipse.jetty.websocket.api.Session.getProtocolVersion.

Doc from org.eclipse.jetty.websocket.api.Session.getProtocolVersion.

Returns the version of the WebSocket protocol currently being used.

This is taken as the value of the Sec-WebSocket-Version header used in the upgrade request.

Returns:String

the WebSocket protocol version

Annotations
@Override
getRemoteSocketAddressback to summary
public SocketAddress getRemoteSocketAddress()

Implements org.eclipse.jetty.websocket.api.Session.getRemoteSocketAddress.

Returns:SocketAddress

Doc from org.eclipse.jetty.websocket.api.Session.getRemoteSocketAddress.

the remote SocketAddress for the connection, if available

Annotations
@Override
getUpgradeRequestback to summary
public UpgradeRequest getUpgradeRequest()

Implements org.eclipse.jetty.websocket.api.Session.getUpgradeRequest.

Returns:UpgradeRequest

Doc from org.eclipse.jetty.websocket.api.Session.getUpgradeRequest.

the UpgradeRequest used to create this session

Annotations
@Override
getUpgradeResponseback to summary
public UpgradeResponse getUpgradeResponse()

Implements org.eclipse.jetty.websocket.api.Session.getUpgradeResponse.

Returns:UpgradeResponse

Doc from org.eclipse.jetty.websocket.api.Session.getUpgradeResponse.

the UpgradeResponse used to create this session

Annotations
@Override
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
isOpenback to summary
public boolean isOpen()

Implements org.eclipse.jetty.websocket.api.Session.isOpen.

Returns:boolean

Doc from org.eclipse.jetty.websocket.api.Session.isOpen.

whether the session is open

Annotations
@Override
isSecureback to summary
public boolean isSecure()

Implements org.eclipse.jetty.websocket.api.Session.isSecure.

Returns:boolean

Doc from org.eclipse.jetty.websocket.api.Session.isSecure.

whether the underlying socket is using a secure transport

Annotations
@Override
sendBinaryback to summary
public void sendBinary(ByteBuffer buffer, Callback callback)

Implements org.eclipse.jetty.websocket.api.Session.sendBinary.

Doc from org.eclipse.jetty.websocket.api.Session.sendBinary.

Initiates the asynchronous send of a BINARY message, notifying the given callback when the message send is completed, either successfully or with a failure.

Parameters
buffer:ByteBuffer

the message bytes to send

callback:Callback

callback to notify when the send operation is complete

Annotations
@Override
sendPartialBinaryback to summary
public void sendPartialBinary(ByteBuffer buffer, boolean last, Callback callback)

Implements org.eclipse.jetty.websocket.api.Session.sendPartialBinary.

Doc from org.eclipse.jetty.websocket.api.Session.sendPartialBinary.

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 with last=true.

Parameters
buffer:ByteBuffer

the frame bytes to send

last:boolean

whether this is the last frame of the message

callback:Callback

callback to notify when the send operation is complete

Annotations
@Override
sendPartialTextback to summary
public void sendPartialText(String text, boolean last, Callback callback)

Implements org.eclipse.jetty.websocket.api.Session.sendPartialText.

Doc from org.eclipse.jetty.websocket.api.Session.sendPartialText.

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 with last=true.

Parameters
text:String

the frame text to send

last:boolean

whether this is the last frame of the message

callback:Callback

callback to notify when the send operation is complete

Annotations
@Override
sendPingback to summary
public void sendPing(ByteBuffer applicationData, Callback callback)

Implements org.eclipse.jetty.websocket.api.Session.sendPing.

Doc from org.eclipse.jetty.websocket.api.Session.sendPing.

Initiates the asynchronous send of a PING frame, notifying the given callback when the frame send is completed, either successfully or with a failure.

Parameters
applicationData:ByteBuffer

the data to be carried in the PING frame

callback:Callback

callback to notify when the send operation is complete

Annotations
@Override
sendPongback to summary
public void sendPong(ByteBuffer applicationData, Callback callback)

Implements org.eclipse.jetty.websocket.api.Session.sendPong.

Doc from org.eclipse.jetty.websocket.api.Session.sendPong.

Initiates the asynchronous send of a PONG frame, notifying the given callback when the frame send is completed, either successfully or with a failure.

Parameters
applicationData:ByteBuffer

the data to be carried in the PONG frame

callback:Callback

callback to notify when the send operation is complete

Annotations
@Override
sendTextback to summary
public void sendText(String text, Callback callback)

Implements org.eclipse.jetty.websocket.api.Session.sendText.

Doc from org.eclipse.jetty.websocket.api.Session.sendText.

Initiates the asynchronous send of a TEXT message, notifying the given callback when the message send is completed, either successfully or with a failure.

Parameters
text:String

the message text to send

callback:Callback

callback to notify when the send operation is complete

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
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
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override