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 Connection
Connection.Listener, Connection.UpgradeFrom, Connection.UpgradeToNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface Invocable
Invocable.Callable, Invocable.InvocationType, Invocable.ReadyTask, Invocable.Task -
Field Summary
Fields inherited from interface Invocable
__nonBlocking, NOOP -
Constructor Summary
ConstructorsConstructorDescriptionWebSocketConnection(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 TypeMethodDescriptionvoidvoiddemand()dump()voiddump(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.voidenqueueFrame(Frame frame, Callback callback, boolean batch) Enqueue a Frame to be sent.longlongDeprecated.longlongDeprecated.usegetRemoteSocketAddress()insteadbooleanbooleanbooleanbooleanvoidCallback method invoked when this connection is closed.voidCallback method invoked when the endpoint is ready to be read.protected voidonFrame(Frame.Parsed frame) booleanonIdleExpired(TimeoutException timeoutException) Callback method invoked upon an idle timeout event.voidonOpen()Callback method invoked when this connection is opened.protected booleanonReadTimeout(TimeoutException timeout) Callback method invoked when the endpoint failed to be ready to be read after a timeoutvoidonUpgradeTo(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 connectionvoidrun()protected voidsetInitialBuffer(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 connectionvoidsetInputBufferSize(int inputBufferSize) voidsetUseInputDirectByteBuffers(boolean useInputDirectByteBuffers) voidsetUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers) voidsetWriteTimeout(long writeTimeout) Deprecated, for removal: This API element is subject to removal in a future version.Methods inherited from class 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:
getExecutorin classAbstractConnection
-
getLocalAddress
Deprecated.usegetLocalSocketAddress()instead- Returns:
- the local InetSocketAddress
-
getLocalSocketAddress
-
getRemoteAddress
Deprecated.usegetRemoteSocketAddress()instead- Returns:
- the remote InetSocketAddress
-
getRemoteSocketAddress
-
isUseInputDirectByteBuffers
public boolean isUseInputDirectByteBuffers() -
setWriteTimeout
Deprecated, for removal: This API element is subject to removal in a future version. -
setUseInputDirectByteBuffers
public void setUseInputDirectByteBuffers(boolean useInputDirectByteBuffers) -
isUseOutputDirectByteBuffers
public boolean isUseOutputDirectByteBuffers() -
setUseOutputDirectByteBuffers
public void setUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers) -
onClose
Description copied from interface:ConnectionCallback method invoked when this connection is closed.
Creators of the connection implementation are responsible for calling this method.
- Specified by:
onClosein interfaceConnection- Overrides:
onClosein classAbstractConnection- Parameters:
cause- The cause of the close or null for a normal close
-
onIdleExpired
Description copied from interface:ConnectionCallback 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:
onIdleExpiredin interfaceConnection- Overrides:
onIdleExpiredin 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:AbstractConnectionCallback method invoked when the endpoint failed to be ready to be read after a timeout
- Overrides:
onReadTimeoutin 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:AbstractConnectionCallback method invoked when the endpoint is ready to be read.
- Specified by:
onFillablein classAbstractConnection- See Also:
-
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:ConnectionCallback method invoked when this connection is opened.
Creators of the connection implementation are responsible for calling this method.
- Specified by:
onOpenin interfaceConnection- Overrides:
onOpenin classAbstractConnection
-
setInputBufferSize
public void setInputBufferSize(int inputBufferSize) - Overrides:
setInputBufferSizein classAbstractConnection
-
dump
-
dump
Description copied from interface:DumpableDump 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:
dumpin 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:
toConnectionStringin 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:
onUpgradeToin interfaceConnection.UpgradeTo- Parameters:
buffer- a non-null buffer of extra bytes
-
getMessagesIn
public long getMessagesIn()- Specified by:
getMessagesInin interfaceConnection- Overrides:
getMessagesInin classAbstractConnection
-
getBytesIn
public long getBytesIn()- Specified by:
getBytesInin interfaceConnection- Overrides:
getBytesInin classAbstractConnection
-
getMessagesOut
public long getMessagesOut()- Specified by:
getMessagesOutin interfaceConnection- Overrides:
getMessagesOutin classAbstractConnection
-
getBytesOut
public long getBytesOut()- Specified by:
getBytesOutin interfaceConnection- Overrides:
getBytesOutin classAbstractConnection
-
enqueueFrame
-
getLocalSocketAddress()instead