Top Description Inners Fields Constructors Methods
org.eclipse.jetty.websocket.core

public Class WebSocketConnection

extends AbstractConnection
implements UpgradeTo, Dumpable, Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.io.Connection.UpgradeTo
Imports
java.io.IOException, java.net.InetSocketAddress, .SocketAddress, java.nio.ByteBuffer, java.nio.channels.ReadPendingException, java.security.SecureRandom, java.util.Objects, .Random, java.util.concurrent.Executor, .TimeoutException, java.util.concurrent.atomic.LongAdder, org.eclipse.jetty.io.AbstractConnection, .ByteBufferPool, .Connection, .EndPoint, .RetainableByteBuffer, org.eclipse.jetty.util.BufferUtil, .Callback, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.thread.AutoLock, .Scheduler, org.eclipse.jetty.websocket.core.exception.WebSocketTimeoutException, org.eclipse.jetty.websocket.core.internal.FrameFlusher, .Generator, .Parser, org.slf4j.Logger, .LoggerFactory

Provides the implementation of org.eclipse.jetty.io.Connection that is suitable for WebSocket

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
private class

Field Summary

Modifier and TypeField and Description
private final ByteBufferPool
private final LongAdder
private final WebSocketCoreSession
private WebSocketConnection.DemandState
private boolean
private final WebSocketConnection.Flusher
private final Generator
private final AutoLock
private static final Logger
private final LongAdder
private static final int
MIN_BUFFER_SIZE

Minimum size of a buffer is the determined to be what would be the maximum framing header size (not including payload)

private RetainableByteBuffer
private final Parser
private final Random
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
public
WebSocketConnection(EndPoint endp, Executor executor, Scheduler scheduler, ByteBufferPool byteBufferPool, WebSocketCoreSession coreSession)

Create a WSConnection.

public
WebSocketConnection(EndPoint
The endpoint ever which Websockot is sent/received
endp
,
Executor
A thread executor to use for WS callbacks.
executor
,
Scheduler
A scheduler to use for timeouts
scheduler
,
ByteBufferPool
A pool of retainable buffers to use.
byteBufferPool
,
WebSocketCoreSession
The WC core session to which frames are delivered.
coreSession
,
Random
A Random used to mask frames. If null then SecureRandom will be created if needed.
randomMask
)

Create a WSConnection.

Method Summary

Modifier and TypeMethod and Description
private void
public void
public void
public String
public void
dump(Appendable
The appendable to dump to
out
,
String
The indent to apply after any new lines.
indent
)

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines.

public void
enqueueFrame(Frame
The frame to queue
frame
,
Callback
The callback to call once the frame is sent
callback
,
boolean
True if batch mode is to be used
batch
)

Enqueue a Frame to be sent.

private void
public long
public long
public Executor
public InetSocketAddress
getLocalAddress()
Deprecated use getLocalSocketAddress() instead

Returns: the local InetSocketAddress

public SocketAddress
public long
public long
public InetSocketAddress
getRemoteAddress()
Deprecated use getRemoteSocketAddress() instead

Returns: the remote InetSocketAddress

public SocketAddress
public boolean
public boolean
public boolean
public boolean
private RetainableByteBuffer
newNetworkBuffer(int capacity)

public void
onClose(Throwable
The cause of the close or null for a normal close
cause
)

Overrides org.eclipse.jetty.io.AbstractConnection.onClose.

Implements org.eclipse.jetty.io.Connection.onClose.

Physical connection disconnect.

public void
onFillable()

Implements abstract org.eclipse.jetty.io.AbstractConnection.onFillable.

Callback method invoked when the endpoint is ready to be read.

protected void
public boolean
onIdleExpired(TimeoutException timeoutException)

Overrides org.eclipse.jetty.io.AbstractConnection.onIdleExpired.

Implements org.eclipse.jetty.io.Connection.onIdleExpired.

