Top Description Inners Fields Constructors Methods
io.undertow.websockets.core

public abstract Class WebSocketChannel

extends AbstractFramedChannel<WebSocketChannel, StreamSourceFrameChannel, StreamSinkFrameChannel>
Class Inheritance
Known Direct Subclasses
io.undertow.websockets.core.protocol.version07.WebSocket07Channel
Imports
io.undertow.conduits.IdleTimeoutConduit, io.undertow.server.protocol.framed.AbstractFramedChannel, .AbstractFramedStreamSourceChannel, .FrameHeaderData, io.undertow.websockets.extensions.ExtensionFunction, org.xnio.ChannelExceptionHandler, .ChannelListener, .ChannelListener.SimpleSetter, .ChannelListeners, .IoUtils, .OptionMap, .StreamConnection, io.undertow.connector.ByteBufferPool, .PooledByteBuffer, org.xnio.channels.StreamSinkChannel, java.io.IOException, .UnsupportedEncodingException, java.net.InetSocketAddress, java.nio.ByteBuffer, java.util.Collection, .Collections, .HashMap, .Map, .Set

A org.xnio.channels.ConnectedChannel which can be used to send and receive WebSocket Frames.
Authors
Norman Maurer, Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
WebSocketChannel.PartialFrame

Interface that represents a frame channel that is in the process of being created

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
private final boolean
private static final CloseMessage
private volatile int
private volatile boolean
private volatile boolean
private volatile boolean
closeInitiatedByRemotePeer

If this is true then the web socket close was initiated by the remote peer

private volatile String
protected final ExtensionFunction
protected final boolean
protected StreamSourceFrameChannel
protected final boolean
private volatile WebSocketChannel.PartialFrame
partialFrame

an incoming frame that has not been created yet

private final Set<WebSocketChannel>
peerConnections

Represents all web socket channels that are attached to the same endpoint.

private final String
private final WebSocketVersion
private final String

Constructor Summary

AccessConstructor and Description
protected
WebSocketChannel(final StreamConnection
The org.xnio.channels.ConnectedStreamChannel over which the WebSocket Frames should get send and received. Be aware that it already must be "upgraded".
connectedStreamChannel
,
ByteBufferPool
The org.xnio.Pool which will be used to acquire java.nio.ByteBuffer's from.
bufferPool
,
WebSocketVersion version, String
The url for which the channel was created.
wsUrl
,
String subProtocol, final boolean client, boolean extensionsSupported, final ExtensionFunction extensionFunction, Set<WebSocketChannel>
The concurrent set that is used to track open connections associtated with an endpoint
peerConnections
,
OptionMap options)

Create a new WebSocketChannel 8

Method Summary

Modifier and TypeMethod and Description
public boolean
areExtensionsSupported()

Returns true if extensions are supported by this WebSocket Channel.

protected StreamSourceFrameChannel
createChannel(FrameHeaderData
The header data, as returned by parseFrame(java.nio.ByteBuffer)
frameHeaderData
,
PooledByteBuffer
Any additional data for the frame that has already been read. This may not be the complete frame contents
frameData
)

Implements abstract io.undertow.server.protocol.framed.AbstractFramedChannel.createChannel.

Method that creates the actual stream source channel implementation that is in use.

protected IdleTimeoutConduit
protected abstract StreamSinkFrameChannel
createStreamSinkChannel(WebSocketFrameType
The WebSocketFrameType of the WebSocketFrame which will be send over this StreamSinkFrameChannel
type
)

Create a new StreamSinkFrameChannel which can be used to send a WebSocket Frame of the type WebSocketFrameType.

public final Object
public int

Returns:

The close code
getCloseCode
()

public String

Returns:

The close reason
getCloseReason
()

public InetSocketAddress

Returns:

the destination address of the WebSocket Channel
getDestinationAddress
()

Overrides io.undertow.server.protocol.framed.AbstractFramedChannel.getDestinationAddress.

Get the destination address of the WebSocket Channel.

public ExtensionFunction
protected WebSocketFramePriority
public Set<WebSocketChannel>

