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 TypeMethodDescriptionvoid
void
awaitWritable
(long l, TimeUnit timeUnit) protected void
Called when a channel has been forcibly closed, and data (frames) have already been written.void
close()
protected SendFrameHeader
boolean
flush()
protected long
Return the timeout used by awaitWritable.org.xnio.ChannelListener.Setter<? extends S>
org.xnio.XnioIoThread
<T> T
getOption
(org.xnio.Option<T> tOption) org.xnio.XnioWorker
org.xnio.ChannelListener.Setter<? extends S>
org.xnio.XnioExecutor
protected void
handleFlushComplete
(boolean finalFrame) boolean
isBroken()
boolean
protected boolean
protected boolean
protected boolean
protected abstract boolean
boolean
isOpen()
boolean
boolean
boolean
Returns true writes have been shutdownvoid
protected PooledByteBuffer
void
protected void
resumeWritesInternal
(boolean wakeup) protected boolean
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
boolean
supportsOption
(org.xnio.Option<?> option) void
long
transferFrom
(FileChannel src, long position, long count) long
transferFrom
(org.xnio.channels.StreamSourceChannel source, long count, ByteBuffer throughBuffer) void
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)
-
Constructor Details
-
AbstractFramedStreamSinkChannel
-
-
Method Details
-
transferFrom
- Specified by:
transferFrom
in interfaceorg.xnio.channels.StreamSinkChannel
- Throws:
IOException
-
transferFrom
public long transferFrom(org.xnio.channels.StreamSourceChannel source, long count, ByteBuffer throughBuffer) throws IOException - Specified by:
transferFrom
in interfaceorg.xnio.channels.StreamSinkChannel
- Throws:
IOException
-
suspendWrites
public void suspendWrites()- Specified by:
suspendWrites
in interfaceorg.xnio.channels.SuspendableWriteChannel
-
createFrameHeader
- Throws:
IOException
-
preWriteTransform
-
isWriteResumed
public boolean isWriteResumed()- Specified by:
isWriteResumed
in interfaceorg.xnio.channels.SuspendableWriteChannel
-
wakeupWrites
public void wakeupWrites()- Specified by:
wakeupWrites
in interfaceorg.xnio.channels.SuspendableWriteChannel
-
resumeWrites
public void resumeWrites()- Specified by:
resumeWrites
in interfaceorg.xnio.channels.SuspendableWriteChannel
-
resumeWritesInternal
protected void resumeWritesInternal(boolean wakeup) -
shutdownWrites
- Specified by:
shutdownWrites
in interfaceorg.xnio.channels.SuspendableWriteChannel
- Throws:
IOException
-
isFinalFrameQueued
protected boolean isFinalFrameQueued() -
awaitWritable
- Specified by:
awaitWritable
in interfaceorg.xnio.channels.SuspendableWriteChannel
- Throws:
IOException
-
awaitWritable
- Specified by:
awaitWritable
in interfaceorg.xnio.channels.SuspendableWriteChannel
- Throws:
IOException
-
getWriteThread
public org.xnio.XnioExecutor getWriteThread()- Specified by:
getWriteThread
in interfaceorg.xnio.channels.SuspendableWriteChannel
-
getWriteSetter
- Specified by:
getWriteSetter
in interfaceorg.xnio.channels.StreamSinkChannel
- Specified by:
getWriteSetter
in interfaceorg.xnio.channels.SuspendableWriteChannel
-
getCloseSetter
- Specified by:
getCloseSetter
in interfaceorg.xnio.channels.CloseableChannel
- Specified by:
getCloseSetter
in interfaceorg.xnio.channels.StreamSinkChannel
- Specified by:
getCloseSetter
in interfaceorg.xnio.channels.SuspendableWriteChannel
-
getWorker
public org.xnio.XnioWorker getWorker()- Specified by:
getWorker
in interfaceorg.xnio.channels.CloseableChannel
-
getIoThread
public org.xnio.XnioIoThread getIoThread()- Specified by:
getIoThread
in interfaceorg.xnio.channels.CloseableChannel
-
flush
- Specified by:
flush
in interfaceorg.xnio.channels.SuspendableWriteChannel
- Throws:
IOException
-
isFlushRequiredOnEmptyBuffer
protected boolean isFlushRequiredOnEmptyBuffer() -
write
- Specified by:
write
in interfaceGatheringByteChannel
- Throws:
IOException
-
write
- Specified by:
write
in interfaceGatheringByteChannel
- Throws:
IOException
-
write
- Specified by:
write
in 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:
writeFinal
in interfaceorg.xnio.channels.StreamSinkChannel
- Throws:
IOException
-
writeFinal
- Specified by:
writeFinal
in interfaceorg.xnio.channels.StreamSinkChannel
- Throws:
IOException
-
writeFinal
- Specified by:
writeFinal
in interfaceorg.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() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceorg.xnio.channels.CloseableChannel
- Specified by:
close
in interfaceInterruptibleChannel
- Specified by:
close
in 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:
supportsOption
in interfaceorg.xnio.channels.Configurable
-
getOption
- Specified by:
getOption
in interfaceorg.xnio.channels.Configurable
- Throws:
IOException
-
setOption
public <T> T setOption(org.xnio.Option<T> tOption, T t) throws IllegalArgumentException, IOException - Specified by:
setOption
in interfaceorg.xnio.channels.Configurable
- Throws:
IllegalArgumentException
IOException
-
getBuffer
-
handleFlushComplete
protected void handleFlushComplete(boolean finalFrame) -
isFirstDataWritten
protected boolean isFirstDataWritten() -
markBroken
public void markBroken() -
getChannel
-
isBroken
public boolean isBroken() -
isBufferFull
public boolean isBufferFull()
-