Callback method invoked upon an idle timeout event.

public void
protected boolean

Returns:

true to signal that the endpoint must be closed, false to keep the endpoint open
onReadTimeout
(TimeoutException
the cause of the read timeout
timeout
)

Overrides org.eclipse.jetty.io.AbstractConnection.onReadTimeout.

Event for no activity on connection (read or write)

public void
onUpgradeTo(ByteBuffer
a non-null buffer of extra bytes
buffer
)

Implements org.eclipse.jetty.io.Connection.UpgradeTo.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

private void
private void
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

protected void
setInitialBuffer(ByteBuffer
the bytes of extra content encountered during upgrade
initialBuffer
)

Extra bytes from the initial HTTP upgrade that need to be processed by the websocket parser before starting to read bytes from the connection

public void
public void
setUseInputDirectByteBuffers(boolean useInputDirectByteBuffers)

public void
setUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers)

public void
setWriteTimeout(long writeTimeout)

public String
Inherited from org.eclipse.jetty.io.AbstractConnection:
addEventListenerclosefailedCallbackfillInterestedgetCreatedTimeStampgetEndPointgetInputBufferSizegetInvocationTypeisFillInterestedonFillInterestedFailedremoveEventListenertoStringtryFillInterested

Field Detail

byteBufferPoolback to summary
private final ByteBufferPool byteBufferPool
bytesInback to summary
private final LongAdder bytesIn
coreSessionback to summary
private final WebSocketCoreSession coreSession
demandback to summary
private WebSocketConnection.DemandState demand
fillingAndParsingback to summary
private boolean fillingAndParsing
flusherback to summary
private final WebSocketConnection.Flusher flusher
generatorback to summary
private final Generator generator
lockback to summary
private final AutoLock lock
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.io.AbstractConnection.LOG.

messagesInback to summary
private final LongAdder messagesIn
MIN_BUFFER_SIZEback to summary
private static final int MIN_BUFFER_SIZE

Minimum size of a buffer is the determined to be what would be the maximum framing header size (not including payload)

networkBufferback to summary
private RetainableByteBuffer networkBuffer
parserback to summary
private final Parser parser
randomback to summary
private final Random random
useInputDirectByteBuffersback to summary
private boolean useInputDirectByteBuffers
useOutputDirectByteBuffersback to summary
private boolean useOutputDirectByteBuffers

Constructor Detail

WebSocketConnectionback to summary
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.

WebSocketConnectionback to summary
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:EndPoint

The endpoint ever which Websockot is sent/received

executor:Executor

A thread executor to use for WS callbacks.

scheduler:Scheduler

A scheduler to use for timeouts

byteBufferPool:ByteBufferPool

A pool of retainable buffers to use.

coreSession:WebSocketCoreSession

The WC core session to which frames are delivered.

randomMask:Random

A Random used to mask frames. If null then SecureRandom will be created if needed.

Method Detail

acquireNetworkBufferback to summary
private void acquireNetworkBuffer()
cancelDemandback to summary
public void cancelDemand()
demandback to summary
public void demand()
dumpback to summary
public String dump()

Overrides default org.eclipse.jetty.util.component.Dumpable.dump.

Annotations
@Override
dumpback to summary
public void dump(Appendable out, String indent) throws IOException

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Doc from org.eclipse.jetty.util.component.Dumpable.dump.

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.

Parameters
out:Appendable

The appendable to dump to

indent:String

The indent to apply after any new lines.

Annotations
@Override
Exceptions
IOException:
if unable to write to Appendable
enqueueFrameback to summary
public void enqueueFrame(Frame frame, Callback callback, boolean batch)

Enqueue a Frame to be sent.

Parameters
frame:Frame

The frame to queue

callback:Callback

The callback to call once the frame is sent

batch:boolean

True if batch mode is to be used

fillAndParseback to summary
private void fillAndParse()
getBytesInback to summary
public long getBytesIn()

