Top Description Inners Fields Constructors Methods
io.undertow.server.protocol.framed

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
Class Inheritance
All Implemented Interfaces
org.xnio.channels.ConnectedChannel, org.xnio.channels.BoundChannel, org.xnio.channels.CloseableChannel, org.xnio.channels.Configurable, java.nio.channels.InterruptibleChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
io.undertow.websockets.core.WebSocketChannel, io.undertow.protocols.ajp.AjpClientChannel, io.undertow.protocols.http2.Http2Channel
Static Imports
org.xnio.IoUtils.safeClose

A org.xnio.channels.ConnectedChannel which can be used to send and receive Frames.

This provides a common base for framed protocols such as websockets and SPDY

Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
AbstractFramedChannel.FrameCloseListener

close listener, just goes through and activates any sub channels to make sure their listeners are invoked

private class
AbstractFramedChannel.FrameReadListener

org.xnio.ChannelListener which delegates the read notification to the appropriate listener

private class
private class

Field Summary

Modifier and TypeField and Description
private final ByteBufferPool
private final StreamConnection
private final ChannelListener.SimpleSetter<C>
private final List<ChannelListener<C>>
private static final ChannelListener<AbstractFramedChannel<C extends AbstractFramedChannel<C, R, S>, R extends AbstractFramedStreamSourceChannel<C, R, S>, S extends AbstractFramedStreamSinkChannel<C, R, S>>>
private volatile boolean
private volatile long
private final FramePriority<C, R, S>
framePriority

Frame priority implementation.

private final ReferenceCountedPooled.FreeNotifier
private final Deque<S>
heldFrames

Frames that are not yet read to send.

private final IdleTimeoutConduit
private final Object
private final int
maxQueuedBuffers

The maximum number of buffers we will queue before suspending reads and waiting for the buffers to be consumed

Todo

make the configurable

private final Deque<S>
newFrames

new frames to be sent.

private volatile int
private static final AtomicIntegerFieldUpdater<AbstractFramedChannel<C extends AbstractFramedChannel<C, R, S>, R extends AbstractFramedStreamSourceChannel<C, R, S>, S extends AbstractFramedStreamSinkChannel<C, R, S>>>
private boolean
private final List<S>
pendingFrames

List of frames that are ready to send

private final int
private final int
private volatile boolean
private volatile ReferenceCountedPooled
private volatile int
private static final AtomicIntegerFieldUpdater<AbstractFramedChannel<C extends AbstractFramedChannel<C, R, S>, R extends AbstractFramedStreamSourceChannel<C, R, S>, S extends AbstractFramedStreamSinkChannel<C, R, S>>>
private volatile R
private final ChannelListener.SimpleSetter<C>
private volatile boolean
private volatile boolean
private volatile boolean
private volatile boolean
requireExplicitFlush

If this is true then the flush() method must be called to queue writes.

private final OptionMap
private final LinkedBlockingDeque<Runnable>
private final Runnable
private volatile int
private static final AtomicIntegerFieldUpdater<AbstractFramedChannel<C extends AbstractFramedChannel<C, R, S>, R extends AbstractFramedStreamSourceChannel<C, R, S>, S extends AbstractFramedStreamSinkChannel<C, R, S>>>

Constructor Summary

AccessConstructor and Description
protected
AbstractFramedChannel(final StreamConnection
The org.xnio.channels.ConnectedStreamChannel over which the Frames should get send and received. Be aware that it already must be "upgraded".
connectedStreamChannel
,
ByteBufferPool
The ByteBufferPool which will be used to acquire ByteBuffer's from.
bufferPool
,
FramePriority<C, R, S> framePriority, final PooledByteBuffer readData, OptionMap
The settings
settings
)

Create a new io.undertow.server.protocol.framed.AbstractFramedChannel 8

Method Summary

Modifier and TypeMethod and Description
public void
private ReferenceCountedPooled
pack-priv void
pack-priv void
awaitWritable(long time, TimeUnit unit)

public void
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

Returns:

A new stream source channel
createChannel
(FrameHeaderData
The header data, as returned by parseFrame(java.nio.ByteBuffer)
frameHeaderData
,
PooledByteBuffer
Any additional data for the frame that has already been read. This may not be the complete frame contents
frameData
)

Method that creates the actual stream source channel implementation that is in use.

protected IdleTimeoutConduit
private void
public void
protected synchronized void
flushSenders()

Flushes all ready stream sink conduits to the channel.

public ByteBufferPool

Returns:

the buffer pool for this connection
getBufferPool
()

Get the buffer pool for this connection.

