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 StreamSinkChannel
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.
EMPTY| Modifier | Constructor and Description |
|---|---|
protected |
AbstractFramedStreamSinkChannel(C channel) |
| Modifier and Type | Method and Description |
|---|---|
void |
awaitWritable()
Block until this channel becomes writable again.
|
void |
awaitWritable(long l,
TimeUnit timeUnit)
Block until this channel becomes writable again, or until the timeout expires.
|
protected void |
channelForciblyClosed()
Called when a channel has been forcibly closed, and data (frames) have already been written.
|
void |
close()
Close this channel.
|
protected SendFrameHeader |
createFrameHeader() |
boolean |
flush()
Flush any waiting partial send or write.
|
ByteBuffer |
getBuffer() |
C |
getChannel() |
ChannelListener.Setter<? extends S> |
getCloseSetter()
Get the setter which can be used to change the close listener for this channel.
|
XnioIoThread |
getIoThread()
Get the I/O thread associated with this channel.
|
<T> T |
getOption(Option<T> tOption)
Get the value of a channel option.
|
XnioWorker |
getWorker()
Get the worker for this channel.
|
ChannelListener.Setter<? extends S> |
getWriteSetter()
Get the setter which can be used to change the write listener for this channel.
|
XnioExecutor |
getWriteThread()
Get the write thread for this channel.
|
protected void |
handleFlushComplete(boolean finalFrame) |
boolean |
isBroken() |
boolean |
isBufferFull() |
protected boolean |
isFinalFrameQueued() |
protected boolean |
isFirstDataWritten() |
protected boolean |
isFlushRequiredOnEmptyBuffer() |
protected abstract boolean |
isLastFrame() |
boolean |
isOpen()
Determine whether this channel is open.
|
boolean |
isReadyForFlush() |
boolean |
isWriteResumed()
Determine whether writes are resumed.
|
boolean |
isWritesShutdown()
Returns true writes have been shutdown
|
void |
markBroken() |
protected PooledByteBuffer |
preWriteTransform(PooledByteBuffer body) |
void |
resumeWrites()
Resume writes on this channel.
|
protected void |
resumeWritesInternal(boolean wakeup) |
protected boolean |
safeToSend() |
boolean |
send(PooledByteBuffer pooled)
Send a buffer to this channel.
|
protected boolean |
sendInternal(PooledByteBuffer pooled) |
<T> T |
setOption(Option<T> tOption,
T t)
Set an option for this channel.
|
void |
shutdownWrites()
Indicate that writing is complete for this channel.
|
boolean |
supportsOption(Option<?> option)
Determine whether an option is supported on this channel.
|
void |
suspendWrites()
Suspend further write notifications on this channel.
|
long |
transferFrom(FileChannel src,
long position,
long count)
Transfer bytes into this channel from the given file.
|
long |
transferFrom(StreamSourceChannel source,
long count,
ByteBuffer throughBuffer)
Transfers bytes from the given channel source.
|
void |
wakeupWrites()
Resume writes on this channel, and force the write listener to be triggered even if the
channel isn't actually writable. |
int |
write(ByteBuffer src) |
long |
write(ByteBuffer[] srcs) |
long |
write(ByteBuffer[] srcs,
int offset,
int length) |
int |
writeFinal(ByteBuffer src)
Writes some data to the channel, with the same semantics as
WritableByteChannel.write(java.nio.ByteBuffer). |
long |
writeFinal(ByteBuffer[] srcs)
Writes some data to the channel, with the same semantics as
GatheringByteChannel.write(java.nio.ByteBuffer[]). |
long |
writeFinal(ByteBuffer[] srcs,
int offset,
int length)
Writes some data to the channel, with the same semantics as
GatheringByteChannel.write(java.nio.ByteBuffer[], int, int). |
protected AbstractFramedStreamSinkChannel(C channel)
public long transferFrom(FileChannel src, long position, long count) throws IOException
StreamSinkChannelFileChannel.transferTo(long, long, WritableByteChannel)
may provide a performance advantage on some platforms.
If the current thread is interrupted when this method is called, it may throw a InterruptedIOException;
however, if this exception is thrown, the InterruptedIOException.bytesTransferred field is
guaranteed to be 0.
transferFrom in interface StreamSinkChannelsrc - the file to read fromposition - the position within the file from which the transfer is to begincount - the number of bytes to be transferredIOException - if an I/O error occurspublic long transferFrom(StreamSourceChannel source, long count, ByteBuffer throughBuffer) throws IOException
StreamSinkChannelthroughBuffer parameter's buffer
space. On entry, throughBuffer will be cleared. On exit, the buffer will be
flipped for emptying, and may be empty or may contain data. If this method returns a value less than
count, then the remaining data in throughBuffer may contain data read from source which must
be written to this channel to complete the operation. Note that using a direct buffer may provide an
intermediate performance gain on platforms without zero-copy facilities.
If the current thread is interrupted when this method is called, it may throw a InterruptedIOException;
however, if this exception is thrown, the InterruptedIOException.bytesTransferred field is
guaranteed to be 0.
transferFrom in interface StreamSinkChannelsource - the source to read fromcount - the number of bytes to be transferredthroughBuffer - the buffer to copy through.IOException - if an I/O error occurspublic void suspendWrites()
SuspendableWriteChannelsuspendWrites in interface SuspendableWriteChannelprotected SendFrameHeader createFrameHeader() throws IOException
IOExceptionprotected PooledByteBuffer preWriteTransform(PooledByteBuffer body)
public boolean isWriteResumed()
SuspendableWriteChannelisWriteResumed in interface SuspendableWriteChanneltrue if writes are resumed, false if writes are suspendedpublic void wakeupWrites()
SuspendableWriteChannelResume writes on this channel, and force the write listener to be triggered even if the
channel isn't actually writable.wakeupWrites in interface SuspendableWriteChannelpublic void resumeWrites()
SuspendableWriteChannelresumeWrites in interface SuspendableWriteChannelprotected void resumeWritesInternal(boolean wakeup)
public void shutdownWrites()
throws IOException
SuspendableWriteChannelSuspendableWriteChannel.flush() method; once this is done, if the read side of the channel was shut down, the channel will
automatically close.shutdownWrites in interface SuspendableWriteChannelIOException - if an I/O error occursprotected boolean isFinalFrameQueued()
public void awaitWritable()
throws IOException
SuspendableWriteChannelawaitWritable in interface SuspendableWriteChannelInterruptedIOException - if the operation is interrupted; the thread's interrupt flag will be set as wellIOException - if an I/O error occurspublic void awaitWritable(long l,
TimeUnit timeUnit)
throws IOException
SuspendableWriteChannelawaitWritable in interface SuspendableWriteChannell - the time to waittimeUnit - the time unitInterruptedIOException - if the operation is interrupted; the thread's interrupt flag will be set as wellIOException - if an I/O error occurspublic XnioExecutor getWriteThread()
SuspendableWriteChannelgetWriteThread in interface SuspendableWriteChannelnull if none is configured or availablepublic ChannelListener.Setter<? extends S> getWriteSetter()
StreamSinkChannelgetWriteSetter in interface StreamSinkChannelgetWriteSetter in interface SuspendableWriteChannelpublic ChannelListener.Setter<? extends S> getCloseSetter()
StreamSinkChannelgetCloseSetter in interface CloseableChannelgetCloseSetter in interface StreamSinkChannelgetCloseSetter in interface SuspendableWriteChannelpublic XnioWorker getWorker()
CloseableChannelgetWorker in interface CloseableChannelpublic XnioIoThread getIoThread()
CloseableChannelgetIoThread in interface CloseableChannelpublic boolean flush()
throws IOException
SuspendableWriteChanneltrue. If there is data to flush which cannot be immediately written, this method
will return false. If this method returns true after SuspendableWriteChannel.shutdownWrites() was called on
this channel, the write listener will no longer be invoked on this channel. If this is case and additionally
this is a write-only channel or the read side was previously shut down, then the channel will
automatically be closed.flush in interface SuspendableWriteChanneltrue if the message was flushed, or false if the result would blockIOException - if an I/O error occursprotected boolean isFlushRequiredOnEmptyBuffer()
public long write(ByteBuffer[] srcs, int offset, int length) throws IOException
write in interface GatheringByteChannelIOExceptionpublic long write(ByteBuffer[] srcs) throws IOException
write in interface GatheringByteChannelIOExceptionpublic int write(ByteBuffer src) throws IOException
write in interface WritableByteChannelIOExceptionpublic boolean send(PooledByteBuffer pooled) throws IOException
pooled - Pooled ByteBuffer to send. The buffer should have data available. This channel will free the buffer
after sending dataIOException - if this channel is closedprotected boolean sendInternal(PooledByteBuffer pooled) throws IOException
IOExceptionprotected boolean safeToSend()
throws IOException
IOExceptionpublic long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException
StreamSinkChannelGatheringByteChannel.write(java.nio.ByteBuffer[], int, int). If all the data is written
out then the channel will have its writes shutdown.
If an exception is thrown the caller is still responsible for closing the channel.writeFinal in interface StreamSinkChannelsrcs - The buffers from which bytes are to be retrievedoffset - The offset within the buffer array of the first buffer from
which bytes are to be retrieved; must be non-negative and no
larger than srcs.lengthlength - The maximum number of buffers to be accessed; must be
non-negative and no larger than
srcs.length - offsetIOExceptionGatheringByteChannel.write(java.nio.ByteBuffer[], int, int),
SuspendableWriteChannel.shutdownWrites()public long writeFinal(ByteBuffer[] srcs) throws IOException
StreamSinkChannelGatheringByteChannel.write(java.nio.ByteBuffer[]). If all the data is written
out then the channel will have its writes shutdown.
If an exception is thrown the caller is still responsible for closing the channel.writeFinal in interface StreamSinkChannelsrcs - The buffers from which bytes are to be retrievedIOExceptionGatheringByteChannel.write(java.nio.ByteBuffer[]),
SuspendableWriteChannel.shutdownWrites()public int writeFinal(ByteBuffer src) throws IOException
StreamSinkChannelWritableByteChannel.write(java.nio.ByteBuffer). If all the data is written
out then the channel will have its writes shutdown. Semantically this
method is equivalent to:
int rem = src.remaining();
int written = channel.write(src);
if(written == rem) {
channel.shutdownWrites()
}
If an exception is thrown the caller is still responsible for closing the channel.writeFinal in interface StreamSinkChannelsrc - The data to writeIOExceptionWritableByteChannel.write(java.nio.ByteBuffer),
SuspendableWriteChannel.shutdownWrites()protected abstract boolean isLastFrame()
true If this is the last frame that will be sent on this connectionpublic boolean isReadyForFlush()
public boolean isWritesShutdown()
public boolean isOpen()
SuspendableWriteChannelfalse if all directions are shut down,
even if there is unflushed write data pending.isOpen in interface ChannelisOpen in interface SuspendableWriteChanneltrue if the channel is open, false otherwisepublic void close()
throws IOException
SuspendableWriteChannelclose in interface Closeableclose in interface AutoCloseableclose in interface Channelclose in interface InterruptibleChannelclose in interface CloseableChannelclose in interface SuspendableWriteChannelIOException - if the close failedprotected void channelForciblyClosed()
throws IOException
IOExceptionpublic boolean supportsOption(Option<?> option)
ConfigurablesupportsOption in interface Configurableoption - the optiontrue if it is supportedpublic <T> T getOption(Option<T> tOption) throws IOException
ConfigurablegetOption in interface ConfigurableT - the type of the option valuetOption - the option to getnull if it is not setIOException - if an I/O error occurred when reading the optionpublic <T> T setOption(Option<T> tOption, T t) throws IllegalArgumentException, IOException
ConfigurablesetOption in interface ConfigurableT - the type of the option valuetOption - the option to sett - the value of the option to setIllegalArgumentException - if the value is not acceptable for this optionIOException - if an I/O error occurred when modifying the optionpublic ByteBuffer getBuffer()
protected void handleFlushComplete(boolean finalFrame)
protected boolean isFirstDataWritten()
public void markBroken()
public C getChannel()
public boolean isBroken()
public boolean isBufferFull()
Copyright © 2018 JBoss by Red Hat. All rights reserved.