Returns:

all 'peer' web socket connections
getPeerConnections
()

Returns all 'peer' web socket connections that were created from the same endpoint.

protected Collection<AbstractFramedStreamSourceChannel<WebSocketChannel, StreamSourceFrameChannel, StreamSinkFrameChannel>>
public String

Returns:

the request URI scheme
getRequestScheme
()

Get the request URI scheme.

public InetSocketAddress

Returns:

the source address of the WebSocket Channel
getSourceAddress
()

Overrides io.undertow.server.protocol.framed.AbstractFramedChannel.getSourceAddress.

Get the source address of the WebSocket Channel.

public String
public Set<String>
getSubProtocols()
Deprecated

Returns an unmodifiable Set of the selected subprotocols if any.

public String

Returns:

url The URL of the endpoint
getUrl
()

Return the URL of the WebSocket endpoint.

public WebSocketVersion

Returns:

version The WebSocketVersion which is in use
getVersion
()

Return the WebSocketVersion which is used

protected void
handleBrokenSinkChannel(Throwable e)

Implements abstract io.undertow.server.protocol.framed.AbstractFramedChannel.handleBrokenSinkChannel.

Method that is invoked when then write side of a channel is broken.

protected void
handleBrokenSourceChannel(Throwable e)

Implements abstract io.undertow.server.protocol.framed.AbstractFramedChannel.handleBrokenSourceChannel.

Method that is invoked when the read side of the channel is broken.

public boolean
public boolean
public boolean
public boolean

Returns:

true if the remote peer closed the connection
isCloseInitiatedByRemotePeer
()

If this is true the session is being closed because the remote peer sent a close frame

protected boolean
isLastFrameReceived()

Implements abstract io.undertow.server.protocol.framed.AbstractFramedChannel.isLastFrameReceived.

Returns true if the protocol specific final frame has been received.

protected boolean
protected boolean
public boolean
isSecure()

Return true if this is handled via WebSocket Secure.

protected void
lastDataRead()

Overrides io.undertow.server.protocol.framed.AbstractFramedChannel.lastDataRead.

Method than is invoked when read() returns -1.

protected void
markReadsBroken(Throwable
The possibly null cause
cause
)

Overrides io.undertow.server.protocol.framed.AbstractFramedChannel.markReadsBroken.

Called when a source sub channel fails to fulfil its contract, and leaves the channel in an inconsistent state.

protected FrameHeaderData
parseFrame(ByteBuffer
The data that has been read from the channel
data
)

Implements abstract io.undertow.server.protocol.framed.AbstractFramedChannel.parseFrame.

Attempts to parse an incoming frame header from the data in the buffer.

protected abstract WebSocketChannel.PartialFrame

Returns:

channel A io.undertow.websockets.core.StreamSourceFrameChannel will be used to read a Frame from. This will return null if the right io.undertow.websockets.core.StreamSourceFrameChannel could not be detected with the given buffer and so more data is needed.
receiveFrame
()

Create a new io.undertow.websockets.core.StreamSourceFrameChannel which can be used to read the data of the received Frame

public final StreamSinkFrameChannel
send(WebSocketFrameType
The WebSocketFrameType for which a StreamSinkChannel should be created
type
)

Returns a new StreamSinkFrameChannel for sending the given WebSocketFrameType with the given payload.

public void
sendClose()

Send a Close frame without a payload

public final boolean
public void
setCloseCode(int closeCode)

public void
setCloseReason(String closeReason)

Inherited from io.undertow.server.protocol.framed.AbstractFramedChannel:
addCloseTaskclosecloseSubChannelsflushflushSendersgetBufferPoolgetCloseSettergetIdleTimeoutgetIoThreadgetLocalAddressgetLocalAddressgetOptiongetPeerAddressgetPeerAddressgetReceiveSettergetSettingsgetUnderlyingConnectiongetWorkerisOpenisReceivesResumedisRequireExplicitFlushisWritesBrokenmarkWritesBrokenqueueFramerecalculateHeldFramesreceiveresumeReceivessetIdleTimeoutsetOptionsetRequireExplicitFlushsupportsOptionsuspendReceivestoStringwriteExceptionHandler

