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

public abstract Class AbstractFramedStreamSinkChannel<C extends AbstractFramedChannel<C, R, S>, R extends AbstractFramedStreamSourceChannel<C, R, S>, S extends AbstractFramedStreamSinkChannel<C, R, S>>

extends Object
implements StreamSinkChannel
Class Inheritance
All Implemented Interfaces
org.xnio.channels.StreamSinkChannel, org.xnio.channels.SuspendableWriteChannel, org.xnio.channels.CloseableChannel, org.xnio.channels.Configurable, java.nio.channels.InterruptibleChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.GatheringByteChannel, java.nio.channels.WritableByteChannel
Known Direct Subclasses
io.undertow.websockets.core.StreamSinkFrameChannel, io.undertow.protocols.ajp.AbstractAjpClientStreamSinkChannel, io.undertow.protocols.http2.AbstractHttp2StreamSinkChannel
Imports
java.io.IOException, .InterruptedIOException, java.nio.ByteBuffer, java.nio.channels.FileChannel, java.security.AccessController, .PrivilegedAction, java.util.concurrent.TimeUnit, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, io.undertow.UndertowLogger, .UndertowMessages, io.undertow.connector.PooledByteBuffer, io.undertow.util.ImmediatePooledByteBuffer, org.xnio.Buffers, .ChannelListener, .ChannelListeners, .IoUtils, .Option, .Options, .XnioExecutor, .XnioIoThread, .XnioWorker, org.xnio.channels.Channels, .StreamSinkChannel, .StreamSourceChannel

Framed Stream Sink Channel.

Thread safety notes:

The general contract is that this channel is only to be used by a single thread at a time. The only exception to this is during flush. A flush will only happen when readyForFlush is set, and while this bit is set the buffer must not be modified.

Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
AbstractFramedStreamSinkChannel.TimeoutRunnable

Runnable used to execute the timeout and avoid hangs if the other end does not read the data and the flush is not performed.

Field Summary

Modifier and TypeField and Description
private static final int
AWAIT_WRITABLE_TIMEOUT

The maximum timeout to wait on awaitWritable in milliseconds when not specified.

private volatile PooledByteBuffer
private volatile boolean
broken

If this channel is broken, updated by multiple threads

private volatile boolean
private final C
private final ChannelListener.SimpleSetter<S>
private static final PooledByteBuffer
private volatile boolean
finalFrameQueued

If the last frame has been queued.

private volatile long
flushExpirationTime

Expiration time for flushing the frame.

private volatile boolean
fullyFlushed

If all the data has been written out and the channel has been fully flushed

private static final int
FUZZ_FACTOR

Extra timeout to make sure the flush has actually timed out

private volatile XnioExecutor.Key
handle

handle to control the time we are waiting for flushing.

private volatile SendFrameHeader
private volatile int
private static final AtomicIntegerFieldUpdater<AbstractFramedStreamSinkChannel<C extends AbstractFramedChannel<C, R, S>, R extends AbstractFramedStreamSourceChannel<C, R, S>, S extends AbstractFramedStreamSinkChannel<C, R, S>>>
private final Object
private volatile boolean
readyForFlush

If this channel is ready for flush, updated by multiple threads.

private volatile int
state

the state variable, this must only be access by the thread that 'owns' the channel

private static final int
private static final int
private static final int
private static final int
private final AbstractFramedStreamSinkChannel.TimeoutRunnable
timeoutRunnable

The timeout runnable to use for the handle.

private volatile int
private volatile PooledByteBuffer
private final ChannelListener.SimpleSetter<S>
private volatile boolean
private volatile boolean

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
private void
addHandle(long timeout)

pack-priv void
addReadyForFlushTask()

Adds the timeout task waiting for flushing.

public void
awaitWritable()

Implements org.xnio.channels.SuspendableWriteChannel.awaitWritable.

Block until this channel becomes writable again.

public void
awaitWritable(long
the time to wait
l
,
TimeUnit
the time unit
timeUnit
)

Implements org.xnio.channels.SuspendableWriteChannel.awaitWritable.

Block until this channel becomes writable again, or until the timeout expires.

protected void
channelForciblyClosed()

Called when a channel has been forcibly closed, and data (frames) have already been written.

public void
protected SendFrameHeader
public boolean
flush()

Implements org.xnio.channels.SuspendableWriteChannel.flush.

Flush any waiting partial send or write.

pack-priv final void
flushComplete()

Method that is invoked when a frame has been fully flushed.

protected long

Returns:

the awaitWritable timeout, in milliseconds
getAwaitWritableTimeout
()

