Class WebSocketConnection
java.lang.Object
org.eclipse.jetty.io.AbstractConnection
org.eclipse.jetty.websocket.core.internal.WebSocketConnection
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Runnable
,Connection
,Connection.UpgradeTo
,Dumpable
public class WebSocketConnection
extends AbstractConnection
implements Connection.UpgradeTo, Dumpable, Runnable
Provides the implementation of
Connection
that is suitable for WebSocket-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.io.Connection
Connection.Listener, Connection.UpgradeFrom, Connection.UpgradeTo
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Field Summary
-
Constructor Summary
ConstructorDescriptionWebSocketConnection
(EndPoint endp, Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, RetainableByteBufferPool retainableByteBufferPool, WebSocketCoreSession coreSession) Create a WSConnection.WebSocketConnection
(EndPoint endp, Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, RetainableByteBufferPool retainableByteBufferPool, WebSocketCoreSession coreSession, Random randomMask) Create a WSConnection. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
demand
(long n) dump()
void
dump
(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.long
long
Deprecated.long
long
Deprecated.usegetRemoteSocketAddress()
insteadboolean
boolean
boolean
boolean
void
Physical connection disconnect.void
Callback method invoked when the endpoint is ready to be read.protected void
onFrame
(Parser.ParsedFrame frame) boolean
Callback method invoked upon an idle timeout event.void
onOpen()
Physical connection Open.protected boolean
onReadTimeout
(Throwable timeout) Event for no activity on connection (read or write)void
onUpgradeTo
(ByteBuffer buffer) Extra bytes from the initial HTTP upgrade that need to be processed by the websocket parser before starting to read bytes from the connectionvoid
run()
protected void
setInitialBuffer
(ByteBuffer initialBuffer) Extra bytes from the initial HTTP upgrade that need to be processed by the websocket parser before starting to read bytes from the connectionvoid
setInputBufferSize
(int inputBufferSize) void
setUseInputDirectByteBuffers
(boolean useInputDirectByteBuffers) void
setUseOutputDirectByteBuffers
(boolean useOutputDirectByteBuffers) Methods inherited from class org.eclipse.jetty.io.AbstractConnection
addEventListener, close, failedCallback, fillInterested, getCreatedTimeStamp, getEndPoint, getInputBufferSize, isFillInterested, onFillInterestedFailed, removeEventListener, toString, tryFillInterested
-
Constructor Details
-
WebSocketConnection
public WebSocketConnection(EndPoint endp, Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, RetainableByteBufferPool retainableByteBufferPool, WebSocketCoreSession coreSession) Create a WSConnection.It is assumed that the WebSocket Upgrade Handshake has already completed successfully before creating this connection.
-
WebSocketConnection
public WebSocketConnection(EndPoint endp, Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, RetainableByteBufferPool retainableByteBufferPool, WebSocketCoreSession coreSession, Random randomMask) Create a WSConnection.It is assumed that the WebSocket Upgrade Handshake has already completed successfully before creating this connection.
- Parameters:
endp
- The endpoint ever which Websockot is sent/receivedexecutor
- A thread executor to use for WS callbacks.scheduler
- A scheduler to use for timeoutsbufferPool
- A pool of buffers to use.retainableByteBufferPool
- A pool of retainable buffers to use.coreSession
- The WC core session to which frames are delivered.randomMask
- A Random used to mask frames. If null then SecureRandom will be created if needed.
-
-
Method Details
-
getExecutor
- Overrides:
getExecutor
in classAbstractConnection
-
getBufferPool
-
getGenerator
-
getParser
-
getLocalAddress
Deprecated.usegetLocalSocketAddress()
instead- Returns:
- the local InetSocketAddress
-
getLocalSocketAddress
-
getRemoteAddress
Deprecated.usegetRemoteSocketAddress()
instead- Returns:
- the remote InetSocketAddress
-
getRemoteSocketAddress
-
isUseInputDirectByteBuffers
public boolean isUseInputDirectByteBuffers() -
setUseInputDirectByteBuffers
public void setUseInputDirectByteBuffers(boolean useInputDirectByteBuffers) -
isUseOutputDirectByteBuffers
public boolean isUseOutputDirectByteBuffers() -
setUseOutputDirectByteBuffers
public void setUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers) -
onClose
Physical connection disconnect.Not related to WebSocket close handshake.
- Specified by:
onClose
in interfaceConnection
- Overrides:
onClose
in classAbstractConnection
- Parameters:
cause
- The cause of the close or null for a normal close
-
onIdleExpired
public boolean onIdleExpired()Description copied from interface:Connection
Callback method invoked upon an idle timeout event.
Implementations of this method may return true to indicate that the idle timeout handling should proceed normally, typically failing the EndPoint and causing it to be closed.
When false is returned, the handling of the idle timeout event is halted immediately and the EndPoint left in the state it was before the idle timeout event.
- Specified by:
onIdleExpired
in interfaceConnection
- Overrides:
onIdleExpired
in classAbstractConnection
- Returns:
- true to let the EndPoint handle the idle timeout, false to tell the EndPoint to halt the handling of the idle timeout.
-
onReadTimeout
Event for no activity on connection (read or write)- Overrides:
onReadTimeout
in classAbstractConnection
- Parameters:
timeout
- the cause of the read timeout- Returns:
- true to signal that the endpoint must be closed, false to keep the endpoint open
-
onFrame
-
onFillable
public void onFillable()Description copied from class:AbstractConnection
Callback method invoked when the endpoint is ready to be read.
- Specified by:
onFillable
in classAbstractConnection
- See Also:
-
run
public void run() -
demand
public void demand(long n) -
moreDemand
public boolean moreDemand() -
meetDemand
public boolean meetDemand() -
cancelDemand
public void cancelDemand() -
setInitialBuffer
Extra bytes from the initial HTTP upgrade that need to be processed by the websocket parser before starting to read bytes from the connection- Parameters:
initialBuffer
- the bytes of extra content encountered during upgrade
-
onOpen
public void onOpen()Physical connection Open.- Specified by:
onOpen
in interfaceConnection
- Overrides:
onOpen
in classAbstractConnection
-
setInputBufferSize
public void setInputBufferSize(int inputBufferSize) - Overrides:
setInputBufferSize
in classAbstractConnection
-
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
-
toConnectionString
- Overrides:
toConnectionString
in classAbstractConnection
-
onUpgradeTo
Extra bytes from the initial HTTP upgrade that need to be processed by the websocket parser before starting to read bytes from the connection- Specified by:
onUpgradeTo
in interfaceConnection.UpgradeTo
- Parameters:
buffer
- a non-null buffer of extra bytes
-
getFrameFlusher
-
getMessagesIn
public long getMessagesIn()- Specified by:
getMessagesIn
in interfaceConnection
- Overrides:
getMessagesIn
in classAbstractConnection
-
getBytesIn
public long getBytesIn()- Specified by:
getBytesIn
in interfaceConnection
- Overrides:
getBytesIn
in classAbstractConnection
-
getMessagesOut
public long getMessagesOut()- Specified by:
getMessagesOut
in interfaceConnection
- Overrides:
getMessagesOut
in classAbstractConnection
-
getBytesOut
public long getBytesOut()- Specified by:
getBytesOut
in interfaceConnection
- Overrides:
getBytesOut
in classAbstractConnection
-
getLocalSocketAddress()
instead