Field Detail

attributesback to summary
private final Map<String, Object> attributes
clientback to summary
private final boolean client
CLOSE_MSGback to summary
private static final CloseMessage CLOSE_MSG
closeCodeback to summary
private volatile int closeCode
closeFrameReceivedback to summary
private volatile boolean closeFrameReceived
closeFrameSentback to summary
private volatile boolean closeFrameSent
closeInitiatedByRemotePeerback to summary
private volatile boolean closeInitiatedByRemotePeer

If this is true then the web socket close was initiated by the remote peer

closeReasonback to summary
private volatile String closeReason
extensionFunctionback to summary
protected final ExtensionFunction extensionFunction
extensionsSupportedback to summary
protected final boolean extensionsSupported
fragmentedChannelback to summary
protected StreamSourceFrameChannel fragmentedChannel
hasReservedOpCodeback to summary
protected final boolean hasReservedOpCode
partialFrameback to summary
private volatile WebSocketChannel.PartialFrame partialFrame

an incoming frame that has not been created yet

peerConnectionsback to summary
private final Set<WebSocketChannel> peerConnections

Represents all web socket channels that are attached to the same endpoint.

subProtocolback to summary
private final String subProtocol
versionback to summary
private final WebSocketVersion version
wsUrlback to summary
private final String wsUrl

Constructor Detail

WebSocketChannelback to summary
protected WebSocketChannel(final StreamConnection connectedStreamChannel, ByteBufferPool bufferPool, WebSocketVersion version, String wsUrl, String subProtocol, final boolean client, boolean extensionsSupported, final ExtensionFunction extensionFunction, Set<WebSocketChannel> peerConnections, OptionMap options)

Create a new WebSocketChannel 8

Parameters
connectedStreamChannel:StreamConnection

The org.xnio.channels.ConnectedStreamChannel over which the WebSocket Frames should get send and received. Be aware that it already must be "upgraded".

bufferPool:ByteBufferPool

The org.xnio.Pool which will be used to acquire java.nio.ByteBuffer's from.

version:WebSocketVersion

The WebSocketVersion of the WebSocketChannel

wsUrl:String

The url for which the channel was created.

peerConnections:Set<WebSocketChannel>

The concurrent set that is used to track open connections associtated with an endpoint

Method Detail

areExtensionsSupportedback to summary
public boolean areExtensionsSupported()

Returns true if extensions are supported by this WebSocket Channel.

createChannelback to summary
protected StreamSourceFrameChannel createChannel(FrameHeaderData frameHeaderData, PooledByteBuffer frameData)

Implements abstract io.undertow.server.protocol.framed.AbstractFramedChannel.createChannel.

Doc from io.undertow.server.protocol.framed.AbstractFramedChannel.createChannel.

Method that creates the actual stream source channel implementation that is in use.

Parameters
frameHeaderData:FrameHeaderData

The header data, as returned by parseFrame(java.nio.ByteBuffer)

frameData:PooledByteBuffer

Any additional data for the frame that has already been read. This may not be the complete frame contents

Returns:StreamSourceFrameChannel

A new stream source channel

Annotations
@Override
createIdleTimeoutChannelback to summary
protected IdleTimeoutConduit createIdleTimeoutChannel(final StreamConnection connectedStreamChannel)

Overrides io.undertow.server.protocol.framed.AbstractFramedChannel.createIdleTimeoutChannel.

Annotations
@Override
createStreamSinkChannelback to summary
protected abstract StreamSinkFrameChannel createStreamSinkChannel(WebSocketFrameType type)

Create a new StreamSinkFrameChannel which can be used to send a WebSocket Frame of the type WebSocketFrameType.

Parameters
type:WebSocketFrameType

The WebSocketFrameType of the WebSocketFrame which will be send over this StreamSinkFrameChannel

getAttributeback to summary
public final Object getAttribute(String key)
getCloseCodeback to summary
public int getCloseCode()
Returns:int

The close code

