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 SPDY
Modifier | Constructor and Description |
---|---|
protected | AbstractFramedChannel(org.xnio.StreamConnection connectedStreamChannel, ByteBufferPool bufferPool, FramePriority<C,R,S> framePriority, PooledByteBuffer readData, org.xnio.OptionMap settings) Create a new AbstractFramedChannel 8 |
Modifier and Type | Method and Description |
---|---|
void | addCloseTask(org.xnio.ChannelListener<C> task) |
void | close() Forcibly closes the AbstractFramedChannel . |
protected abstract void | closeSubChannels() Method that is called when the channel is being forcibly closed, and all sub stream sink/source channels should also be forcibly closed. |
protected abstract R | createChannel(FrameHeaderData frameHeaderData, PooledByteBuffer frameData) Method that creates the actual stream source channel implementation that is in use. |
protected IdleTimeoutConduit | createIdleTimeoutChannel(org.xnio.StreamConnection connectedStreamChannel) |
void | flush() |
protected void | flushSenders() Flushes all ready stream sink conduits to the channel. |
ByteBufferPool | 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) |
protected abstract Collection<AbstractFramedStreamSourceChannel<C,R,S>> | getReceivers() |
org.xnio.ChannelListener.Setter<C> | getReceiveSetter() Return the ChannelListener.Setter which will holds the ChannelListener that gets notified once a frame was received. |
protected org.xnio.OptionMap | getSettings() |
InetSocketAddress | getSourceAddress() Get the source address of the Channel. |
protected org.xnio.StreamConnection | getUnderlyingConnection() |
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() |
boolean | isRequireExplicitFlush() |
protected boolean | isWritesBroken() |
protected void | lastDataRead() Method than is invoked when read() returns -1. |
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. |
protected void | recalculateHeldFrames() |
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) |
void | setRequireExplicitFlush(boolean requireExplicitFlush) |
boolean | supportsOption(org.xnio.Option<?> option) |
void | suspendReceives() Suspend the receive of new frames via receive() |
String | toString() |
protected org.xnio.ChannelExceptionHandler<org.xnio.channels.SuspendableWriteChannel> | writeExceptionHandler() |
protected AbstractFramedChannel(org.xnio.StreamConnection connectedStreamChannel, ByteBufferPool bufferPool, FramePriority<C,R,S> framePriority, PooledByteBuffer readData, org.xnio.OptionMap settings)
AbstractFramedChannel
8connectedStreamChannel
- The ConnectedStreamChannel
over which the Frames should get send and received. Be aware that it already must be "upgraded".bufferPool
- The ByteBufferPool
which will be used to acquire ByteBuffer
's from.framePriority
- settings
- The settingsprotected IdleTimeoutConduit createIdleTimeoutChannel(org.xnio.StreamConnection connectedStreamChannel)
public ByteBufferPool 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
Calling this method can also have the side effect of making additional data available to existing source channels. In general if you suspend receives or don't have some other way of calling this method then it can prevent frame channels for being fully consumed.
IOException
protected void lastDataRead()
protected abstract R createChannel(FrameHeaderData frameHeaderData, PooledByteBuffer frameData) throws IOException
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 contentsIOException
protected 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 recalculateHeldFrames() throws IOException
IOException
protected void flushSenders()
Frames will be batched up, to allow them all to be written out via a gathering write. The framePriority
implementation will be invoked to decide which frames are eligible for sending and in what order.
protected void queueFrame(S channel) throws IOException
Depending on the FramePriority
implementation in use the channel may or may not be added to the actual pending queue
channel
- The channelIOException
public void flush()
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
.close
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)
The underlying read side will be forcibly closed.
cause
- The possibly null causeprotected abstract void closeSubChannels()
protected void markWritesBroken(Throwable cause)
The underlying channel will be closed, and any sub channels that have writes resumed will have their listeners notified. It is expected that these listeners will then attempt to use the channel, and their standard error handling logic will take over.
cause
- The possibly null causeprotected boolean isWritesBroken()
protected boolean isReadsBroken()
protected abstract Collection<AbstractFramedStreamSourceChannel<C,R,S>> getReceivers()
public void setIdleTimeout(long timeout)
public long getIdleTimeout()
protected FramePriority<C,R,S> getFramePriority()
public void addCloseTask(org.xnio.ChannelListener<C> task)
protected org.xnio.StreamConnection getUnderlyingConnection()
protected org.xnio.ChannelExceptionHandler<org.xnio.channels.SuspendableWriteChannel> writeExceptionHandler()
public boolean isRequireExplicitFlush()
public void setRequireExplicitFlush(boolean requireExplicitFlush)
protected org.xnio.OptionMap getSettings()
Copyright © 2020 JBoss by Red Hat. All rights reserved.