Overrides org.eclipse.jetty.io.AbstractConnection.getBytesIn.

Implements org.eclipse.jetty.io.Connection.getBytesIn.

Annotations
@Override
getBytesOutback to summary
public long getBytesOut()

Overrides org.eclipse.jetty.io.AbstractConnection.getBytesOut.

Implements org.eclipse.jetty.io.Connection.getBytesOut.

Annotations
@Override
getExecutorback to summary
public Executor getExecutor()

Overrides org.eclipse.jetty.io.AbstractConnection.getExecutor.

Annotations
@Override
getLocalAddressback to summary
public InetSocketAddress getLocalAddress()

Deprecated

use getLocalSocketAddress() instead

Returns:InetSocketAddress

the local InetSocketAddress

Annotations
@Deprecated
getLocalSocketAddressback to summary
public SocketAddress getLocalSocketAddress()
getMessagesInback to summary
public long getMessagesIn()

Overrides org.eclipse.jetty.io.AbstractConnection.getMessagesIn.

Implements org.eclipse.jetty.io.Connection.getMessagesIn.

Annotations
@Override
getMessagesOutback to summary
public long getMessagesOut()

Overrides org.eclipse.jetty.io.AbstractConnection.getMessagesOut.

Implements org.eclipse.jetty.io.Connection.getMessagesOut.

Annotations
@Override
getRemoteAddressback to summary
public InetSocketAddress getRemoteAddress()

Deprecated

use getRemoteSocketAddress() instead

Returns:InetSocketAddress

the remote InetSocketAddress

Annotations
@Deprecated
getRemoteSocketAddressback to summary
public SocketAddress getRemoteSocketAddress()
isUseInputDirectByteBuffersback to summary
public boolean isUseInputDirectByteBuffers()
isUseOutputDirectByteBuffersback to summary
public boolean isUseOutputDirectByteBuffers()
meetDemandback to summary
public boolean meetDemand()
moreDemandback to summary
public boolean moreDemand()
newNetworkBufferback to summary
private RetainableByteBuffer newNetworkBuffer(int capacity)
onCloseback to summary
public void onClose(Throwable cause)

Overrides org.eclipse.jetty.io.AbstractConnection.onClose.

Implements org.eclipse.jetty.io.Connection.onClose.

Physical connection disconnect.

Not related to WebSocket close handshake.

Parameters
cause:Throwable

Doc from org.eclipse.jetty.io.Connection.onClose.

The cause of the close or null for a normal close

Annotations
@Override
onFillableback to summary
public void onFillable()

Implements abstract org.eclipse.jetty.io.AbstractConnection.onFillable.

Doc from org.eclipse.jetty.io.AbstractConnection.onFillable.

Callback method invoked when the endpoint is ready to be read.

Annotations
@Override
onFrameback to summary
protected void onFrame(Frame.Parsed frame)
onIdleExpiredback to summary
public boolean onIdleExpired(TimeoutException timeoutException)

Overrides org.eclipse.jetty.io.AbstractConnection.onIdleExpired.

Implements org.eclipse.jetty.io.Connection.onIdleExpired.

Doc from org.eclipse.jetty.io.Connection.onIdleExpired.

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.

Returns:boolean

true to let the EndPoint handle the idle timeout, false to tell the EndPoint to halt the handling of the idle timeout.

Annotations
@Override
onOpenback to summary
public void onOpen()

Overrides org.eclipse.jetty.io.AbstractConnection.onOpen.

Implements org.eclipse.jetty.io.Connection.onOpen.

Physical connection Open.

Annotations
@Override
onReadTimeoutback to summary
protected boolean onReadTimeout(TimeoutException timeout)

Overrides org.eclipse.jetty.io.AbstractConnection.onReadTimeout.

Event for no activity on connection (read or write)

Parameters
timeout:TimeoutException

Doc from org.eclipse.jetty.io.AbstractConnection.onReadTimeout.

