io.undertow.server.protocol.framed

## Class AbstractFramedStreamSinkChannel<C extends AbstractFramedChannel<C,R,S>,R extends AbstractFramedStreamSourceChannel<C,R,S>,S extends AbstractFramedStreamSinkChannel<C,R,S>>

- java.lang.Object
- - io.undertow.server.protocol.framed.AbstractFramedStreamSinkChannel<C,R,S>

All Implemented Interfaces:
  Closeable, AutoCloseable, Channel, GatheringByteChannel, InterruptibleChannel, WritableByteChannel, org.xnio.channels.CloseableChannel, org.xnio.channels.Configurable, org.xnio.channels.StreamSinkChannel, org.xnio.channels.SuspendableWriteChannel

Direct Known Subclasses:
  AbstractAjpClientStreamSinkChannel, AbstractHttp2StreamSinkChannel, StreamSinkFrameChannel

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

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

### Field Summary

### Fields inherited from interface org.xnio.channels.Configurable

`EMPTY`

### Constructor Summary

Constructors
`protected` `AbstractFramedStreamSinkChannel(C channel)`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`void` `awaitWritable()`
`void` `awaitWritable(long l, TimeUnit timeUnit)`
`protected void` `channelForciblyClosed()` Called when a channel has been forcibly closed, and data (frames) have already been written.
`void` `close()`
`protected SendFrameHeader` `createFrameHeader()`
`boolean` `flush()`
`protected long` `getAwaitWritableTimeout()` Return the timeout used by awaitWritable.
`ByteBuffer` `getBuffer()`
`C` `getChannel()`
`org.xnio.ChannelListener.Setter<? extends S>` `getCloseSetter()`
`org.xnio.XnioIoThread` `getIoThread()`
`<T> T` `getOption(org.xnio.Option<T> tOption)`
`org.xnio.XnioWorker` `getWorker()`
`org.xnio.ChannelListener.Setter<? extends S>` `getWriteSetter()`
`org.xnio.XnioExecutor` `getWriteThread()`
`protected void` `handleFlushComplete(boolean finalFrame)`
`boolean` `isBroken()`
`boolean` `isBufferFull()`
`protected boolean` `isFinalFrameQueued()`
`protected boolean` `isFirstDataWritten()`
`protected boolean` `isFlushRequiredOnEmptyBuffer()`
`protected abstract boolean` `isLastFrame()`
`boolean` `isOpen()`
`boolean` `isReadyForFlush()`
`boolean` `isWriteResumed()`
`boolean` `isWritesShutdown()` Returns true writes have been shutdown
`void` `markBroken()`
`protected PooledByteBuffer` `preWriteTransform(PooledByteBuffer body)`
`void` `resumeWrites()`
`protected void` `resumeWritesInternal(boolean wakeup)`
`protected boolean` `safeToSend()`
`boolean` `send(PooledByteBuffer pooled)` Send a buffer to this channel.
`protected boolean` `sendInternal(PooledByteBuffer pooled)`
`<T> T` `setOption(org.xnio.Option<T> tOption, T t)`
`void` `shutdownWrites()`
`boolean` `supportsOption(org.xnio.Option<?> option)`
`void` `suspendWrites()`
`long` `transferFrom(FileChannel src, long position, long count)`
`long` `transferFrom(org.xnio.channels.StreamSourceChannel source, long count, ByteBuffer throughBuffer)`
`void` `wakeupWrites()`
`int` `write(ByteBuffer src)`
`long` `write(ByteBuffer[] srcs)`
`long` `write(ByteBuffer[] srcs, int offset, int length)`
`int` `writeFinal(ByteBuffer src)`
`long` `writeFinal(ByteBuffer[] srcs)`
`long` `writeFinal(ByteBuffer[] srcs, int offset, int length)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### AbstractFramedStreamSinkChannel

    protected AbstractFramedStreamSinkChannel(C channel)

### Method Detail

#### transferFrom

    public long transferFrom(FileChannel src,
                             long position,
                             long count)
                      throws IOException

Specified by:
  `transferFrom` in interface `org.xnio.channels.StreamSinkChannel`
Throws:
  `IOException`

#### transferFrom

    public long transferFrom(org.xnio.channels.StreamSourceChannel source,
                             long count,
                             ByteBuffer throughBuffer)
                      throws IOException

Specified by:
  `transferFrom` in interface `org.xnio.channels.StreamSinkChannel`
Throws:
  `IOException`

#### suspendWrites

    public void suspendWrites()

Specified by:
  `suspendWrites` in interface `org.xnio.channels.SuspendableWriteChannel`

#### createFrameHeader

    protected SendFrameHeader createFrameHeader()
                                         throws IOException

Throws:
  `IOException`

#### preWriteTransform

    protected PooledByteBuffer preWriteTransform(PooledByteBuffer body)

#### isWriteResumed

    public boolean isWriteResumed()

Specified by:
  `isWriteResumed` in interface `org.xnio.channels.SuspendableWriteChannel`

#### wakeupWrites

    public void wakeupWrites()

Specified by:
  `wakeupWrites` in interface `org.xnio.channels.SuspendableWriteChannel`

#### resumeWrites

    public void resumeWrites()

Specified by:
  `resumeWrites` in interface `org.xnio.channels.SuspendableWriteChannel`

#### resumeWritesInternal

    protected void resumeWritesInternal(boolean wakeup)

#### shutdownWrites

    public void shutdownWrites()
                        throws IOException

Specified by:
  `shutdownWrites` in interface `org.xnio.channels.SuspendableWriteChannel`
Throws:
  `IOException`

#### isFinalFrameQueued

    protected boolean isFinalFrameQueued()

#### awaitWritable

    public void awaitWritable()
                       throws IOException

Specified by:
  `awaitWritable` in interface `org.xnio.channels.SuspendableWriteChannel`
Throws:
  `IOException`

#### awaitWritable

    public void awaitWritable(long l,
                              TimeUnit timeUnit)
                       throws IOException

Specified by:
  `awaitWritable` in interface `org.xnio.channels.SuspendableWriteChannel`
Throws:
  `IOException`

#### getWriteThread

    public org.xnio.XnioExecutor getWriteThread()

Specified by:
  `getWriteThread` in interface `org.xnio.channels.SuspendableWriteChannel`

#### getWriteSetter

    public org.xnio.ChannelListener.Setter<? extends S> getWriteSetter()

Specified by:
  `getWriteSetter` in interface `org.xnio.channels.StreamSinkChannel`
Specified by:
  `getWriteSetter` in interface `org.xnio.channels.SuspendableWriteChannel`

#### getCloseSetter

    public org.xnio.ChannelListener.Setter<? extends S> getCloseSetter()

Specified by:
  `getCloseSetter` in interface `org.xnio.channels.CloseableChannel`
Specified by:
  `getCloseSetter` in interface `org.xnio.channels.StreamSinkChannel`
Specified by:
  `getCloseSetter` in interface `org.xnio.channels.SuspendableWriteChannel`

#### getWorker

    public org.xnio.XnioWorker getWorker()

Specified by:
  `getWorker` in interface `org.xnio.channels.CloseableChannel`

#### getIoThread

    public org.xnio.XnioIoThread getIoThread()

Specified by:
  `getIoThread` in interface `org.xnio.channels.CloseableChannel`

#### flush

    public boolean flush()
                  throws IOException

Specified by:
  `flush` in interface `org.xnio.channels.SuspendableWriteChannel`
Throws:
  `IOException`

#### isFlushRequiredOnEmptyBuffer

    protected boolean isFlushRequiredOnEmptyBuffer()

#### write

    public long write(ByteBuffer[] srcs,
                      int offset,
                      int length)
               throws IOException

Specified by:
  `write` in interface `GatheringByteChannel`
Throws:
  `IOException`

#### write

    public long write(ByteBuffer[] srcs)
               throws IOException

Specified by:
  `write` in interface `GatheringByteChannel`
Throws:
  `IOException`

#### write

    public int write(ByteBuffer src)
              throws IOException

Specified by:
  `write` in interface `WritableByteChannel`
Throws:
  `IOException`

#### send

    public boolean send(PooledByteBuffer pooled)
                 throws IOException

Send a buffer to this channel.

Parameters:
  `pooled` - Pooled ByteBuffer to send. The buffer should have data available. This channel will free the buffer after sending data
Returns:
  true if the buffer was accepted; false if the channel needs to first be flushed
Throws:
  `IOException` - if this channel is closed

#### sendInternal

    protected boolean sendInternal(PooledByteBuffer pooled)
                            throws IOException

Throws:
  `IOException`

#### safeToSend

    protected boolean safeToSend()
                          throws IOException

Throws:
  `IOException`

#### getAwaitWritableTimeout

    protected long getAwaitWritableTimeout()

Return the timeout used by awaitWritable.

Returns:
  the awaitWritable timeout, in milliseconds

#### writeFinal

    public long writeFinal(ByteBuffer[] srcs,
                           int offset,
                           int length)
                    throws IOException

Specified by:
  `writeFinal` in interface `org.xnio.channels.StreamSinkChannel`
Throws:
  `IOException`

#### writeFinal

    public long writeFinal(ByteBuffer[] srcs)
                    throws IOException

Specified by:
  `writeFinal` in interface `org.xnio.channels.StreamSinkChannel`
Throws:
  `IOException`

#### writeFinal

    public int writeFinal(ByteBuffer src)
                   throws IOException

Specified by:
  `writeFinal` in interface `org.xnio.channels.StreamSinkChannel`
Throws:
  `IOException`

#### isLastFrame

    protected abstract boolean isLastFrame()

Returns:
  `true` If this is the last frame that will be sent on this connection

#### isReadyForFlush

    public boolean isReadyForFlush()

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.

#### isWritesShutdown

    public boolean isWritesShutdown()

Returns true writes have been shutdown

#### isOpen

    public boolean isOpen()

Specified by:
  `isOpen` in interface `Channel`
Specified by:
  `isOpen` in interface `org.xnio.channels.SuspendableWriteChannel`

#### close

    public void close()
               throws IOException

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Channel`
Specified by:
  `close` in interface `InterruptibleChannel`