public ChannelListener.Setter<? extends AbstractFramedChannel<C extends AbstractFramedChannel<C, R, S>, R extends AbstractFramedStreamSourceChannel<C, R, S>, S extends AbstractFramedStreamSinkChannel<C, R, S>>>
getCloseSetter()

Implements org.xnio.channels.ConnectedChannel.getCloseSetter.

Get the setter which can be used to change the close listener for this channel.

public InetSocketAddress

Returns:

the destination address of the Channel
getDestinationAddress
()

Get the destination address of the Channel.

protected FramePriority<C, R, S>
public long
public XnioIoThread
getIoThread()

Implements org.xnio.channels.CloseableChannel.getIoThread.

Get the I/O thread associated with this channel.

public SocketAddress
getLocalAddress()

Implements org.xnio.channels.BoundChannel.getLocalAddress.

Get the local address that this channel is bound to.

public <A extends SocketAddress> A
getLocalAddress(Class<A>
the address type class
type
)

Implements org.xnio.channels.BoundChannel.getLocalAddress.

Get the local address of a given type, or null if the address is not of that type.

public <T> T
getOption(Option<T>
the option to get
option
)

Implements org.xnio.channels.Configurable.getOption.

Get the value of a channel option.

public SocketAddress
getPeerAddress()

Implements org.xnio.channels.ConnectedChannel.getPeerAddress.

Get the peer address of this channel.

public <A extends SocketAddress> A
getPeerAddress(Class<A>
the address type class
type
)

Implements org.xnio.channels.ConnectedChannel.getPeerAddress.

Get the peer address of a given type, or null if the address is not of that type.

protected abstract Collection<AbstractFramedStreamSourceChannel<C, R, S>>
public ChannelListener.Setter<C>
getReceiveSetter()

Return the org.xnio.ChannelListener.Setter which will holds the org.xnio.ChannelListener that gets notified once a frame was received.

protected OptionMap
public InetSocketAddress

Returns:

the source address of the Channel
getSourceAddress
()

Get the source address of the Channel.

pack-priv StreamSourceChannel
protected StreamConnection
public XnioWorker
getWorker()

Implements org.xnio.channels.CloseableChannel.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.

private void
handleLastFrame(AbstractFramedStreamSourceChannel<C extends AbstractFramedChannel<C, R, S>, R extends AbstractFramedStreamSourceChannel<C, R, S>, S extends AbstractFramedStreamSinkChannel<C, R, S>>
The channel that received the last frame
newChannel
)

Called when the last frame has been received (note that their may still be data from the last frame than needs to be read)

protected abstract boolean

Returns:

true If the last frame has been received
isLastFrameReceived
()

Returns true if the protocol specific final frame has been received.

protected abstract boolean

Returns:

true If the last frame has been sent
isLastFrameSent
()

public boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

protected boolean
private boolean
public boolean
public boolean
protected boolean
protected void
lastDataRead()

Method than is invoked when read() returns -1.

protected void
markReadsBroken(Throwable
The possibly null cause
cause
)

Called when a source sub channel fails to fulfil its contract, and leaves the channel in an inconsistent state.

protected void
markWritesBroken(Throwable
The possibly null cause
cause
)

Called when a sub channel fails to fulfil its contract, and leaves the channel in an inconsistent state.

pack-priv void
protected abstract FrameHeaderData

Returns:

The frame header data, or null if the data was incomplete
parseFrame
(ByteBuffer
The data that has been read from the channel
data
)

Attempts to parse an incoming frame header from the data in the buffer.

protected void
queueFrame(final S
The channel
channel
)

Queues a new frame to be sent, and attempts a flush if this is the first frame in the new frame queue.

protected synchronized void
public synchronized R
receive()

Receive method, returns null if no frame is ready.

public synchronized void
resumeReceives()

Resume the receive of new frames via receive()

pack-priv void
pack-priv void
runInIoThread(Runnable
The task to be executed in the IO thread
task
)

Adds the task to the queue and executes the IO thread runner.

pack-priv void
runNowOrInIoThread(Runnable
The task to be executed in the IO thread
task
)

Executes the task in IO thread now if the current thread is the IO thread or schedules it calling method runInIoThread.

public void
setIdleTimeout(long timeout)

public <T> T
setOption(Option<T>
the option to set
option
,
T
the value of the option to set
value
)

Implements org.xnio.channels.Configurable.setOption.

Set an option for this channel.

public void
setRequireExplicitFlush(boolean requireExplicitFlush)

public boolean
supportsOption(Option<?>
the option
option
)

Implements org.xnio.channels.Configurable.supportsOption.

Determine whether an option is supported on this channel.

public synchronized void
suspendReceives()

Suspend the receive of new frames via receive()

pack-priv void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv void
protected ChannelExceptionHandler<SuspendableWriteChannel>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait