@ManagedObject(value="A Jetty WebSocket Session") public class WebSocketSession extends ContainerLifeCycle implements Session, RemoteEndpointFactory, WebSocketSessionScope, IncomingFrames, Connection.Listener
AbstractLifeCycle.AbstractLifeCycleListener
Connection.Listener.Adapter
Container.InheritedListener, Container.Listener
LifeCycle.Listener
Modifier and Type | Field and Description |
---|---|
private java.lang.ClassLoader |
classLoader |
private java.util.concurrent.atomic.AtomicBoolean |
closed |
private LogicalConnection |
connection |
private WebSocketContainerScope |
containerScope |
private java.util.concurrent.Executor |
executor |
private ExtensionFactory |
extensionFactory |
private IncomingFrames |
incomingHandler |
private static 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 and Description |
---|
WebSocketSession(WebSocketContainerScope containerScope,
java.net.URI requestURI,
EventDriver websocket,
LogicalConnection connection) |
Modifier and Type | Method and 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.
|
private void |
close(CloseInfo closeInfo,
Callback callback)
Close Primary Entry Point.
|
void |
close(CloseStatus closeStatus)
Request Close the current conversation, giving a reason for the closure.
|
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 throwable
|
void |
disconnect()
Harsh disconnect
|
void |
dispatch(java.lang.Runnable runnable) |
protected void |
doStart()
Starts the managed lifecycle beans in the order they were added.
|
protected void |
doStop()
Stops the managed lifecycle beans in the reverse order they were added.
|
java.lang.String |
dumpSelf()
The description of this/self found in the dump.
|
BatchMode |
getBatchMode() |
ByteBufferPool |
getBufferPool() |
java.lang.ClassLoader |
getClassLoader() |
LogicalConnection |
getConnection() |
WebSocketContainerScope |
getContainerScope()
The parent
WebSocketContainerScope for this session scope. |
ExtensionFactory |
getExtensionFactory() |
long |
getIdleTimeout()
The idle timeout in milliseconds
|
IncomingFrames |
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 session
|
UpgradeResponse |
getUpgradeResponse()
Get the UpgradeResponse used to create this session
|
WebSocketSession |
getWebSocketSession()
Active
WebSocketSession associated with this scope. |
void |
incomingFrame(Frame frame)
Incoming Raw Frames from Parser
|
boolean |
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(Connection connection)
Jetty Connection onSessionClosed event
|
void |
onOpened(Connection connection)
Jetty Connection onOpen event
|
void |
open()
Open/Activate the session
|
void |
setExtensionFactory(ExtensionFactory extensionFactory) |
void |
setFuture(java.util.concurrent.CompletableFuture<Session> fut) |
void |
setIdleTimeout(long ms)
Set the timeout in milliseconds
|
void |
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() |
addBean, 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
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
dumpObjects
private static final Logger LOG
private final WebSocketContainerScope containerScope
private final java.net.URI requestURI
private final LogicalConnection connection
private final EventDriver websocket
private final java.util.concurrent.Executor executor
private final WebSocketPolicy policy
private final java.util.concurrent.atomic.AtomicBoolean closed
private java.lang.ClassLoader classLoader
private ExtensionFactory extensionFactory
private RemoteEndpointFactory remoteEndpointFactory
private java.lang.String protocolVersion
private java.util.Map<java.lang.String,java.lang.String[]> parameterMap
private RemoteEndpoint remote
private IncomingFrames incomingHandler
private OutgoingFrames outgoingHandler
private UpgradeRequest upgradeRequest
private UpgradeResponse upgradeResponse
private java.util.concurrent.CompletableFuture<Session> openFuture
private java.util.concurrent.atomic.AtomicBoolean onCloseCalled
public WebSocketSession(WebSocketContainerScope containerScope, java.net.URI requestURI, EventDriver websocket, LogicalConnection connection)
public void close(java.lang.Throwable cause)
cause
- the cause for closing the connectionpublic void close()
Session
This will enqueue a graceful close to the remote endpoint.
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface Session
Session.close(CloseStatus)
,
Session.close(int, String)
,
Session.disconnect()
public void close(CloseStatus closeStatus)
Session
This will enqueue a graceful close to the remote endpoint.
close
in interface Session
closeStatus
- the reason for the closureSession.close()
,
Session.close(int, String)
,
Session.disconnect()
public void close(int statusCode, java.lang.String reason)
Session
This will enqueue a graceful close to the remote endpoint.
close
in interface Session
statusCode
- the status codereason
- the (optional) reason. (can be null for no reason)StatusCode
,
Session.close()
,
Session.close(CloseStatus)
,
Session.disconnect()
private void close(CloseInfo closeInfo, Callback callback)
closeInfo
- the close detailspublic void disconnect()
disconnect
in interface Session
Session.close()
,
Session.close(CloseStatus)
,
Session.close(int, String)
,
Session.disconnect()
public void dispatch(java.lang.Runnable runnable)
protected void doStart() throws java.lang.Exception
ContainerLifeCycle
doStart
in class ContainerLifeCycle
java.lang.Exception
protected void doStop() throws java.lang.Exception
ContainerLifeCycle
doStop
in class ContainerLifeCycle
java.lang.Exception
public java.lang.String dumpSelf()
Dumpable
public ByteBufferPool getBufferPool()
public java.lang.ClassLoader getClassLoader()
public LogicalConnection getConnection()
public WebSocketContainerScope getContainerScope()
WebSocketSessionScope
WebSocketContainerScope
for this session scope.getContainerScope
in interface WebSocketSessionScope
public ExtensionFactory getExtensionFactory()
public long getIdleTimeout()
getIdleTimeout
in interface Session
@ManagedAttribute(readonly=true) public IncomingFrames getIncomingHandler()
public java.net.InetSocketAddress getLocalAddress()
Session
getLocalAddress
in interface Session
@ManagedAttribute(readonly=true) public OutgoingFrames getOutgoingHandler()
public WebSocketPolicy getPolicy()
Session
WebSocketPolicy
in use for this connection.public java.lang.String getProtocolVersion()
Session
getProtocolVersion
in interface Session
public RemoteEndpoint getRemote()
Session
public java.net.InetSocketAddress getRemoteAddress()
Session
getRemoteAddress
in interface Session
public java.net.URI getRequestURI()
public UpgradeRequest getUpgradeRequest()
Session
getUpgradeRequest
in interface Session
public UpgradeResponse getUpgradeResponse()
Session
getUpgradeResponse
in interface Session
public WebSocketSession getWebSocketSession()
WebSocketSessionScope
WebSocketSession
associated with this scope.getWebSocketSession
in interface WebSocketSessionScope
public void incomingFrame(Frame frame)
incomingFrame
in interface IncomingFrames
frame
- the frame to processpublic boolean isOpen()
Session
public boolean isSecure()
Session
public void callApplicationOnClose(CloseInfo closeInfo)
public void callApplicationOnError(java.lang.Throwable cause)
public void onClosed(Connection connection)
onClosed
in interface Connection.Listener
connection
- the connection that was closedpublic void onOpened(Connection connection)
onOpened
in interface Connection.Listener
connection
- the connection that was openedpublic WebSocketRemoteEndpoint newRemoteEndpoint(LogicalConnection connection, OutgoingFrames outgoingFrames, BatchMode batchMode)
newRemoteEndpoint
in interface RemoteEndpointFactory
public void open()
public void setExtensionFactory(ExtensionFactory extensionFactory)
public void setFuture(java.util.concurrent.CompletableFuture<Session> fut)
public void setIdleTimeout(long ms)
setIdleTimeout
in interface Session
ms
- the number of milliseconds.public void setOutgoingHandler(OutgoingFrames outgoing)
@Deprecated public void setPolicy(WebSocketPolicy policy)
public void setUpgradeRequest(UpgradeRequest request)
public void setUpgradeResponse(UpgradeResponse response)
public SuspendToken suspend()
Session
public BatchMode getBatchMode()
private void notifySessionListeners(WebSocketContainerScope scope, java.util.function.Consumer<WebSocketSessionListener> consumer)
public java.lang.String toString()
toString
in class AbstractLifeCycle