Return the timeout used by awaitWritable and flush tasks.

public ByteBuffer
public C
public ChannelListener.Setter<? extends S>
getCloseSetter()

Implements org.xnio.channels.StreamSinkChannel.getCloseSetter.

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

pack-priv final SendFrameHeader

Returns:

The header for the current frame, or null
getFrameHeader
()

Returns the header for the current frame.

public XnioIoThread
getIoThread()

Implements org.xnio.channels.CloseableChannel.getIoThread.

Get the I/O thread associated with this channel.

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

Implements org.xnio.channels.Configurable.getOption.

Get the value of a channel option.

public XnioWorker
getWorker()

Implements org.xnio.channels.CloseableChannel.getWorker.

Get the worker for this channel.

pack-priv ChannelListener<? super S>
public ChannelListener.Setter<? extends S>
getWriteSetter()

Implements org.xnio.channels.StreamSinkChannel.getWriteSetter.

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

public XnioExecutor
getWriteThread()

Implements org.xnio.channels.SuspendableWriteChannel.getWriteThread.

Get the write thread for this channel.

private void
protected void
handleFlushComplete(boolean finalFrame)

public boolean
public boolean
protected boolean
protected boolean
protected boolean
protected abstract boolean

Returns:

true If this is the last frame that will be sent on this connection
isLastFrame
()

public boolean
public boolean

Returns:

true if the channel is ready to be flushed. When a channel is ready to be flushed nothing should modify the buffer, as it may be written out by another thread.
isReadyForFlush
()

public boolean
isWriteResumed()

Implements org.xnio.channels.SuspendableWriteChannel.isWriteResumed.

Determine whether writes are resumed.

public boolean
isWritesShutdown()

Returns true writes have been shutdown

public void
pack-priv final void
protected PooledByteBuffer
private void
private void
public void
resumeWrites()

Implements org.xnio.channels.SuspendableWriteChannel.resumeWrites.

Resume writes on this channel.

protected void
resumeWritesInternal(boolean wakeup)

protected boolean
public boolean

Returns:

true if the buffer was accepted; false if the channel needs to first be flushed
send
(PooledByteBuffer
Pooled ByteBuffer to send. The buffer should have data available. This channel will free the buffer after sending data
pooled
)

Send a buffer to this channel.

protected boolean
private void
public <T> T
setOption(Option<T>
the option to set
tOption
,
T
the value of the option to set
t
)

Implements org.xnio.channels.Configurable.setOption.

Set an option for this channel.

public void
shutdownWrites()

Implements org.xnio.channels.SuspendableWriteChannel.shutdownWrites.

Indicate that writing is complete for this channel.

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

Implements org.xnio.channels.Configurable.supportsOption.

Determine whether an option is supported on this channel.

public void
suspendWrites()

Implements org.xnio.channels.SuspendableWriteChannel.suspendWrites.

Suspend further write notifications on this channel.

public long
transferFrom(final FileChannel
the file to read from
src
,
final long
the position within the file from which the transfer is to begin
position
,
final long
the number of bytes to be transferred
count
)

Implements org.xnio.channels.StreamSinkChannel.transferFrom.

Transfer bytes into this channel from the given file.

public long
transferFrom(final StreamSourceChannel
the source to read from
source
,
final long
the number of bytes to be transferred
count
,
final ByteBuffer
the buffer to copy through.
throughBuffer
)

Implements org.xnio.channels.StreamSinkChannel.transferFrom.

Transfers bytes from the given channel source.

private void
public void
wakeupWrites()

Implements org.xnio.channels.SuspendableWriteChannel.wakeupWrites.

Resume writes on this channel, and force the write listener to be triggered even if the channel isn't actually writable.

public long
write(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
,
int
The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length
offset
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
length
)

Implements java.nio.channels.GatheringByteChannel.write.

Writes a sequence of bytes to this channel from a subsequence of the given buffers.

public long
write(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
)

Implements java.nio.channels.GatheringByteChannel.write.

Writes a sequence of bytes to this channel from the given buffers.

public int
write(ByteBuffer
The buffer from which bytes are to be retrieved
src
)

Implements java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

public long
writeFinal(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
,
int
The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length
offset
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
length
)

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, with the same semantics as write(java.nio.ByteBuffer[], int, int).

public long
writeFinal(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
)

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, with the same semantics as write(java.nio.ByteBuffer[]).

public int
writeFinal(ByteBuffer
The data to write
src
)

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, with the same semantics as write(java.nio.ByteBuffer).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait