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 ConnectedChannel
ConnectedChannel
which can be used to send and receive Frames.
This provides a common base for framed protocols such as websockets and SPDY
EMPTY
Modifier | Constructor and Description |
---|---|
protected |
AbstractFramedChannel(StreamConnection connectedStreamChannel,
ByteBufferPool bufferPool,
FramePriority<C,R,S> framePriority,
PooledByteBuffer readData,
OptionMap settings)
Create a new
AbstractFramedChannel
8 |
Modifier and Type | Method and Description |
---|---|
void |
addCloseTask(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(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.
|
ChannelListener.Setter<? extends AbstractFramedChannel> |
getCloseSetter()
Get the setter which can be used to change the close listener for this channel.
|
InetSocketAddress |
getDestinationAddress()
Get the destination address of the Channel.
|
protected FramePriority<C,R,S> |
getFramePriority() |
long |
getIdleTimeout() |
XnioIoThread |
getIoThread()
Get the I/O thread associated with this channel.
|
SocketAddress |
getLocalAddress()
Get the local address that this channel is bound to.
|
<A extends SocketAddress> |
getLocalAddress(Class<A> type)
Get the local address of a given type, or
null if the address is not of that
type. |
<T> T |
getOption(Option<T> option)
Get the value of a channel option.
|
SocketAddress |
getPeerAddress()
Get the peer address of this channel.
|
<A extends SocketAddress> |
getPeerAddress(Class<A> type)
Get the peer address of a given type, or
null if the address is not of that
type. |
ChannelListener.Setter<C> |
getReceiveSetter()
Return the
ChannelListener.Setter which will holds the ChannelListener that gets notified once a frame was
received. |
protected OptionMap |
getSettings() |
InetSocketAddress |
getSourceAddress()
Get the source address of the Channel.
|
protected StreamConnection |
getUnderlyingConnection() |
XnioWorker |
getWorker()
Get the worker for this channel.
|
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(Option<T> option,
T value)
Set an option for this channel.
|
void |
setRequireExplicitFlush(boolean requireExplicitFlush) |
boolean |
supportsOption(Option<?> option)
Determine whether an option is supported on this channel.
|
void |
suspendReceives()
Suspend the receive of new frames via
receive() |
String |
toString() |
protected ChannelExceptionHandler<SuspendableWriteChannel> |
writeExceptionHandler() |
protected AbstractFramedChannel(StreamConnection connectedStreamChannel, ByteBufferPool bufferPool, FramePriority<C,R,S> framePriority, PooledByteBuffer readData, 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(StreamConnection connectedStreamChannel)
public ByteBufferPool getBufferPool()
public SocketAddress getLocalAddress()
BoundChannel
getLocalAddress
in interface BoundChannel
public <A extends SocketAddress> A getLocalAddress(Class<A> type)
BoundChannel
null
if the address is not of that
type.getLocalAddress
in interface BoundChannel
A
- the address typetype
- the address type classnull
if unknownpublic XnioWorker getWorker()
CloseableChannel
getWorker
in interface CloseableChannel
public XnioIoThread getIoThread()
CloseableChannel
getIoThread
in interface CloseableChannel
public boolean supportsOption(Option<?> option)
Configurable
supportsOption
in interface Configurable
option
- the optiontrue
if it is supportedpublic <T> T getOption(Option<T> option) throws IOException
Configurable
getOption
in interface Configurable
T
- the type of the option valueoption
- the option to getnull
if it is not setIOException
- if an I/O error occurred when reading the optionpublic <T> T setOption(Option<T> option, T value) throws IOException
Configurable
setOption
in interface Configurable
T
- the type of the option valueoption
- the option to setvalue
- the value of the option to setIOException
- if an I/O error occurred when modifying the optionpublic SocketAddress getPeerAddress()
ConnectedChannel
getPeerAddress
in interface ConnectedChannel
public <A extends SocketAddress> A getPeerAddress(Class<A> type)
ConnectedChannel
null
if the address is not of that
type.getPeerAddress
in interface ConnectedChannel
type
- the address type classnull
if unknownpublic 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 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 CloseableChannel
IOException
- if the close failedpublic ChannelListener.Setter<? extends AbstractFramedChannel> getCloseSetter()
ConnectedChannel
getCloseSetter
in interface BoundChannel
getCloseSetter
in interface CloseableChannel
getCloseSetter
in interface 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()
public void setIdleTimeout(long timeout)
public long getIdleTimeout()
protected FramePriority<C,R,S> getFramePriority()
public void addCloseTask(ChannelListener<C> task)
protected StreamConnection getUnderlyingConnection()
protected ChannelExceptionHandler<SuspendableWriteChannel> writeExceptionHandler()
public boolean isRequireExplicitFlush()
public void setRequireExplicitFlush(boolean requireExplicitFlush)
protected OptionMap getSettings()
Copyright © 2017 JBoss by Red Hat. All rights reserved.