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
readyForFlushis set, and while this bit is set the buffer must not be modified.- Author:
- Stuart Douglas
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractFramedStreamSinkChannel(C channel)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidawaitWritable()voidawaitWritable(long l, TimeUnit timeUnit)protected voidchannelForciblyClosed()Called when a channel has been forcibly closed, and data (frames) have already been written.voidclose()protected SendFrameHeadercreateFrameHeader()booleanflush()protected longgetAwaitWritableTimeout()Return the timeout used by awaitWritable and flush tasks.ByteBuffergetBuffer()CgetChannel()org.xnio.ChannelListener.Setter<? extends S>getCloseSetter()org.xnio.XnioIoThreadgetIoThread()<T> TgetOption(org.xnio.Option<T> tOption)org.xnio.XnioWorkergetWorker()org.xnio.ChannelListener.Setter<? extends S>getWriteSetter()org.xnio.XnioExecutorgetWriteThread()protected voidhandleFlushComplete(boolean finalFrame)booleanisBroken()booleanisBufferFull()protected booleanisFinalFrameQueued()protected booleanisFirstDataWritten()protected booleanisFlushRequiredOnEmptyBuffer()protected abstract booleanisLastFrame()booleanisOpen()booleanisReadyForFlush()booleanisWriteResumed()booleanisWritesShutdown()Returns true writes have been shutdownvoidmarkBroken()protected PooledByteBufferpreWriteTransform(PooledByteBuffer body)voidresumeWrites()protected voidresumeWritesInternal(boolean wakeup)protected booleansafeToSend()booleansend(PooledByteBuffer pooled)Send a buffer to this channel.protected booleansendInternal(PooledByteBuffer pooled)<T> TsetOption(org.xnio.Option<T> tOption, T t)voidshutdownWrites()booleansupportsOption(org.xnio.Option<?> option)voidsuspendWrites()longtransferFrom(FileChannel src, long position, long count)longtransferFrom(org.xnio.channels.StreamSourceChannel source, long count, ByteBuffer throughBuffer)voidwakeupWrites()intwrite(ByteBuffer src)longwrite(ByteBuffer[] srcs)longwrite(ByteBuffer[] srcs, int offset, int length)intwriteFinal(ByteBuffer src)longwriteFinal(ByteBuffer[] srcs)longwriteFinal(ByteBuffer[] srcs, int offset, int length)
-
-
-
Constructor Detail
-
AbstractFramedStreamSinkChannel
protected AbstractFramedStreamSinkChannel(C channel)
-
-
Method Detail
-
transferFrom
public long transferFrom(FileChannel src, long position, long count) throws IOException
- Specified by:
transferFromin interfaceorg.xnio.channels.StreamSinkChannel- Throws:
IOException
-
transferFrom
public long transferFrom(org.xnio.channels.StreamSourceChannel source, long count, ByteBuffer throughBuffer) throws IOException- Specified by:
transferFromin interfaceorg.xnio.channels.StreamSinkChannel- Throws:
IOException
-
suspendWrites
public void suspendWrites()
- Specified by:
suspendWritesin interfaceorg.xnio.channels.SuspendableWriteChannel
-
createFrameHeader
protected SendFrameHeader createFrameHeader() throws IOException
- Throws:
IOException
-
preWriteTransform
protected PooledByteBuffer preWriteTransform(PooledByteBuffer body)
-
isWriteResumed
public boolean isWriteResumed()
- Specified by:
isWriteResumedin interfaceorg.xnio.channels.SuspendableWriteChannel
-
wakeupWrites
public void wakeupWrites()
- Specified by:
wakeupWritesin interfaceorg.xnio.channels.SuspendableWriteChannel
-
resumeWrites
public void resumeWrites()
- Specified by:
resumeWritesin interfaceorg.xnio.channels.SuspendableWriteChannel
-
resumeWritesInternal
protected void resumeWritesInternal(boolean wakeup)
-
shutdownWrites
public void shutdownWrites() throws IOException- Specified by:
shutdownWritesin interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
IOException
-
isFinalFrameQueued
protected boolean isFinalFrameQueued()
-
awaitWritable
public void awaitWritable() throws IOException- Specified by:
awaitWritablein interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
IOException
-
awaitWritable
public void awaitWritable(long l, TimeUnit timeUnit) throws IOException- Specified by:
awaitWritablein interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
IOException
-
getWriteThread
public org.xnio.XnioExecutor getWriteThread()
- Specified by:
getWriteThreadin interfaceorg.xnio.channels.SuspendableWriteChannel
-
getWriteSetter
public org.xnio.ChannelListener.Setter<? extends S> getWriteSetter()
- Specified by:
getWriteSetterin interfaceorg.xnio.channels.StreamSinkChannel- Specified by:
getWriteSetterin interfaceorg.xnio.channels.SuspendableWriteChannel
-
getCloseSetter
public org.xnio.ChannelListener.Setter<? extends S> getCloseSetter()
- Specified by:
getCloseSetterin interfaceorg.xnio.channels.CloseableChannel- Specified by:
getCloseSetterin interfaceorg.xnio.channels.StreamSinkChannel- Specified by:
getCloseSetterin interfaceorg.xnio.channels.SuspendableWriteChannel
-
getWorker
public org.xnio.XnioWorker getWorker()
- Specified by:
getWorkerin interfaceorg.xnio.channels.CloseableChannel
-
getIoThread
public org.xnio.XnioIoThread getIoThread()
- Specified by:
getIoThreadin interfaceorg.xnio.channels.CloseableChannel
-
flush
public boolean flush() throws IOException- Specified by:
flushin interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
IOException
-
isFlushRequiredOnEmptyBuffer
protected boolean isFlushRequiredOnEmptyBuffer()
-
write
public long write(ByteBuffer[] srcs, int offset, int length) throws IOException
- Specified by:
writein interfaceGatheringByteChannel- Throws:
IOException
-
write
public long write(ByteBuffer[] srcs) throws IOException
- Specified by:
writein interfaceGatheringByteChannel- Throws:
IOException
-
write
public int write(ByteBuffer src) throws IOException
- Specified by:
writein interfaceWritableByteChannel- 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 and flush tasks. First the channel write timeout is read and if not set the default AWAIT_WRITABLE_TIMEOUT.- Returns:
- the awaitWritable timeout, in milliseconds
-
writeFinal
public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException
- Specified by:
writeFinalin interfaceorg.xnio.channels.StreamSinkChannel- Throws:
IOException
-
writeFinal
public long writeFinal(ByteBuffer[] srcs) throws IOException
- Specified by:
writeFinalin interfaceorg.xnio.channels.StreamSinkChannel- Throws:
IOException
-
writeFinal
public int writeFinal(ByteBuffer src) throws IOException
- Specified by:
writeFinalin interfaceorg.xnio.channels.StreamSinkChannel- Throws:
IOException
-
isLastFrame
protected abstract boolean isLastFrame()
- Returns:
trueIf 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()
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceorg.xnio.channels.CloseableChannel- Specified by:
closein interfaceInterruptibleChannel- Specified by:
closein interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
IOException
-
channelForciblyClosed
protected void channelForciblyClosed() throws IOExceptionCalled 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:
supportsOptionin interfaceorg.xnio.channels.Configurable
-
getOption
public <T> T getOption(org.xnio.Option<T> tOption) throws IOException- Specified by:
getOptionin interfaceorg.xnio.channels.Configurable- Throws:
IOException
-
setOption
public <T> T setOption(org.xnio.Option<T> tOption, T t) throws IllegalArgumentException, IOException- Specified by:
setOptionin interfaceorg.xnio.channels.Configurable- Throws:
IllegalArgumentExceptionIOException
-
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()
-
-