Class WebSocketSession
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.websocket.common.WebSocketSession
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,org.eclipse.jetty.io.Connection.Listener
,org.eclipse.jetty.util.component.Container
,org.eclipse.jetty.util.component.Destroyable
,org.eclipse.jetty.util.component.Dumpable
,org.eclipse.jetty.util.component.Dumpable.DumpableContainer
,org.eclipse.jetty.util.component.LifeCycle
,IncomingFrames
,OutgoingFrames
,Session
,RemoteEndpointFactory
,WebSocketSessionScope
- Direct Known Subclasses:
JsrSession
@ManagedObject("A Jetty WebSocket Session") public class WebSocketSession extends org.eclipse.jetty.util.component.ContainerLifeCycle implements Session, RemoteEndpointFactory, WebSocketSessionScope, IncomingFrames, OutgoingFrames, org.eclipse.jetty.io.Connection.Listener
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.io.Connection.Listener
org.eclipse.jetty.io.Connection.Listener.Adapter
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ClassLoader
classLoader
private LogicalConnection
connection
private WebSocketContainerScope
containerScope
private static RemoteEndpointFactory
defaultRemoteEndpointFactory
private java.util.concurrent.Executor
executor
private ExtensionFactory
extensionFactory
private IncomingFrames
incomingHandler
private static org.eclipse.jetty.util.log.Logger
LOG
private java.util.concurrent.atomic.AtomicBoolean
onCloseCalled
private java.util.concurrent.CompletableFuture<Session>
openFuture
private OutgoingFrames
outgoingHandler
private java.util.Map<java.lang.String,java.lang.String[]>
parameterMap
private WebSocketPolicy
policy
private java.lang.String
protocolVersion
private RemoteEndpoint
remote
private RemoteEndpointFactory
remoteEndpointFactory
private java.net.URI
requestURI
private UpgradeRequest
upgradeRequest
private UpgradeResponse
upgradeResponse
private EventDriver
websocket
-
Constructor Summary
Constructors Constructor Description WebSocketSession(WebSocketContainerScope containerScope, java.net.URI requestURI, EventDriver websocket, LogicalConnection connection)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
callApplicationOnClose(CloseInfo closeInfo)
void
callApplicationOnError(java.lang.Throwable cause)
void
close()
Request a close of the current conversation with a normal status code and no reason phrase.void
close(int statusCode, java.lang.String reason)
Send a websocket Close frame, with status code.void
close(java.lang.Throwable cause)
Close the active session based on the throwablevoid
close(CloseStatus closeStatus)
Request Close the current conversation, giving a reason for the closure.private void
close(CloseInfo closeInfo, org.eclipse.jetty.util.Callback callback)
Close Primary Entry Point.void
disconnect()
Harsh disconnectvoid
dispatch(java.lang.Runnable runnable)
protected void
doStart()
protected void
doStop()
java.lang.String
dumpSelf()
BatchMode
getBatchMode()
org.eclipse.jetty.io.ByteBufferPool
getBufferPool()
java.lang.ClassLoader
getClassLoader()
LogicalConnection
getConnection()
WebSocketContainerScope
getContainerScope()
The parentWebSocketContainerScope
for this session scope.ExtensionFactory
getExtensionFactory()
long
getIdleTimeout()
The idle timeout in millisecondsIncomingFrames
getIncomingHandler()
java.net.InetSocketAddress
getLocalAddress()
Get the address of the local side.OutgoingFrames
getOutgoingHandler()
WebSocketPolicy
getPolicy()
Access the (now read-only)WebSocketPolicy
in use for this connection.java.lang.String
getProtocolVersion()
Returns the version of the websocket protocol currently being used.RemoteEndpoint
getRemote()
Return a reference to the RemoteEndpoint object representing the other end of this conversation.java.net.InetSocketAddress
getRemoteAddress()
Get the address of the remote side.java.net.URI
getRequestURI()
UpgradeRequest
getUpgradeRequest()
Get the UpgradeRequest used to create this sessionUpgradeResponse
getUpgradeResponse()
Get the UpgradeResponse used to create this sessionWebSocketSession
getWebSocketSession()
ActiveWebSocketSession
associated with this scope.void
incomingFrame(Frame frame)
Incoming Raw Frames from Parserboolean
isOpen()
Return true if and only if the underlying socket is open.boolean
isSecure()
Return true if and only if the underlying socket is using a secure transport.WebSocketRemoteEndpoint
newRemoteEndpoint(LogicalConnection connection, OutgoingFrames outgoingFrames, BatchMode batchMode)
private void
notifySessionListeners(WebSocketContainerScope scope, java.util.function.Consumer<WebSocketSessionListener> consumer)
void
onClosed(org.eclipse.jetty.io.Connection connection)
Jetty Connection onSessionClosed eventvoid
onOpened(org.eclipse.jetty.io.Connection connection)
Jetty Connection onOpen eventvoid
open()
Open/Activate the sessionvoid
outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode)
A frame, and optional callback, intended for the network layer.void
setExtensionFactory(ExtensionFactory extensionFactory)
void
setFuture(java.util.concurrent.CompletableFuture<Session> fut)
void
setIdleTimeout(long ms)
Set the timeout in millisecondsvoid
setOutgoingHandler(OutgoingFrames outgoing)
void
setPolicy(WebSocketPolicy policy)
Deprecated.void
setUpgradeRequest(UpgradeRequest request)
void
setUpgradeResponse(UpgradeResponse response)
SuspendToken
suspend()
Suspend the incoming read events on the connection.java.lang.String
toString()
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
-
-
-
Field Detail
-
LOG
private static final org.eclipse.jetty.util.log.Logger LOG
-
defaultRemoteEndpointFactory
private static final RemoteEndpointFactory defaultRemoteEndpointFactory
-
containerScope
private final WebSocketContainerScope containerScope
-
requestURI
private final java.net.URI requestURI
-
connection
private final LogicalConnection connection
-
websocket
private final EventDriver websocket
-
executor
private final java.util.concurrent.Executor executor
-
policy
private final WebSocketPolicy policy
-
onCloseCalled
private final java.util.concurrent.atomic.AtomicBoolean onCloseCalled
-
remoteEndpointFactory
private final RemoteEndpointFactory remoteEndpointFactory
-
classLoader
private final java.lang.ClassLoader classLoader
-
extensionFactory
private ExtensionFactory extensionFactory
-
protocolVersion
private java.lang.String protocolVersion
-
parameterMap
private final java.util.Map<java.lang.String,java.lang.String[]> parameterMap
-
remote
private RemoteEndpoint remote
-
incomingHandler
private final IncomingFrames incomingHandler
-
outgoingHandler
private OutgoingFrames outgoingHandler
-
upgradeRequest
private UpgradeRequest upgradeRequest
-
upgradeResponse
private UpgradeResponse upgradeResponse
-
openFuture
private java.util.concurrent.CompletableFuture<Session> openFuture
-
-
Constructor Detail
-
WebSocketSession
public WebSocketSession(WebSocketContainerScope containerScope, java.net.URI requestURI, EventDriver websocket, LogicalConnection connection)
-
-
Method Detail
-
close
public void close(java.lang.Throwable cause)
Close the active session based on the throwable- Parameters:
cause
- the cause for closing the connection
-
close
public void close()
Description copied from interface:Session
Request 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.
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceSession
- See Also:
Session.close(CloseStatus)
,Session.close(int, String)
,Session.disconnect()
-
close
public void close(CloseStatus closeStatus)
Description copied from interface:Session
Request 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.
- Specified by:
close
in interfaceSession
- Parameters:
closeStatus
- the reason for the closure- See Also:
Session.close()
,Session.close(int, String)
,Session.disconnect()
-
close
public void close(int statusCode, java.lang.String reason)
Description copied from interface:Session
Send a websocket Close frame, with status code.This will enqueue a graceful close to the remote endpoint.
- Specified by:
close
in interfaceSession
- Parameters:
statusCode
- the status codereason
- the (optional) reason. (can be null for no reason)- See Also:
StatusCode
,Session.close()
,Session.close(CloseStatus)
,Session.disconnect()
-
close
private void close(CloseInfo closeInfo, org.eclipse.jetty.util.Callback callback)
Close Primary Entry Point.- Parameters:
closeInfo
- the close details
-
disconnect
public void disconnect()
Harsh disconnect- Specified by:
disconnect
in interfaceSession
- See Also:
Session.close()
,Session.close(CloseStatus)
,Session.close(int, String)
,Session.disconnect()
-
dispatch
public void dispatch(java.lang.Runnable runnable)
-
doStart
protected void doStart() throws java.lang.Exception
- Overrides:
doStart
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.lang.Exception
-
doStop
protected void doStop() throws java.lang.Exception
- Overrides:
doStop
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.lang.Exception
-
dumpSelf
public java.lang.String dumpSelf()
- Specified by:
dumpSelf
in interfaceorg.eclipse.jetty.util.component.Dumpable
-
getBufferPool
public org.eclipse.jetty.io.ByteBufferPool getBufferPool()
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
-
getConnection
public LogicalConnection getConnection()
-
getContainerScope
public WebSocketContainerScope getContainerScope()
Description copied from interface:WebSocketSessionScope
The parentWebSocketContainerScope
for this session scope.- Specified by:
getContainerScope
in interfaceWebSocketSessionScope
- Returns:
- the websocket container scope
-
getExtensionFactory
public ExtensionFactory getExtensionFactory()
-
getIdleTimeout
public long getIdleTimeout()
The idle timeout in milliseconds- Specified by:
getIdleTimeout
in interfaceSession
- Returns:
- the timeout in milliseconds.
-
getIncomingHandler
@ManagedAttribute(readonly=true) public IncomingFrames getIncomingHandler()
-
getLocalAddress
public java.net.InetSocketAddress getLocalAddress()
Description copied from interface:Session
Get the address of the local side.- Specified by:
getLocalAddress
in interfaceSession
- Returns:
- the local side address
-
getOutgoingHandler
@ManagedAttribute(readonly=true) public OutgoingFrames getOutgoingHandler()
-
getPolicy
public WebSocketPolicy getPolicy()
Description copied from interface:Session
Access the (now read-only)WebSocketPolicy
in use for this connection.
-
getProtocolVersion
public java.lang.String 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 the opening handshake. i.e. "13".- Specified by:
getProtocolVersion
in interfaceSession
- Returns:
- the protocol version
-
getRemote
public RemoteEndpoint getRemote()
Description copied from interface:Session
Return a reference to the RemoteEndpoint object representing the other end of this conversation.
-
getRemoteAddress
public java.net.InetSocketAddress getRemoteAddress()
Description copied from interface:Session
Get the address of the remote side.- Specified by:
getRemoteAddress
in interfaceSession
- Returns:
- the remote side address
-
getRequestURI
public java.net.URI getRequestURI()
-
getUpgradeRequest
public UpgradeRequest getUpgradeRequest()
Description copied from interface:Session
Get the UpgradeRequest used to create this session- Specified by:
getUpgradeRequest
in interfaceSession
- Returns:
- the UpgradeRequest used to create this session
-
getUpgradeResponse
public UpgradeResponse getUpgradeResponse()
Description copied from interface:Session
Get the UpgradeResponse used to create this session- Specified by:
getUpgradeResponse
in interfaceSession
- Returns:
- the UpgradeResponse used to create this session
-
getWebSocketSession
public WebSocketSession getWebSocketSession()
Description copied from interface:WebSocketSessionScope
ActiveWebSocketSession
associated with this scope.- Specified by:
getWebSocketSession
in interfaceWebSocketSessionScope
- Returns:
- the websocket session
-
incomingFrame
public void incomingFrame(Frame frame)
Incoming Raw Frames from Parser- Specified by:
incomingFrame
in interfaceIncomingFrames
- Parameters:
frame
- the frame to process
-
outgoingFrame
public void outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode)
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:
outgoingFrame
in interfaceOutgoingFrames
- Parameters:
frame
- the frame to eventually write to the network layer.callback
- the callback to notify when the frame is written.batchMode
- the batch mode requested by the sender.
-
isOpen
public boolean isOpen()
Description copied from interface:Session
Return true if and only if the underlying socket is open.
-
isSecure
public boolean isSecure()
Description copied from interface:Session
Return true if and only if the underlying socket is using a secure transport.
-
callApplicationOnClose
public void callApplicationOnClose(CloseInfo closeInfo)
-
callApplicationOnError
public void callApplicationOnError(java.lang.Throwable cause)
-
onClosed
public void onClosed(org.eclipse.jetty.io.Connection connection)
Jetty Connection onSessionClosed event- Specified by:
onClosed
in interfaceorg.eclipse.jetty.io.Connection.Listener
- Parameters:
connection
- the connection that was closed
-
onOpened
public void onOpened(org.eclipse.jetty.io.Connection connection)
Jetty Connection onOpen event- Specified by:
onOpened
in interfaceorg.eclipse.jetty.io.Connection.Listener
- Parameters:
connection
- the connection that was opened
-
newRemoteEndpoint
public WebSocketRemoteEndpoint newRemoteEndpoint(LogicalConnection connection, OutgoingFrames outgoingFrames, BatchMode batchMode)
- Specified by:
newRemoteEndpoint
in interfaceRemoteEndpointFactory
-
open
public void open()
Open/Activate the session
-
setExtensionFactory
public void setExtensionFactory(ExtensionFactory extensionFactory)
-
setFuture
public void setFuture(java.util.concurrent.CompletableFuture<Session> fut)
-
setIdleTimeout
public void setIdleTimeout(long ms)
Set the timeout in milliseconds- Specified by:
setIdleTimeout
in interfaceSession
- Parameters:
ms
- the number of milliseconds.
-
setOutgoingHandler
public void setOutgoingHandler(OutgoingFrames outgoing)
-
setPolicy
@Deprecated public void setPolicy(WebSocketPolicy policy)
Deprecated.
-
setUpgradeRequest
public void setUpgradeRequest(UpgradeRequest request)
-
setUpgradeResponse
public void setUpgradeResponse(UpgradeResponse response)
-
suspend
public SuspendToken suspend()
Description copied from interface:Session
Suspend the incoming read events on the connection.
-
getBatchMode
public BatchMode getBatchMode()
- Returns:
- the default (initial) value for the batching mode.
-
notifySessionListeners
private void notifySessionListeners(WebSocketContainerScope scope, java.util.function.Consumer<WebSocketSessionListener> consumer)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classorg.eclipse.jetty.util.component.AbstractLifeCycle
-
-