Class WebSocketCoreSession
- All Implemented Interfaces:
Dumpable
,Configuration
,CoreSession
,IncomingFrames
,OutgoingFrames
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.websocket.core.Configuration
Configuration.ConfigurationCustomizer, Configuration.Customizer
Nested classes/interfaces inherited from interface org.eclipse.jetty.websocket.core.CoreSession
CoreSession.Empty
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Field Summary
-
Constructor Summary
ConstructorDescriptionWebSocketCoreSession
(FrameHandler handler, Behavior behavior, Negotiated negotiated, WebSocketComponents components) -
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
Issue a harsh abort of the underlying connection.void
void
Send Close Frame with specified Status Code and optional Reasonvoid
Send Close Frame with no payload.void
demand
(long n) Manage flow control by indicating demand for handling Frames.dump()
void
dump
(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.void
If using BatchMode.ON or BatchMode.AUTO, trigger a flush of enqueued / batched frames.Get the Idle Timeoutint
The Local Socket Address for the connectionlong
long
int
Get the maximum number of data frames allowed to be waiting to be sent at any one time.long
The negotiated WebSocket Extension Configurations for this session.The negotiated WebSocket Sub-Protocol for this session.int
The parameter map (from URI Query) for the active session.The activeSec-WebSocket-Version
(protocol version) in use.The Remote Socket Address for the connectionThe active connection's Request URI.Get the Write Timeoutprotected void
Can be overridden to scope into the correct classloader before calling application code.boolean
boolean
isClosed()
boolean
boolean
boolean
boolean
boolean
boolean
boolean
isSecure()
The active connection's Secure status indicator.void
onEof()
void
Process the incoming frame.void
onOpen()
Open/Activate the session.void
processConnectionError
(Throwable cause, Callback callback) Process an Error that originated from the connection.void
processHandlerError
(Throwable cause, Callback callback) Process an Error that originated from the handler.void
A frame, and optional callback, intended for the network layer.void
setAutoFragment
(boolean autoFragment) void
setClassLoader
(ClassLoader classLoader) void
setIdleTimeout
(Duration timeout) Set the Idle Timeout.void
setInputBufferSize
(int inputBufferSize) void
setMaxBinaryMessageSize
(long maxSize) void
setMaxFrameSize
(long maxFrameSize) 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 maxSize) void
setOutputBufferSize
(int outputBufferSize) void
setWebSocketConnection
(WebSocketConnection connection) void
setWriteTimeout
(Duration timeout) Set the Write Timeout.toString()
-
Constructor Details
-
WebSocketCoreSession
public WebSocketCoreSession(FrameHandler handler, Behavior behavior, Negotiated negotiated, WebSocketComponents components)
-
-
Method Details
-
getClassLoader
-
setClassLoader
-
handle
Can be overridden to scope into the correct classloader before calling application code.- Parameters:
runnable
- the runnable to execute.
-
isDemanding
public boolean isDemanding()- Returns:
- True if the sessions handling is demanding.
-
getExtensionStack
-
getHandler
-
getNegotiatedSubProtocol
Description copied from interface:CoreSession
The negotiated WebSocket Sub-Protocol for this session.- Specified by:
getNegotiatedSubProtocol
in interfaceCoreSession
- Returns:
- the negotiated WebSocket Sub-Protocol for this session.
-
getIdleTimeout
Description copied from interface:Configuration
Get the Idle Timeout- Specified by:
getIdleTimeout
in interfaceConfiguration
- Returns:
- the idle timeout
-
setIdleTimeout
Description copied from interface:Configuration
Set the Idle Timeout.- Specified by:
setIdleTimeout
in interfaceConfiguration
- Parameters:
timeout
- the timeout duration (timeout <= 0 implies an infinite timeout)
-
getWriteTimeout
Description copied from interface:Configuration
Get the Write Timeout- Specified by:
getWriteTimeout
in interfaceConfiguration
- Returns:
- the write timeout
-
setWriteTimeout
Description copied from interface:Configuration
Set the Write Timeout.- Specified by:
setWriteTimeout
in interfaceConfiguration
- Parameters:
timeout
- the timeout duration (timeout <= 0 implies an infinite timeout)
-
getLocalAddress
Description copied from interface:CoreSession
The Local Socket Address for the connectionDo not assume that this will return a
InetSocketAddress
in all cases. Use of various proxies, and even UnixSockets can result a SocketAddress being returned without supportingInetSocketAddress
- Specified by:
getLocalAddress
in interfaceCoreSession
- Returns:
- the SocketAddress for the local connection, or null if not supported by Session
-
getRemoteAddress
Description copied from interface:CoreSession
The Remote Socket Address for the connectionDo not assume that this will return a
InetSocketAddress
in all cases. Use of various proxies, and even UnixSockets can result a SocketAddress being returned without supportingInetSocketAddress
- Specified by:
getRemoteAddress
in interfaceCoreSession
- Returns:
- the SocketAddress for the remote connection, or null if not supported by Session
-
isInputOpen
public boolean isInputOpen()- Specified by:
isInputOpen
in interfaceCoreSession
- Returns:
- True if the websocket is open inbound
-
isOutputOpen
public boolean isOutputOpen()- Specified by:
isOutputOpen
in interfaceCoreSession
- Returns:
- True if the websocket is open outbound
-
isClosed
public boolean isClosed() -
setWebSocketConnection
-
close
Send Close Frame with no payload.- Specified by:
close
in interfaceCoreSession
- Parameters:
callback
- the callback on successful send of close frame
-
close
Send Close Frame with specified Status Code and optional Reason- Specified by:
close
in interfaceCoreSession
- Parameters:
statusCode
- a valid WebSocket status codereason
- an optional reason phrasecallback
- the callback on successful send of close frame
-
getByteBufferPool
- Specified by:
getByteBufferPool
in interfaceCoreSession
- Returns:
- The shared ByteBufferPool
-
onEof
public void onEof() -
processConnectionError
Process an Error that originated from the connection. For protocol causes, send and abnormal close frame otherwise just close the connection.- Parameters:
cause
- the causecallback
- the callback on completion of error handling
-
processHandlerError
Process an Error that originated from the handler. Send an abnormal close frame to ensure connection is closed.- Parameters:
cause
- the causecallback
- the callback on completion of error handling
-
onOpen
public void onOpen()Open/Activate the session. -
demand
public void demand(long n) Description copied from interface:CoreSession
Manage flow control by indicating demand for handling Frames. A call toFrameHandler.onFrame(Frame, Callback)
will only be made if a corresponding demand has been signaled. It is an error to call this method ifFrameHandler.isDemanding()
returns false.- Specified by:
demand
in interfaceCoreSession
- Parameters:
n
- The number of frames that can be handled (in sequential calls toFrameHandler.onFrame(Frame, Callback)
). May not be negative.
-
autoDemand
public void autoDemand() -
isRsv1Used
public boolean isRsv1Used()- Specified by:
isRsv1Used
in interfaceCoreSession
- Returns:
- true if an extension has been negotiated which uses the RSV1 bit.
-
isRsv2Used
public boolean isRsv2Used()- Specified by:
isRsv2Used
in interfaceCoreSession
- Returns:
- true if an extension has been negotiated which uses the RSV2 bit.
-
isRsv3Used
public boolean isRsv3Used()- Specified by:
isRsv3Used
in interfaceCoreSession
- Returns:
- true if an extension has been negotiated which uses the RSV3 bit.
-
getConnection
-
getExecutor
-
onFrame
Description copied from interface:IncomingFrames
Process the incoming frame.
Note: if you need to hang onto any information from the frame, be sure to copy it, as the information contained in the Frame will be released and/or reused by the implementation.
Failure of the callback will propagate the failure back to the
CoreSession
to fail the connection and attempt to send a closeFrame
if one has not been sent.- Specified by:
onFrame
in interfaceIncomingFrames
- Parameters:
frame
- the frame to process.callback
- the read completion.
-
sendFrame
Description copied from interface:OutgoingFrames
A frame, and optional callback, intended for the network layer.Note: the frame can undergo many transformations in the various layers and extensions present in the implementation.
If you are implementing a mutation, you are obliged to handle the incoming WriteCallback appropriately.
- Specified by:
sendFrame
in interfaceOutgoingFrames
- Parameters:
frame
- the frame to eventually write to the network layer.callback
- the callback to notify when the frame is written.batch
- the batch mode requested by the sender.
-
flush
Description copied from interface:CoreSession
If using BatchMode.ON or BatchMode.AUTO, trigger a flush of enqueued / batched frames.- Specified by:
flush
in interfaceCoreSession
- Parameters:
callback
- the callback to track close frame sent (or failed)
-
abort
public void abort()Description copied from interface:CoreSession
Issue a harsh abort of the underlying connection.This will terminate the connection, without sending a websocket close frame. No WebSocket Protocol close handshake will be performed.
Once called, any read/write activity on the websocket from this point will be indeterminate. This can result in the
FrameHandler.onError(Throwable, Callback)
event being called indicating any issue that arises.Once the underlying connection has been determined to be closed, the
FrameHandler.onClosed(CloseStatus, Callback)
event will be called.- Specified by:
abort
in interfaceCoreSession
-
isAutoFragment
public boolean isAutoFragment()- Specified by:
isAutoFragment
in interfaceConfiguration
-
setAutoFragment
public void setAutoFragment(boolean autoFragment) - Specified by:
setAutoFragment
in interfaceConfiguration
-
getMaxFrameSize
public long getMaxFrameSize()- Specified by:
getMaxFrameSize
in interfaceConfiguration
-
setMaxFrameSize
public void setMaxFrameSize(long maxFrameSize) - Specified by:
setMaxFrameSize
in interfaceConfiguration
-
getOutputBufferSize
public int getOutputBufferSize()- Specified by:
getOutputBufferSize
in interfaceConfiguration
-
setOutputBufferSize
public void setOutputBufferSize(int outputBufferSize) - Specified by:
setOutputBufferSize
in interfaceConfiguration
-
getInputBufferSize
public int getInputBufferSize()- Specified by:
getInputBufferSize
in interfaceConfiguration
-
setInputBufferSize
public void setInputBufferSize(int inputBufferSize) - Specified by:
setInputBufferSize
in interfaceConfiguration
-
getMaxBinaryMessageSize
public long getMaxBinaryMessageSize()- Specified by:
getMaxBinaryMessageSize
in interfaceConfiguration
-
setMaxBinaryMessageSize
public void setMaxBinaryMessageSize(long maxSize) - Specified by:
setMaxBinaryMessageSize
in interfaceConfiguration
-
getMaxTextMessageSize
public long getMaxTextMessageSize()- Specified by:
getMaxTextMessageSize
in interfaceConfiguration
-
setMaxTextMessageSize
public void setMaxTextMessageSize(long maxSize) - Specified by:
setMaxTextMessageSize
in interfaceConfiguration
-
getMaxOutgoingFrames
public int getMaxOutgoingFrames()Description copied from interface:Configuration
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 interfaceConfiguration
- Returns:
- the max number of frames.
-
setMaxOutgoingFrames
public void setMaxOutgoingFrames(int maxOutgoingFrames) Description copied from interface:Configuration
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 interfaceConfiguration
- Parameters:
maxOutgoingFrames
- the max number of frames.
-
dump
-
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
-
getNegotiatedExtensions
Description copied from interface:CoreSession
The negotiated WebSocket Extension Configurations for this session.- Specified by:
getNegotiatedExtensions
in interfaceCoreSession
- Returns:
- the list of Negotiated Extension Configurations for this session.
-
getParameterMap
Description copied from interface:CoreSession
The parameter map (from URI Query) for the active session.- Specified by:
getParameterMap
in interfaceCoreSession
- Returns:
- the immutable map of parameters
-
getProtocolVersion
Description copied from interface:CoreSession
The activeSec-WebSocket-Version
(protocol version) in use.- Specified by:
getProtocolVersion
in interfaceCoreSession
- Returns:
- the protocol version in use.
-
getRequestURI
Description copied from interface:CoreSession
The active connection's Request URI. This is the URI of the upgrade request and is typically http: or https: rather than the ws: or wss: scheme.- Specified by:
getRequestURI
in interfaceCoreSession
- Returns:
- the absolute URI (including Query string)
-
isSecure
public boolean isSecure()Description copied from interface:CoreSession
The active connection's Secure status indicator.- Specified by:
isSecure
in interfaceCoreSession
- Returns:
- true if connection is secure (similar in role to
HttpServletRequest.isSecure()
)
-
getBehavior
- Specified by:
getBehavior
in interfaceCoreSession
- Returns:
- Client or Server behaviour
-
getWebSocketComponents
- Specified by:
getWebSocketComponents
in interfaceCoreSession
- Returns:
- the WebSocketComponents instance in use for this Connection.
-
toString
-