public abstract class WebSocketChannel extends Object implements org.xnio.channels.ConnectedChannel
ConnectedChannel which can be used to send and receive WebSocket Frames.| Modifier and Type | Class and Description |
|---|---|
static interface |
WebSocketChannel.PartialFrame
Interface that represenets a channel that is in the process of being created
|
class |
WebSocketChannel.StreamSourceChannelControl |
| Modifier | Constructor and Description |
|---|---|
protected |
WebSocketChannel(org.xnio.StreamConnection connectedStreamChannel,
org.xnio.Pool<ByteBuffer> bufferPool,
WebSocketVersion version,
String wsUrl,
Set<String> subProtocols,
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. |
void |
close()
Forcibly closes the
WebSocketChannel. |
protected abstract StreamSinkFrameChannel |
createStreamSinkChannel(org.xnio.channels.StreamSinkChannel channel,
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) |
org.xnio.Pool<ByteBuffer> |
getBufferPool()
Get the buffer pool for this connection.
|
org.xnio.ChannelListener.Setter<? extends WebSocketChannel> |
getCloseSetter() |
InetSocketAddress |
getDestinationAddress()
Get the destination address of the WebSocket Channel.
|
long |
getIdleTimeout() |
org.xnio.XnioIoThread |
getIoThread() |
SocketAddress |
getLocalAddress() |
<A extends SocketAddress> |
getLocalAddress(Class<A> type) |
<T> T |
getOption(org.xnio.Option<T> option) |
SocketAddress |
getPeerAddress() |
<A extends SocketAddress> |
getPeerAddress(Class<A> type) |
org.xnio.ChannelListener.Setter<WebSocketChannel> |
getReceiveSetter()
Return the
ChannelListener.Setter which will holds the ChannelListener that gets notified once a frame was
received. |
String |
getRequestScheme()
Get the request URI scheme.
|
InetSocketAddress |
getSourceAddress()
Get the source address of the WebSocket Channel.
|
Set<String> |
getSubProtocols()
Returns an unmodifiable
Set of the selected subprotocols if any. |
String |
getUrl()
Return the URL of the WebSocket endpoint.
|
WebSocketVersion |
getVersion()
Return the
WebSocketVersion which is used |
org.xnio.XnioWorker |
getWorker() |
boolean |
isClient() |
boolean |
isCloseFrameReceived() |
boolean |
isCloseFrameSent() |
boolean |
isOpen() |
boolean |
isSecure()
Return
true if this is handled via WebSocket Secure. |
StreamSourceFrameChannel |
receive()
Async receive, returns null if no frame is ready.
|
protected abstract WebSocketChannel.PartialFrame |
receiveFrame(WebSocketChannel.StreamSourceChannelControl streamSourceChannelControl)
Create a new
StreamSourceFrameChannel which can be used to read the data of the received WebSocket Frame |
void |
resumeReceives()
Resume the receive of new frames via
receive() |
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
|
FragmentedMessageChannel |
sendFragmentedBinary()
Return a
FragmentedMessageChannel which can be used t send a BINARY WebSocket message in fragments. |
FragmentedMessageChannel |
sendFragmentedText()
Return a
FragmentedMessageChannel which can be used t send a TEXT WebSocket message in fragments. |
boolean |
setAttribute(String key,
Object value) |
void |
setIdleTimeout(long timeout) |
<T> T |
setOption(org.xnio.Option<T> option,
T value) |
boolean |
supportsOption(org.xnio.Option<?> option) |
void |
suspendReceives()
Suspend the receive of new frames via
receive() |
protected WebSocketChannel(org.xnio.StreamConnection connectedStreamChannel,
org.xnio.Pool<ByteBuffer> bufferPool,
WebSocketVersion version,
String wsUrl,
Set<String> subProtocols,
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 WebSocketChannelwsUrl - The url for which the WebSocket00Channel was created.client - public boolean areExtensionsSupported()
true if extensions are supported by this WebSocket Channel.public Set<String> getSubProtocols()
Set of the selected subprotocols if any.public org.xnio.Pool<ByteBuffer> getBufferPool()
public SocketAddress getLocalAddress()
getLocalAddress in interface org.xnio.channels.BoundChannelpublic <A extends SocketAddress> A getLocalAddress(Class<A> type)
getLocalAddress in interface org.xnio.channels.BoundChannelpublic org.xnio.XnioWorker getWorker()
getWorker in interface org.xnio.channels.CloseableChannelpublic org.xnio.XnioIoThread getIoThread()
getIoThread in interface org.xnio.channels.CloseableChannelpublic boolean supportsOption(org.xnio.Option<?> option)
supportsOption in interface org.xnio.channels.Configurablepublic <T> T getOption(org.xnio.Option<T> option)
throws IOException
getOption in interface org.xnio.channels.ConfigurableIOExceptionpublic <T> T setOption(org.xnio.Option<T> option,
T value)
throws IOException
setOption in interface org.xnio.channels.ConfigurableIOExceptionpublic boolean isCloseFrameReceived()
public boolean isCloseFrameSent()
public SocketAddress getPeerAddress()
getPeerAddress in interface org.xnio.channels.ConnectedChannelpublic <A extends SocketAddress> A getPeerAddress(Class<A> type)
getPeerAddress in interface org.xnio.channels.ConnectedChannelpublic 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()
public InetSocketAddress getDestinationAddress()
public StreamSourceFrameChannel receive() throws IOException
IOExceptionpublic org.xnio.ChannelListener.Setter<WebSocketChannel> getReceiveSetter()
ChannelListener.Setter which will holds the ChannelListener that gets notified once a frame was
received.public void suspendReceives()
receive()public boolean isClient()
public void resumeReceives()
receive()public void close()
throws IOException
WebSocketChannel. Generally clients will wish to use sendClose() for
a clean shutdownclose in interface Closeableclose in interface AutoCloseableclose in interface Channelclose in interface InterruptibleChannelclose in interface org.xnio.channels.CloseableChannelIOExceptionpublic 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.IOExceptionpublic final FragmentedMessageChannel sendFragmentedText()
FragmentedMessageChannel which can be used t send a TEXT WebSocket message in fragments.
This means the first fragment will be send as TEXT frame and the following as CONTINUATION frames.
If this method is called multiple times, subsequent FragmentedMessageChannel's will not be writable until all previous frames
were completely written.public final FragmentedMessageChannel sendFragmentedBinary()
FragmentedMessageChannel which can be used t send a BINARY WebSocket message in fragments.
This means the first fragment will be send as TEXT frame and the following as CONTINUATION frames.
If this method is called multiple times, subsequent FragmentedMessageChannel's will not be writable until all previous frames
were completely written.public void sendClose()
throws IOException
IOExceptionpublic org.xnio.ChannelListener.Setter<? extends WebSocketChannel> getCloseSetter()
getCloseSetter in interface org.xnio.channels.BoundChannelgetCloseSetter in interface org.xnio.channels.CloseableChannelgetCloseSetter in interface org.xnio.channels.ConnectedChannelprotected abstract WebSocketChannel.PartialFrame receiveFrame(WebSocketChannel.StreamSourceChannelControl streamSourceChannelControl)
StreamSourceFrameChannel which can be used to read the data of the received WebSocket FramestreamSourceChannelControl@return - channel A StreamSourceFrameChannel 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 abstract StreamSinkFrameChannel createStreamSinkChannel(org.xnio.channels.StreamSinkChannel channel, WebSocketFrameType type, long payloadSize)
WebSocketFrameType.channel - The StreamSinkChannel to wraptype - The WebSocketFrameType of the WebSocketFrame which will be send over this StreamSinkFrameChannelpayloadSize - The size of the payload to transmit. May be 0 if non payload at all should be included.public void setIdleTimeout(long timeout)
public long getIdleTimeout()
Copyright © 2013 JBoss by Red Hat. All Rights Reserved.