Class WebSocketConnection
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Runnable
,Connection
,Connection.UpgradeTo
,Dumpable
,Invocable
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
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
Invocable.Callable, Invocable.InvocationType, Invocable.ReadyTask, Invocable.Task
-
Field Summary
Fields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking, NOOP
-
Constructor Summary
ConstructorDescriptionWebSocketConnection
(EndPoint endp, Executor executor, Scheduler scheduler, ByteBufferPool byteBufferPool, WebSocketCoreSession coreSession) Create a WSConnection.WebSocketConnection
(EndPoint endp, Executor executor, Scheduler scheduler, ByteBufferPool byteBufferPool, WebSocketCoreSession coreSession, Random randomMask) Create a WSConnection. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
demand()
dump()
void
dump
(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.void
enqueueFrame
(Frame frame, Callback callback, boolean batch) Enqueue a Frame to be sent.long
long
Deprecated.long
long
Deprecated.usegetRemoteSocketAddress()
insteadboolean
boolean
boolean
boolean
void
Callback method invoked when this connection is closed.void
Callback method invoked when the endpoint is ready to be read.protected void
onFrame
(Frame.Parsed frame) boolean
onIdleExpired
(TimeoutException timeoutException) Callback method invoked upon an idle timeout event.void
onOpen()
Callback method invoked when this connection is opened.protected boolean
onReadTimeout
(TimeoutException timeout) Callback method invoked when the endpoint failed to be ready to be read after a timeoutvoid
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) void
setWriteTimeout
(long writeTimeout) Methods inherited from class org.eclipse.jetty.io.AbstractConnection
addEventListener, close, failedCallback, fillInterested, getCreatedTimeStamp, getEndPoint, getInputBufferSize, getInvocationType, isFillInterested, onFillInterestedFailed, removeEventListener, toString, tryFillInterested
-
Constructor Details
-
WebSocketConnection
public WebSocketConnection(EndPoint endp, Executor executor, Scheduler scheduler, ByteBufferPool byteBufferPool, 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 byteBufferPool, 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 timeoutsbyteBufferPool
- 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
-
getLocalAddress
Deprecated.usegetLocalSocketAddress()
instead- Returns:
- the local InetSocketAddress
-
getLocalSocketAddress
-
getRemoteAddress
Deprecated.usegetRemoteSocketAddress()
instead- Returns:
- the remote InetSocketAddress
-
getRemoteSocketAddress
-
isUseInputDirectByteBuffers
public boolean isUseInputDirectByteBuffers() -
setWriteTimeout
public void setWriteTimeout(long writeTimeout) -
setUseInputDirectByteBuffers
public void setUseInputDirectByteBuffers(boolean useInputDirectByteBuffers) -
isUseOutputDirectByteBuffers
public boolean isUseOutputDirectByteBuffers() -
setUseOutputDirectByteBuffers
public void setUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers) -
onClose
Description copied from interface:Connection
Callback method invoked when this connection is closed.
Creators of the connection implementation are responsible for calling this method.
- Specified by:
onClose
in interfaceConnection
- Overrides:
onClose
in classAbstractConnection
- Parameters:
cause
- The cause of the close or null for a normal close
-
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
Description copied from class:AbstractConnection
Callback method invoked when the endpoint failed to be ready to be read after a timeout
- 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() -
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()Description copied from interface:Connection
Callback method invoked when this connection is opened.
Creators of the connection implementation are responsible for calling this method.
- 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
-
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
-
enqueueFrame
Enqueue a Frame to be sent.- Parameters:
frame
- The frame to queuecallback
- The callback to call once the frame is sentbatch
- True if batch mode is to be used
-
getLocalSocketAddress()
instead