Specified by:
  `close` in interface `org.xnio.channels.CloseableChannel`
Specified by:
  `close` in interface `org.xnio.channels.SuspendableWriteChannel`
Throws:
  `IOException`

#### channelForciblyClosed

    protected void channelForciblyClosed()
                                  throws IOException

Called when a channel has been forcibly closed, and data (frames) have already been written. The action this should take is protocol dependent, e.g. for SPDY a RST_STREAM should be sent, for websockets the channel should be closed. By default this will just close the underlying channel

Throws:
  `IOException`

#### supportsOption

    public boolean supportsOption(org.xnio.Option<?> option)

Specified by:
  `supportsOption` in interface `org.xnio.channels.Configurable`

#### getOption

    public <T> T getOption(org.xnio.Option<T> tOption)
                    throws IOException

Specified by:
  `getOption` in interface `org.xnio.channels.Configurable`
Throws:
  `IOException`

#### setOption

    public <T> T setOption(org.xnio.Option<T> tOption,
                           T t)
                    throws IllegalArgumentException,
                           IOException

Specified by:
  `setOption` in interface `org.xnio.channels.Configurable`
Throws:
  `IllegalArgumentException`
  `IOException`

#### getBuffer

    public ByteBuffer getBuffer()

#### handleFlushComplete

    protected void handleFlushComplete(boolean finalFrame)

#### isFirstDataWritten

    protected boolean isFirstDataWritten()

#### markBroken

    public void markBroken()

#### getChannel

    public C getChannel()

#### isBroken

    public boolean isBroken()

#### isBufferFull

    public boolean isBufferFull()