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

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel, java.nio.channels.GatheringByteChannel, java.nio.channels.InterruptibleChannel, java.nio.channels.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 java.lang.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
    • Constructor Detail

      • AbstractFramedStreamSinkChannel

        protected AbstractFramedStreamSinkChannel​(C channel)
    • Method Detail

      • transferFrom

        public long transferFrom​(java.nio.channels.FileChannel src,
                                 long position,
                                 long count)
                          throws java.io.IOException
        Specified by:
        transferFrom in interface org.xnio.channels.StreamSinkChannel
        Throws:
        java.io.IOException
      • transferFrom

        public long transferFrom​(org.xnio.channels.StreamSourceChannel source,
                                 long count,
                                 java.nio.ByteBuffer throughBuffer)
                          throws java.io.IOException
        Specified by:
        transferFrom in interface org.xnio.channels.StreamSinkChannel
        Throws:
        java.io.IOException
      • suspendWrites

        public void suspendWrites()
        Specified by:
        suspendWrites in interface org.xnio.channels.SuspendableWriteChannel
      • createFrameHeader

        protected SendFrameHeader createFrameHeader()
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • 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 java.io.IOException
        Specified by:
        shutdownWrites in interface org.xnio.channels.SuspendableWriteChannel
        Throws:
        java.io.IOException
      • isFinalFrameQueued

        protected boolean isFinalFrameQueued()
      • awaitWritable

        public void awaitWritable()
                           throws java.io.IOException
        Specified by:
        awaitWritable in interface org.xnio.channels.SuspendableWriteChannel
        Throws:
        java.io.IOException
      • awaitWritable

        public void awaitWritable​(long l,
                                  java.util.concurrent.TimeUnit timeUnit)
                           throws java.io.IOException
        Specified by:
        awaitWritable in interface org.xnio.channels.SuspendableWriteChannel
        Throws:
        java.io.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 java.io.IOException
        Specified by:
        flush in interface org.xnio.channels.SuspendableWriteChannel
        Throws:
        java.io.IOException
      • isFlushRequiredOnEmptyBuffer

        protected boolean isFlushRequiredOnEmptyBuffer()
      • write

        public long write​(java.nio.ByteBuffer[] srcs,
                          int offset,
                          int length)
                   throws java.io.IOException
        Specified by:
        write in interface java.nio.channels.GatheringByteChannel
        Throws:
        java.io.IOException
      • write

        public long write​(java.nio.ByteBuffer[] srcs)
                   throws java.io.IOException
        Specified by:
        write in interface java.nio.channels.GatheringByteChannel
        Throws:
        java.io.IOException
      • write

        public int write​(java.nio.ByteBuffer src)
                  throws java.io.IOException
        Specified by:
        write in interface java.nio.channels.WritableByteChannel
        Throws:
        java.io.IOException
      • send

        public boolean send​(PooledByteBuffer pooled)
                     throws java.io.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:
        java.io.IOException - if this channel is closed
      • sendInternal

        protected boolean sendInternal​(PooledByteBuffer pooled)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • safeToSend

        protected boolean safeToSend()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • getAwaitWritableTimeout

        protected long getAwaitWritableTimeout()
        Return the timeout used by awaitWritable.
        Returns:
        the awaitWritable timeout, in milliseconds
      • writeFinal

        public long writeFinal​(java.nio.ByteBuffer[] srcs,
                               int offset,
                               int length)
                        throws java.io.IOException
        Specified by:
        writeFinal in interface org.xnio.channels.StreamSinkChannel
        Throws:
        java.io.IOException
      • writeFinal

        public long writeFinal​(java.nio.ByteBuffer[] srcs)
                        throws java.io.IOException
        Specified by:
        writeFinal in interface org.xnio.channels.StreamSinkChannel
        Throws:
        java.io.IOException
      • writeFinal

        public int writeFinal​(java.nio.ByteBuffer src)
                       throws java.io.IOException
        Specified by:
        writeFinal in interface org.xnio.channels.StreamSinkChannel
        Throws:
        java.io.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 java.nio.channels.Channel
        Specified by:
        isOpen in interface org.xnio.channels.SuspendableWriteChannel
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface org.xnio.channels.CloseableChannel
        Specified by:
        close in interface java.nio.channels.InterruptibleChannel
        Specified by:
        close in interface org.xnio.channels.SuspendableWriteChannel
        Throws:
        java.io.IOException
      • channelForciblyClosed

        protected void channelForciblyClosed()
                                      throws java.io.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:
        java.io.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 java.io.IOException
        Specified by:
        getOption in interface org.xnio.channels.Configurable
        Throws:
        java.io.IOException
      • setOption

        public <T> T setOption​(org.xnio.Option<T> tOption,
                               T t)
                        throws java.lang.IllegalArgumentException,
                               java.io.IOException
        Specified by:
        setOption in interface org.xnio.channels.Configurable
        Throws:
        java.lang.IllegalArgumentException
        java.io.IOException
      • getBuffer

        public java.nio.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()