getCloseReasonback to summary
public String getCloseReason()
Returns:String

The close reason

getDestinationAddressback to summary
public InetSocketAddress getDestinationAddress()

Overrides io.undertow.server.protocol.framed.AbstractFramedChannel.getDestinationAddress.

Get the destination address of the WebSocket Channel.

Returns:InetSocketAddress

the destination address of the WebSocket Channel

getExtensionFunctionback to summary
public ExtensionFunction getExtensionFunction()
getFramePriorityback to summary
protected WebSocketFramePriority getFramePriority()

Overrides io.undertow.server.protocol.framed.AbstractFramedChannel.getFramePriority.

getPeerConnectionsback to summary
public Set<WebSocketChannel> getPeerConnections()

Returns all 'peer' web socket connections that were created from the same endpoint.

Returns:Set<WebSocketChannel>

all 'peer' web socket connections

getReceiversback to summary
protected Collection<AbstractFramedStreamSourceChannel<WebSocketChannel, StreamSourceFrameChannel, StreamSinkFrameChannel>> getReceivers()

Implements abstract io.undertow.server.protocol.framed.AbstractFramedChannel.getReceivers.

Annotations
@Override
getRequestSchemeback to summary
public String getRequestScheme()

Get the request URI scheme. Normally this is one of ws or wss.

Returns:String

the request URI scheme

getSourceAddressback to summary
public InetSocketAddress getSourceAddress()

Overrides io.undertow.server.protocol.framed.AbstractFramedChannel.getSourceAddress.

Get the source address of the WebSocket Channel.

Returns:InetSocketAddress

the source address of the WebSocket Channel

getSubProtocolback to summary
public String getSubProtocol()
getSubProtocolsback to summary
public Set<String> getSubProtocols()

Deprecated

Returns an unmodifiable Set of the selected subprotocols if any.

Annotations
@Deprecated
getUrlback to summary
public String getUrl()

Return the URL of the WebSocket endpoint.

Returns:String

url The URL of the endpoint

getVersionback to summary
public WebSocketVersion getVersion()

Return the WebSocketVersion which is used

Returns:WebSocketVersion

version The WebSocketVersion which is in use

handleBrokenSinkChannelback to summary
protected void handleBrokenSinkChannel(Throwable e)

Implements abstract io.undertow.server.protocol.framed.AbstractFramedChannel.handleBrokenSinkChannel.

Doc from io.undertow.server.protocol.framed.AbstractFramedChannel.handleBrokenSinkChannel.

Method that is invoked when then write side of a channel is broken. This generally happens on a protocol error.

Annotations
@Override
handleBrokenSourceChannelback to summary
protected void handleBrokenSourceChannel(Throwable e)

Implements abstract io.undertow.server.protocol.framed.AbstractFramedChannel.handleBrokenSourceChannel.

Doc from io.undertow.server.protocol.framed.AbstractFramedChannel.handleBrokenSourceChannel.

Method that is invoked when the read side of the channel is broken. This generally happens on a protocol error.

Annotations
@Override
isClientback to summary
public boolean isClient()
isCloseFrameReceivedback to summary
public boolean isCloseFrameReceived()
isCloseFrameSentback to summary
public boolean isCloseFrameSent()
isCloseInitiatedByRemotePeerback to summary
public boolean isCloseInitiatedByRemotePeer()

If this is true the session is being closed because the remote peer sent a close frame

Returns:boolean

true if the remote peer closed the connection

isLastFrameReceivedback to summary
protected boolean isLastFrameReceived()

Implements abstract io.undertow.server.protocol.framed.AbstractFramedChannel.isLastFrameReceived.

Doc from io.undertow.server.protocol.framed.AbstractFramedChannel.isLastFrameReceived.

Returns true if the protocol specific final frame has been received.

Returns:boolean

true If the last frame has been received

Annotations
@Override
isLastFrameSentback to summary
protected boolean isLastFrameSent()

Implements abstract io.undertow.server.protocol.framed.AbstractFramedChannel.isLastFrameSent.

Returns:boolean

