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:
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.StreamSinkChannelFramed 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()protected voidawaitWritable(long timeoutInNanos)Block until this channel is writable again for the maximum timeout.voidawaitWritable(long l, java.util.concurrent.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.java.nio.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(java.nio.channels.FileChannel src, long position, long count)longtransferFrom(org.xnio.channels.StreamSourceChannel source, long count, java.nio.ByteBuffer throughBuffer)voidwakeupWrites()intwrite(java.nio.ByteBuffer src)longwrite(java.nio.ByteBuffer[] srcs)longwrite(java.nio.ByteBuffer[] srcs, int offset, int length)intwriteFinal(java.nio.ByteBuffer src)longwriteFinal(java.nio.ByteBuffer[] srcs)longwriteFinal(java.nio.ByteBuffer[] srcs, int offset, int length)
-
-
-
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:
transferFromin interfaceorg.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:
transferFromin interfaceorg.xnio.channels.StreamSinkChannel- Throws:
java.io.IOException
-
suspendWrites
public void suspendWrites()
- Specified by:
suspendWritesin interfaceorg.xnio.channels.SuspendableWriteChannel
-
createFrameHeader
protected SendFrameHeader createFrameHeader() throws java.io.IOException
- Throws:
java.io.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 java.io.IOException- Specified by:
shutdownWritesin interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
java.io.IOException
-
isFinalFrameQueued
protected boolean isFinalFrameQueued()
-
awaitWritable
public void awaitWritable() throws java.io.IOException- Specified by:
awaitWritablein interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
java.io.IOException
-
awaitWritable
public void awaitWritable(long l, java.util.concurrent.TimeUnit timeUnit) throws java.io.IOException- Specified by:
awaitWritablein interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
java.io.IOException
-
awaitWritable
protected void awaitWritable(long timeoutInNanos) throws java.io.IOExceptionBlock until this channel is writable again for the maximum timeout.- Parameters:
timeoutInNanos- maximum timeout to block in nanoseconds- Throws:
java.io.IOException- if an I/O error occurs
-
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 java.io.IOException- Specified by:
flushin interfaceorg.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:
writein interfacejava.nio.channels.GatheringByteChannel- Throws:
java.io.IOException
-
write
public long write(java.nio.ByteBuffer[] srcs) throws java.io.IOException- Specified by:
writein interfacejava.nio.channels.GatheringByteChannel- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOException- Specified by:
writein interfacejava.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:
writeFinalin interfaceorg.xnio.channels.StreamSinkChannel- Throws:
java.io.IOException
-
writeFinal
public long writeFinal(java.nio.ByteBuffer[] srcs) throws java.io.IOException- Specified by:
writeFinalin interfaceorg.xnio.channels.StreamSinkChannel- Throws:
java.io.IOException
-
writeFinal
public int writeFinal(java.nio.ByteBuffer src) throws java.io.IOException- Specified by:
writeFinalin interfaceorg.xnio.channels.StreamSinkChannel- Throws:
java.io.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()
- Specified by:
isOpenin interfacejava.nio.channels.Channel- Specified by:
isOpenin interfaceorg.xnio.channels.SuspendableWriteChannel
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceorg.xnio.channels.CloseableChannel- Specified by:
closein interfacejava.nio.channels.InterruptibleChannel- Specified by:
closein interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
java.io.IOException
-
channelForciblyClosed
protected void channelForciblyClosed() throws java.io.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:
java.io.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 java.io.IOException- Specified by:
getOptionin interfaceorg.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:
setOptionin interfaceorg.xnio.channels.Configurable- Throws:
java.lang.IllegalArgumentExceptionjava.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()
-
-