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 -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidawaitWritable(long l, TimeUnit timeUnit) protected voidCalled when a channel has been forcibly closed, and data (frames) have already been written.voidclose()protected SendFrameHeaderbooleanflush()protected longReturn the timeout used by awaitWritable.org.xnio.ChannelListener.Setter<? extends S>org.xnio.XnioIoThread<T> TgetOption(org.xnio.Option<T> tOption) org.xnio.XnioWorkerorg.xnio.ChannelListener.Setter<? extends S>org.xnio.XnioExecutorprotected voidhandleFlushComplete(boolean finalFrame) booleanisBroken()booleanprotected booleanprotected booleanprotected booleanprotected abstract booleanbooleanisOpen()booleanbooleanbooleanReturns true writes have been shutdownvoidprotected PooledByteBuffervoidprotected voidresumeWritesInternal(boolean wakeup) protected booleanbooleansend(PooledByteBuffer pooled) Send a buffer to this channel.protected booleansendInternal(PooledByteBuffer pooled) <T> TsetOption(org.xnio.Option<T> tOption, T t) voidbooleansupportsOption(org.xnio.Option<?> option) voidlongtransferFrom(FileChannel src, long position, long count) longtransferFrom(org.xnio.channels.StreamSourceChannel source, long count, ByteBuffer throughBuffer) voidintwrite(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 Details
-
AbstractFramedStreamSinkChannel
-
-
Method Details
-
transferFrom
- 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
- Throws:
IOException
-
preWriteTransform
-
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
- Specified by:
shutdownWritesin interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
IOException
-
isFinalFrameQueued
protected boolean isFinalFrameQueued() -
awaitWritable
- Specified by:
awaitWritablein interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
IOException
-
awaitWritable
- Specified by:
awaitWritablein interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
IOException
-
getWriteThread
public org.xnio.XnioExecutor getWriteThread()- Specified by:
getWriteThreadin interfaceorg.xnio.channels.SuspendableWriteChannel
-
getWriteSetter
- Specified by:
getWriteSetterin interfaceorg.xnio.channels.StreamSinkChannel- Specified by:
getWriteSetterin interfaceorg.xnio.channels.SuspendableWriteChannel
-
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
- Specified by:
flushin interfaceorg.xnio.channels.SuspendableWriteChannel- Throws:
IOException
-
isFlushRequiredOnEmptyBuffer
protected boolean isFlushRequiredOnEmptyBuffer() -
write
- Specified by:
writein interfaceGatheringByteChannel- Throws:
IOException
-
write
- Specified by:
writein interfaceGatheringByteChannel- Throws:
IOException
-
write
- Specified by:
writein interfaceWritableByteChannel- Throws:
IOException
-
send
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
- Throws:
IOException
-
safeToSend
- Throws:
IOException
-
getAwaitWritableTimeout
protected long getAwaitWritableTimeout()Return the timeout used by awaitWritable.- Returns:
- the awaitWritable timeout, in milliseconds
-
writeFinal
- Specified by:
writeFinalin interfaceorg.xnio.channels.StreamSinkChannel- Throws:
IOException
-
writeFinal
- Specified by:
writeFinalin interfaceorg.xnio.channels.StreamSinkChannel- Throws:
IOException
-
writeFinal
- 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
- 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
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:
supportsOptionin interfaceorg.xnio.channels.Configurable
-
getOption
- 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
-
handleFlushComplete
protected void handleFlushComplete(boolean finalFrame) -
isFirstDataWritten
protected boolean isFirstDataWritten() -
markBroken
public void markBroken() -
getChannel
-
isBroken
public boolean isBroken() -
isBufferFull
public boolean isBufferFull()
-