public abstract class AbstractFramedChannel<C extends AbstractFramedChannel<C,R,S>,R extends AbstractFramedStreamSourceChannel<C,R,S>,S extends AbstractFramedStreamSinkChannel<C,R,S>> extends Object implements org.xnio.channels.ConnectedChannel
ConnectedChannel
which can be used to send and receive Frames.
This provides a common base for framed protocols such as websockets and SPDYModifier | Constructor and Description |
---|---|
protected |
AbstractFramedChannel(org.xnio.StreamConnection connectedStreamChannel,
org.xnio.Pool<ByteBuffer> bufferPool,
FramePriority<C,R,S> framePriority)
Create a new
AbstractFramedChannel
8 |
Modifier and Type | Method and Description |
---|---|
void |
close()
Forcibly closes the
AbstractFramedChannel . |
protected abstract R |
createChannel(FrameHeaderData frameHeaderData,
org.xnio.Pooled<ByteBuffer> frameData)
Method that creates the actual stream source channel implementation that is in use.
|
protected void |
flushSenders()
Flushes all ready stream sink conduits to the channel.
|
org.xnio.Pool<ByteBuffer> |
getBufferPool()
Get the buffer pool for this connection.
|
org.xnio.ChannelListener.Setter<? extends AbstractFramedChannel> |
getCloseSetter() |
InetSocketAddress |
getDestinationAddress()
Get the destination address of the Channel.
|
protected FramePriority<C,R,S> |
getFramePriority() |
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<C> |
getReceiveSetter()
Return the
ChannelListener.Setter which will holds the ChannelListener that gets notified once a frame was
received. |
InetSocketAddress |
getSourceAddress()
Get the source address of the Channel.
|
org.xnio.XnioWorker |
getWorker() |
protected abstract void |
handleBrokenSinkChannel(Throwable e)
Method that is invoked when then write side of a channel is broken.
|
protected abstract void |
handleBrokenSourceChannel(Throwable e)
Method that is invoked when the read side of the channel is broken.
|
protected abstract boolean |
isLastFrameReceived()
Returns true if the protocol specific final frame has been received.
|
protected abstract boolean |
isLastFrameSent() |
boolean |
isOpen() |
protected boolean |
isReadsBroken() |
boolean |
isReceivesResumed() |
protected boolean |
isWritesBroken() |
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 void |
markWritesBroken(Throwable cause)
Called when a sub channel fails to fulfil its contract, and leaves the channel in an inconsistent state.
|
protected abstract FrameHeaderData |
parseFrame(ByteBuffer data)
Attempts to parse an incoming frame header from the data in the buffer.
|
protected void |
queueFrame(S channel)
Queues a new frame to be sent, and attempts a flush if this is the first frame in the new frame queue.
|
R |
receive()
receive method, returns null if no frame is ready.
|
void |
resumeReceives()
Resume the receive of new frames via
receive() |
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() |
String |
toString() |
protected AbstractFramedChannel(org.xnio.StreamConnection connectedStreamChannel, org.xnio.Pool<ByteBuffer> bufferPool, FramePriority<C,R,S> framePriority)
AbstractFramedChannel
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.framePriority
- public org.xnio.Pool<ByteBuffer> getBufferPool()
public SocketAddress getLocalAddress()
getLocalAddress
in interface org.xnio.channels.BoundChannel
public <A extends SocketAddress> A getLocalAddress(Class<A> type)
getLocalAddress
in interface org.xnio.channels.BoundChannel
public org.xnio.XnioWorker getWorker()
getWorker
in interface org.xnio.channels.CloseableChannel
public org.xnio.XnioIoThread getIoThread()
getIoThread
in interface org.xnio.channels.CloseableChannel
public boolean supportsOption(org.xnio.Option<?> option)
supportsOption
in interface org.xnio.channels.Configurable
public <T> T getOption(org.xnio.Option<T> option) throws IOException
getOption
in interface org.xnio.channels.Configurable
IOException
public <T> T setOption(org.xnio.Option<T> option, T value) throws IOException
setOption
in interface org.xnio.channels.Configurable
IOException
public SocketAddress getPeerAddress()
getPeerAddress
in interface org.xnio.channels.ConnectedChannel
public <A extends SocketAddress> A getPeerAddress(Class<A> type)
getPeerAddress
in interface org.xnio.channels.ConnectedChannel
public InetSocketAddress getSourceAddress()
public InetSocketAddress getDestinationAddress()
public R receive() throws IOException
IOException
protected abstract R createChannel(FrameHeaderData frameHeaderData, org.xnio.Pooled<ByteBuffer> frameData)
frameHeaderData
- The header data, as returned by parseFrame(java.nio.ByteBuffer)
frameData
- Any additional data for the frame that has already been read. This may not be the complete frame contentsprotected abstract FrameHeaderData parseFrame(ByteBuffer data) throws IOException
data
- The data that has been read from the channelnull
if the data was incompleteIOException
- If the data could not be parsed.protected void flushSenders() throws IOException
framePriority
implementation will be invoked to decide which
frames are eligible for sending and in what order.IOException
protected void queueFrame(S channel) throws IOException
FramePriority
implementation in use the channel may or may not be added to the actual
pending queuechannel
- The channelIOException
protected abstract boolean isLastFrameReceived()
true
If the last frame has been receivedprotected abstract boolean isLastFrameSent()
true
If the last frame has been sentprotected abstract void handleBrokenSourceChannel(Throwable e)
protected abstract void handleBrokenSinkChannel(Throwable e)
public org.xnio.ChannelListener.Setter<C> getReceiveSetter()
ChannelListener.Setter
which will holds the ChannelListener
that gets notified once a frame was
received.public void suspendReceives()
receive()
public void resumeReceives()
receive()
public boolean isReceivesResumed()
public void close() throws IOException
AbstractFramedChannel
.
a clean shutdownclose
in interface Closeable
close
in interface AutoCloseable
close
in interface Channel
close
in interface InterruptibleChannel
close
in interface org.xnio.channels.CloseableChannel
IOException
public org.xnio.ChannelListener.Setter<? extends AbstractFramedChannel> getCloseSetter()
getCloseSetter
in interface org.xnio.channels.BoundChannel
getCloseSetter
in interface org.xnio.channels.CloseableChannel
getCloseSetter
in interface org.xnio.channels.ConnectedChannel
protected void markReadsBroken(Throwable cause)
cause
- The possibly null causeprotected void markWritesBroken(Throwable cause)
cause
- The possibly null causeprotected boolean isWritesBroken()
protected boolean isReadsBroken()
public void setIdleTimeout(long timeout)
public long getIdleTimeout()
protected FramePriority<C,R,S> getFramePriority()
Copyright © 2014 JBoss by Red Hat. All rights reserved.