Doc from io.undertow.server.protocol.framed.AbstractFramedChannel.isLastFrameSent.

true If the last frame has been sent

Annotations
@Override
isReadsBrokenback to summary
protected boolean isReadsBroken()

Overrides io.undertow.server.protocol.framed.AbstractFramedChannel.isReadsBroken.

isSecureback to summary
public boolean isSecure()

Return true if this is handled via WebSocket Secure.

lastDataReadback to summary
protected void lastDataRead()

Overrides io.undertow.server.protocol.framed.AbstractFramedChannel.lastDataRead.

Doc from io.undertow.server.protocol.framed.AbstractFramedChannel.lastDataRead.

Method than is invoked when read() returns -1.

Annotations
@Override
markReadsBrokenback to summary
protected void markReadsBroken(Throwable cause)

Overrides io.undertow.server.protocol.framed.AbstractFramedChannel.markReadsBroken.

Doc from io.undertow.server.protocol.framed.AbstractFramedChannel.markReadsBroken.

Called when a source sub channel fails to fulfil its contract, and leaves the channel in an inconsistent state.

The underlying read side will be forcibly closed.

Parameters
cause:Throwable

The possibly null cause

Annotations
@Override
parseFrameback to summary
protected FrameHeaderData parseFrame(ByteBuffer data) throws IOException

Implements abstract io.undertow.server.protocol.framed.AbstractFramedChannel.parseFrame.

Doc from io.undertow.server.protocol.framed.AbstractFramedChannel.parseFrame.

Attempts to parse an incoming frame header from the data in the buffer.

Parameters
data:ByteBuffer

The data that has been read from the channel

Returns:FrameHeaderData

The frame header data, or null if the data was incomplete

Annotations
@Override
Exceptions
IOException:
If the data could not be parsed.
receiveFrameback to summary
protected abstract WebSocketChannel.PartialFrame receiveFrame()

Create a new io.undertow.websockets.core.StreamSourceFrameChannel which can be used to read the data of the received Frame

Returns:WebSocketChannel.PartialFrame

channel A io.undertow.websockets.core.StreamSourceFrameChannel will be used to read a Frame from. This will return null if the right io.undertow.websockets.core.StreamSourceFrameChannel could not be detected with the given buffer and so more data is needed.

sendback to summary
public final StreamSinkFrameChannel send(WebSocketFrameType type) throws IOException

Returns a new StreamSinkFrameChannel for sending the given WebSocketFrameType with the given payload. If this method is called multiple times, subsequent StreamSinkFrameChannel's will not be writable until all previous frames were completely written.

Parameters
type:WebSocketFrameType

The WebSocketFrameType for which a StreamSinkChannel should be created

sendCloseback to summary
public void sendClose() throws IOException

Send a Close frame without a payload

setAttributeback to summary
public final boolean setAttribute(String key, Object value)
setCloseCodeback to summary
public void setCloseCode(int closeCode)
setCloseReasonback to summary
public void setCloseReason(String closeReason)
io.undertow.websockets.core back to summary

public Interface WebSocketChannel.PartialFrame

extends FrameHeaderData
Known Direct Subinterfaces
io.undertow.websockets.core.WebSocketFrame

Interface that represents a frame channel that is in the process of being created

Method Summary

Modifier and TypeMethod and Description
public StreamSourceFrameChannel

Returns:

The channel, or null if the channel is not available yet
getChannel
(final PooledByteBuffer data)

public void
handle(ByteBuffer data)

Handles the data, any remaining data will be pushed back

public boolean

Returns:

true if the channel is available
isDone
()

Inherited from io.undertow.server.protocol.framed.FrameHeaderData:
getExistingChannelgetFrameLength

Method Detail

getChannelback to summary
public StreamSourceFrameChannel getChannel(final PooledByteBuffer data)
Returns:StreamSourceFrameChannel

The channel, or null if the channel is not available yet

handleback to summary
public void handle(ByteBuffer data) throws WebSocketException

Handles the data, any remaining data will be pushed back

isDoneback to summary
public boolean isDone()
Returns:boolean

true if the channel is available