public abstract class WebSocketChannel extends AbstractFramedChannel<WebSocketChannel,StreamSourceFrameChannel,StreamSinkFrameChannel>
ConnectedChannel
which can be used to send and receive WebSocket Frames.Modifier and Type | Class and Description |
---|---|
static interface |
WebSocketChannel.PartialFrame
Interface that represents a frame channel that is in the process of being created
|
Modifier and Type | Field and Description |
---|---|
protected StreamSourceFrameChannel |
fragmentedChannel |
Modifier | Constructor and Description |
---|---|
protected |
WebSocketChannel(org.xnio.StreamConnection connectedStreamChannel,
org.xnio.Pool<ByteBuffer> bufferPool,
WebSocketVersion version,
String wsUrl,
String subProtocol,
boolean client,
boolean extensionsSupported)
Create a new
WebSocketChannel
8 |
Modifier and Type | Method and Description |
---|---|
boolean |
areExtensionsSupported()
Returns
true if extensions are supported by this WebSocket Channel. |
protected StreamSourceFrameChannel |
createChannel(FrameHeaderData frameHeaderData,
org.xnio.Pooled<ByteBuffer> frameData)
Method that creates the actual stream source channel implementation that is in use.
|
protected abstract StreamSinkFrameChannel |
createStreamSinkChannel(WebSocketFrameType type,
long payloadSize)
Create a new StreamSinkFrameChannel which can be used to send a WebSocket Frame of the type
WebSocketFrameType . |
Object |
getAttribute(String key) |
InetSocketAddress |
getDestinationAddress()
Get the destination address of the WebSocket Channel.
|
protected WebSocketFramePriority |
getFramePriority() |
String |
getRequestScheme()
Get the request URI scheme.
|
InetSocketAddress |
getSourceAddress()
Get the source address of the WebSocket Channel.
|
String |
getSubProtocol() |
Set<String> |
getSubProtocols()
Deprecated.
|
String |
getUrl()
Return the URL of the WebSocket endpoint.
|
WebSocketVersion |
getVersion()
Return the
WebSocketVersion which is used |
protected void |
handleBrokenSinkChannel(Throwable e)
Method that is invoked when then write side of a channel is broken.
|
protected void |
handleBrokenSourceChannel(Throwable e)
Method that is invoked when the read side of the channel is broken.
|
boolean |
isClient() |
boolean |
isCloseFrameReceived() |
boolean |
isCloseFrameSent() |
protected boolean |
isLastFrameReceived()
Returns true if the protocol specific final frame has been received.
|
protected boolean |
isLastFrameSent() |
protected boolean |
isReadsBroken() |
boolean |
isSecure()
Return
true if this is handled via WebSocket Secure. |
protected void |
markReadsBroken(Throwable cause)
Called when a source sub channel fails to fulfil its contract, and leaves the channel in an inconsistent state.
|
protected FrameHeaderData |
parseFrame(ByteBuffer data)
Attempts to parse an incoming frame header from the data in the buffer.
|
protected abstract WebSocketChannel.PartialFrame |
receiveFrame()
Create a new
StreamSourceFrameChannel which can be used to read the data of the received Frame |
StreamSinkFrameChannel |
send(WebSocketFrameType type)
Returns a new
StreamSinkFrameChannel for sending the given WebSocketFrameType with the given payload. |
StreamSinkFrameChannel |
send(WebSocketFrameType type,
long payloadSize)
Returns a new
StreamSinkFrameChannel for sending the given WebSocketFrameType with the given payload. |
void |
sendClose()
Send a Close frame without a payload
|
boolean |
setAttribute(String key,
Object value) |
close, flushSenders, getBufferPool, getCloseSetter, getIdleTimeout, getIoThread, getLocalAddress, getLocalAddress, getOption, getPeerAddress, getPeerAddress, getReceiveSetter, getWorker, isOpen, isReceivesResumed, isWritesBroken, markWritesBroken, queueFrame, receive, resumeReceives, setIdleTimeout, setOption, supportsOption, suspendReceives, toString
protected StreamSourceFrameChannel fragmentedChannel
protected WebSocketChannel(org.xnio.StreamConnection connectedStreamChannel, org.xnio.Pool<ByteBuffer> bufferPool, WebSocketVersion version, String wsUrl, String subProtocol, boolean client, boolean extensionsSupported)
WebSocketChannel
8connectedStreamChannel
- The ConnectedStreamChannel
over which the WebSocket Frames should get send and received.
Be aware that it already must be "upgraded".bufferPool
- The Pool
which will be used to acquire ByteBuffer
's from.version
- The WebSocketVersion
of the WebSocketChannel
wsUrl
- The url for which the channel was created.client
- protected boolean isLastFrameSent()
isLastFrameSent
in class AbstractFramedChannel<WebSocketChannel,StreamSourceFrameChannel,StreamSinkFrameChannel>
true
If the last frame has been sentprotected boolean isLastFrameReceived()
AbstractFramedChannel
isLastFrameReceived
in class AbstractFramedChannel<WebSocketChannel,StreamSourceFrameChannel,StreamSinkFrameChannel>
true
If the last frame has been receivedprotected void markReadsBroken(Throwable cause)
AbstractFramedChannel
markReadsBroken
in class AbstractFramedChannel<WebSocketChannel,StreamSourceFrameChannel,StreamSinkFrameChannel>
cause
- The possibly null causeprotected boolean isReadsBroken()
isReadsBroken
in class AbstractFramedChannel<WebSocketChannel,StreamSourceFrameChannel,StreamSinkFrameChannel>
protected FrameHeaderData parseFrame(ByteBuffer data) throws IOException
AbstractFramedChannel
parseFrame
in class AbstractFramedChannel<WebSocketChannel,StreamSourceFrameChannel,StreamSinkFrameChannel>
data
- The data that has been read from the channelnull
if the data was incompleteIOException
- If the data could not be parsed.protected abstract WebSocketChannel.PartialFrame receiveFrame()
StreamSourceFrameChannel
which can be used to read the data of the received FrameStreamSourceFrameChannel
will be used to read a Frame from.
This will return null
if the right StreamSourceFrameChannel
could not be detected with the given
buffer and so more data is needed.protected StreamSourceFrameChannel createChannel(FrameHeaderData frameHeaderData, org.xnio.Pooled<ByteBuffer> frameData)
AbstractFramedChannel
createChannel
in class AbstractFramedChannel<WebSocketChannel,StreamSourceFrameChannel,StreamSinkFrameChannel>
frameHeaderData
- The header data, as returned by AbstractFramedChannel.parseFrame(java.nio.ByteBuffer)
frameData
- Any additional data for the frame that has already been read. This may not be the complete frame contentspublic boolean areExtensionsSupported()
true
if extensions are supported by this WebSocket Channel.protected void handleBrokenSourceChannel(Throwable e)
AbstractFramedChannel
handleBrokenSourceChannel
in class AbstractFramedChannel<WebSocketChannel,StreamSourceFrameChannel,StreamSinkFrameChannel>
protected void handleBrokenSinkChannel(Throwable e)
AbstractFramedChannel
handleBrokenSinkChannel
in class AbstractFramedChannel<WebSocketChannel,StreamSourceFrameChannel,StreamSinkFrameChannel>
@Deprecated public Set<String> getSubProtocols()
Set
of the selected subprotocols if any.public String getSubProtocol()
public boolean isCloseFrameReceived()
public boolean isCloseFrameSent()
public String getRequestScheme()
ws
or wss
.public boolean isSecure()
true
if this is handled via WebSocket Secure.public String getUrl()
public WebSocketVersion getVersion()
WebSocketVersion
which is usedWebSocketVersion
which is in usepublic InetSocketAddress getSourceAddress()
getSourceAddress
in class AbstractFramedChannel<WebSocketChannel,StreamSourceFrameChannel,StreamSinkFrameChannel>
public InetSocketAddress getDestinationAddress()
getDestinationAddress
in class AbstractFramedChannel<WebSocketChannel,StreamSourceFrameChannel,StreamSinkFrameChannel>
public boolean isClient()
public final StreamSinkFrameChannel send(WebSocketFrameType type, long payloadSize) throws IOException
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.type
- The WebSocketFrameType
for which a StreamSinkChannel
should be createdpayloadSize
- The size of the payload which will be included in the WebSocket Frame. This may be 0 if you want
to transmit no payload at all.IOException
public final StreamSinkFrameChannel send(WebSocketFrameType type) throws IOException
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.type
- The WebSocketFrameType
for which a StreamSinkChannel
should be createdIOException
public void sendClose() throws IOException
IOException
protected abstract StreamSinkFrameChannel createStreamSinkChannel(WebSocketFrameType type, long payloadSize)
WebSocketFrameType
.type
- The WebSocketFrameType
of the WebSocketFrame which will be send over this StreamSinkFrameChannel
payloadSize
- The size of the payload to transmit. May be 0 if non payload at all should be included, or -1 if unknownprotected WebSocketFramePriority getFramePriority()
getFramePriority
in class AbstractFramedChannel<WebSocketChannel,StreamSourceFrameChannel,StreamSinkFrameChannel>
Copyright © 2014 JBoss by Red Hat. All rights reserved.