public abstract class AbstractFramedStreamSourceChannel<C extends AbstractFramedChannel<C,R,S>,R extends AbstractFramedStreamSourceChannel<C,R,S>,S extends AbstractFramedStreamSinkChannel<C,R,S>> extends Object implements StreamSourceChannel
EMPTY
Constructor and Description |
---|
AbstractFramedStreamSourceChannel(C framedChannel) |
AbstractFramedStreamSourceChannel(C framedChannel,
PooledByteBuffer data,
long frameDataRemaining) |
Modifier and Type | Method and Description |
---|---|
void |
addCloseTask(ChannelListener<R> channelListener) |
void |
awaitReadable()
Block until this channel becomes readable again.
|
void |
awaitReadable(long l,
TimeUnit timeUnit)
Block until this channel becomes readable again, or until the timeout expires.
|
protected void |
channelForciblyClosed() |
void |
close()
Close this channel.
|
protected void |
complete()
Method that is invoked when all data has been read.
|
protected void |
dataReady(FrameHeaderData headerData,
PooledByteBuffer frameData)
Called when data has been read from the underlying channel.
|
ChannelListener.Setter<? extends R> |
getCloseSetter()
Get the setter which can be used to change the close listener for this channel.
|
protected C |
getFramedChannel() |
XnioIoThread |
getIoThread()
Get the I/O thread associated with this channel.
|
long |
getMaxStreamSize() |
<T> T |
getOption(Option<T> tOption)
Get the value of a channel option.
|
protected int |
getReadFrameCount() |
ChannelListener.Setter<? extends R> |
getReadSetter()
Get the setter which can be used to change the read listener for this channel.
|
XnioExecutor |
getReadThread()
Get the read thread for this channel.
|
XnioWorker |
getWorker()
Get the worker for this channel.
|
protected void |
handleHeaderData(FrameHeaderData headerData) |
protected boolean |
isComplete() |
protected boolean |
isLastFrame() |
boolean |
isOpen() |
boolean |
isReadResumed()
Determine whether reads are resumed.
|
protected void |
lastFrame() |
protected void |
markStreamBroken()
Called when this stream is no longer valid.
|
protected PooledByteBuffer |
processFrameData(PooledByteBuffer data,
boolean lastFragmentOfFrame) |
int |
read(ByteBuffer dst) |
long |
read(ByteBuffer[] dsts) |
long |
read(ByteBuffer[] dsts,
int offset,
int length) |
void |
resumeReads()
Resume reads on this channel.
|
void |
setMaxStreamSize(long maxStreamSize) |
<T> T |
setOption(Option<T> tOption,
T t)
Set an option for this channel.
|
void |
shutdownReads()
Places this readable channel at "end of stream".
|
boolean |
supportsOption(Option<?> option)
Determine whether an option is supported on this channel.
|
void |
suspendReads()
Suspend further read notifications on this channel.
|
long |
transferTo(long count,
ByteBuffer throughBuffer,
StreamSinkChannel streamSinkChannel)
Transfers bytes into the given channel target.
|
long |
transferTo(long position,
long count,
FileChannel target)
Transfers bytes into the given file from this channel.
|
protected long |
updateFrameDataRemaining(PooledByteBuffer frameData,
long frameDataRemaining) |
void |
wakeupReads()
Resume reads on this channel, and force the read listener to be triggered even if the
channel isn't actually readable. |
public AbstractFramedStreamSourceChannel(C framedChannel)
public AbstractFramedStreamSourceChannel(C framedChannel, PooledByteBuffer data, long frameDataRemaining)
public long transferTo(long position, long count, FileChannel target) throws IOException
StreamSourceChannel
FileChannel.transferFrom(ReadableByteChannel, long, long)
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.
transferTo
in interface StreamSourceChannel
position
- the position within the file from which the transfer is to begincount
- the number of bytes to be transferredtarget
- the file to write toIOException
- if an I/O error occurspublic long transferTo(long count, ByteBuffer throughBuffer, StreamSinkChannel streamSinkChannel) throws IOException
StreamSourceChannel
throughBuffer
parameter's buffer
space. On entry, throughBuffer
will be cleared. On exit, the buffer will be
flipped for emptying, and may possibly 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 this channel which must
be written to target
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.
Note that the return value is the amount of data that was actually transferred to the StreamSinkChannel
.
The actual amount of data read could be larger than this, and can be calculated by adding the return value and
the amount of data left in throughBuffer
.
transferTo
in interface StreamSourceChannel
count
- the number of bytes to be transferredthroughBuffer
- the buffer to copy through.streamSinkChannel
- the destination to write toIOException
- if an I/O error occurspublic long getMaxStreamSize()
public void setMaxStreamSize(long maxStreamSize)
public void suspendReads()
SuspendableReadChannel
suspendReads
in interface SuspendableReadChannel
protected void complete() throws IOException
IOException
protected boolean isComplete()
public void resumeReads()
SuspendableReadChannel
resumeReads
in interface SuspendableReadChannel
public boolean isReadResumed()
SuspendableReadChannel
isReadResumed
in interface SuspendableReadChannel
true
if reads are resumed, false
if reads are suspendedpublic void wakeupReads()
SuspendableReadChannel
Resume reads
on this channel, and force the read listener to be triggered even if the
channel isn't actually readable.wakeupReads
in interface SuspendableReadChannel
public void addCloseTask(ChannelListener<R> channelListener)
public void shutdownReads() throws IOException
SuspendableReadChannel
CloseableChannel.close()
to be called automatically.shutdownReads
in interface SuspendableReadChannel
IOException
- if an I/O error occursprotected void lastFrame()
protected boolean isLastFrame()
public void awaitReadable() throws IOException
SuspendableReadChannel
awaitReadable
in interface SuspendableReadChannel
InterruptedIOException
- if the operation is interrupted; the thread's interrupt flag will be set as wellIOException
- if an I/O error occurspublic void awaitReadable(long l, TimeUnit timeUnit) throws IOException
SuspendableReadChannel
awaitReadable
in interface SuspendableReadChannel
l
- 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 occursprotected void dataReady(FrameHeaderData headerData, PooledByteBuffer frameData)
headerData
- The frame header data. This may be null if the data is part of a an existing frameframeData
- The frame dataprotected long updateFrameDataRemaining(PooledByteBuffer frameData, long frameDataRemaining)
protected PooledByteBuffer processFrameData(PooledByteBuffer data, boolean lastFragmentOfFrame) throws IOException
IOException
protected void handleHeaderData(FrameHeaderData headerData)
public XnioExecutor getReadThread()
SuspendableReadChannel
getReadThread
in interface SuspendableReadChannel
null
if none is configured or availablepublic ChannelListener.Setter<? extends R> getReadSetter()
StreamSourceChannel
getReadSetter
in interface StreamSourceChannel
getReadSetter
in interface SuspendableReadChannel
public ChannelListener.Setter<? extends R> getCloseSetter()
StreamSourceChannel
getCloseSetter
in interface CloseableChannel
getCloseSetter
in interface StreamSourceChannel
getCloseSetter
in interface SuspendableReadChannel
public XnioWorker getWorker()
CloseableChannel
getWorker
in interface CloseableChannel
public XnioIoThread getIoThread()
CloseableChannel
getIoThread
in interface CloseableChannel
public boolean supportsOption(Option<?> option)
Configurable
supportsOption
in interface Configurable
option
- the optiontrue
if it is supportedpublic <T> T getOption(Option<T> tOption) throws IOException
Configurable
getOption
in interface Configurable
T
- 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
Configurable
setOption
in interface Configurable
T
- 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 long read(ByteBuffer[] dsts, int offset, int length) throws IOException
read
in interface ScatteringByteChannel
IOException
public long read(ByteBuffer[] dsts) throws IOException
read
in interface ScatteringByteChannel
IOException
public int read(ByteBuffer dst) throws IOException
read
in interface ReadableByteChannel
IOException
public void close()
CloseableChannel
close
in interface Closeable
close
in interface AutoCloseable
close
in interface Channel
close
in interface InterruptibleChannel
close
in interface CloseableChannel
protected void channelForciblyClosed()
protected C getFramedChannel()
protected int getReadFrameCount()
protected void markStreamBroken()
Copyright © 2017 JBoss by Red Hat. All rights reserved.