the cause of the read timeout

Returns:boolean

true to signal that the endpoint must be closed, false to keep the endpoint open

Annotations
@Override
onUpgradeToback to summary
public void onUpgradeTo(ByteBuffer buffer)

Implements org.eclipse.jetty.io.Connection.UpgradeTo.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

Parameters
buffer:ByteBuffer

a non-null buffer of extra bytes

Annotations
@Override
reacquireNetworkBufferback to summary
private void reacquireNetworkBuffer()
releaseNetworkBufferback to summary
private void releaseNetworkBuffer()
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
setInitialBufferback to summary
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 connection

Parameters
initialBuffer:ByteBuffer

the bytes of extra content encountered during upgrade

setInputBufferSizeback to summary
public void setInputBufferSize(int inputBufferSize)

Overrides org.eclipse.jetty.io.AbstractConnection.setInputBufferSize.

Annotations
@Override
setUseInputDirectByteBuffersback to summary
public void setUseInputDirectByteBuffers(boolean useInputDirectByteBuffers)
setUseOutputDirectByteBuffersback to summary
public void setUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers)
setWriteTimeoutback to summary
public void setWriteTimeout(long writeTimeout)
toConnectionStringback to summary
public String toConnectionString()

Overrides org.eclipse.jetty.io.AbstractConnection.toConnectionString.

Annotations
@Override
org.eclipse.jetty.websocket.core back to summary

private final Enum WebSocketConnection.DemandState

extends Enum<WebSocketConnection.DemandState>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final WebSocketConnection.DemandState
public static final WebSocketConnection.DemandState
public static final WebSocketConnection.DemandState

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static WebSocketConnection.DemandState
public static WebSocketConnection.DemandState[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CANCELLEDback to summary
public static final WebSocketConnection.DemandState CANCELLED
DEMANDINGback to summary
public static final WebSocketConnection.DemandState DEMANDING
NOT_DEMANDINGback to summary
public static final WebSocketConnection.DemandState NOT_DEMANDING

Constructor Detail

DemandStateback to summary
private DemandState()

Method Detail

valueOfback to summary
public static WebSocketConnection.DemandState valueOf(String name)
valuesback to summary
public static WebSocketConnection.DemandState[] values()
org.eclipse.jetty.websocket.core back to summary

private Class WebSocketConnection.Flusher

extends FrameFlusher
Class Inheritance

Field Summary

Inherited from org.eclipse.jetty.websocket.core.internal.FrameFlusher:
FLUSH_FRAME

Constructor Summary

AccessConstructor and Description
private
Flusher(Scheduler scheduler, int bufferSize, Generator generator, EndPoint endpoint)

Method Summary

Modifier and TypeMethod and Description
public void
onCompleteFailure(Throwable
the throwable to indicate cause of failure
x
)

Overrides org.eclipse.jetty.websocket.core.internal.FrameFlusher.onCompleteFailure.

Invoked when the overall task has completed with a failure.

Inherited from org.eclipse.jetty.websocket.core.internal.FrameFlusher:
enqueuegetBytesOutgetIdleTimeoutgetMessagesOutisUseDirectByteBuffersnotifyCallbackFailurenotifyCallbackSuccessonCloseprocesssetIdleTimeoutsetUseDirectByteBufferstimeoutExpiredtoString

Constructor Detail

Flusherback to summary
private Flusher(Scheduler scheduler, int bufferSize, Generator generator, EndPoint endpoint)

Method Detail

onCompleteFailureback to summary
public void onCompleteFailure(Throwable x)

Overrides org.eclipse.jetty.websocket.core.internal.FrameFlusher.onCompleteFailure.

Doc from org.eclipse.jetty.util.IteratingCallback.onCompleteFailure.

Invoked when the overall task has completed with a failure.

Parameters
x:Throwable

the throwable to indicate cause of failure

Annotations
@Override