public class IdleTimeoutConduit extends Object implements StreamSinkConduit, StreamSourceConduit
Constructor and Description |
---|
IdleTimeoutConduit(StreamConnection connection) |
Modifier and Type | Method and Description |
---|---|
void |
awaitReadable()
Block until this channel becomes readable again.
|
void |
awaitReadable(long time,
TimeUnit timeUnit)
Block until this conduit becomes readable again, or until the timeout expires.
|
void |
awaitWritable()
Block until this channel becomes writable again.
|
void |
awaitWritable(long time,
TimeUnit timeUnit)
Block until this conduit becomes writable again, or until the timeout expires.
|
protected void |
doClose() |
boolean |
flush()
Flush out any unwritten, buffered output.
|
long |
getIdleTimeout() |
XnioIoThread |
getReadThread()
Get the XNIO read thread.
|
XnioWorker |
getWorker()
Get the XNIO worker associated with this conduit.
|
XnioIoThread |
getWriteThread()
Get the write thread for this conduit.
|
boolean |
isReadResumed()
Determine whether read notifications are currently enabled.
|
boolean |
isReadShutdown()
Determine whether reads have been shut down on this conduit.
|
boolean |
isWriteResumed()
Determine whether write notifications are currently enabled.
|
boolean |
isWriteShutdown()
Determine whether writes have been fully shut down on this conduit.
|
int |
read(ByteBuffer dst)
Read a sequence of bytes from this conduit to the given buffer.
|
long |
read(ByteBuffer[] dsts,
int offset,
int length)
Read a sequence of bytes from this conduit to the given buffers.
|
void |
resumeReads()
Indicate that the conduit's
ReadReadyHandler should be invoked as soon as data can be read
without blocking. |
void |
resumeWrites()
Indicate that the conduit's
WriteReadyHandler should be invoked as soon as data can be written
without blocking. |
void |
setIdleTimeout(long idleTimeout) |
void |
setReadReadyHandler(ReadReadyHandler handler)
Set the handler which should receive readiness notifications.
|
void |
setWriteReadyHandler(WriteReadyHandler handler)
Set the handler which should receive readiness notifications.
|
void |
suspendReads()
Indicate that calling the conduit's
ReadReadyHandler should be suspended. |
void |
suspendWrites()
Indicate that calling the conduit's
WriteReadyHandler should be suspended. |
void |
terminateReads()
Indicate that no more data will be read from this conduit.
|
void |
terminateWrites()
Signal that no more write data is forthcoming.
|
long |
transferFrom(FileChannel src,
long position,
long count)
Transfer bytes into this conduit from the given file.
|
long |
transferFrom(StreamSourceChannel source,
long count,
ByteBuffer throughBuffer)
Transfers bytes from the given channel source.
|
long |
transferTo(long count,
ByteBuffer throughBuffer,
StreamSinkChannel target)
Transfers bytes into the given channel target.
|
long |
transferTo(long position,
long count,
FileChannel target)
Transfers bytes into the given file from this channel.
|
void |
truncateWrites()
Terminate writes and discard any outstanding write data.
|
void |
wakeupReads()
Indicate that the conduit's
ReadReadyHandler should be invoked immediately, and then again as soon
as data can be read without blocking. |
void |
wakeupWrites()
Indicate that the conduit's
WriteReadyHandler should be invoked immediately, and then again as soon
as data can be written without blocking. |
int |
write(ByteBuffer src)
Writes a sequence of bytes to this conduit from the given buffer.
|
long |
write(ByteBuffer[] srcs,
int offset,
int length)
Writes a sequence of bytes to this conduit from the given buffers.
|
int |
writeFinal(ByteBuffer src)
Writes some data to the conduit, with the same semantics as
StreamSinkConduit.write(java.nio.ByteBuffer) . |
long |
writeFinal(ByteBuffer[] srcs,
int offset,
int length)
Writes some data to the conduit, with the same semantics as
StreamSinkConduit.write(java.nio.ByteBuffer[], int, int) . |
public IdleTimeoutConduit(StreamConnection connection)
protected void doClose()
public int write(ByteBuffer src) throws IOException
StreamSinkConduit
write
in interface StreamSinkConduit
src
- the buffer containing data to writeClosedChannelException
- if this conduit's SinkConduit.terminateWrites()
method was previously calledIOException
- if an error occurspublic long write(ByteBuffer[] srcs, int offset, int length) throws IOException
StreamSinkConduit
write
in interface StreamSinkConduit
srcs
- the buffers containing data to writeoffset
- the offset into the buffer arraylength
- the number of buffers to writeClosedChannelException
- if this conduit's SinkConduit.terminateWrites()
method was previously calledIOException
- if an error occurspublic int writeFinal(ByteBuffer src) throws IOException
StreamSinkConduit
StreamSinkConduit.write(java.nio.ByteBuffer)
. If all the data is written
out then the conduit will have its writes terminated. Semantically this
method is equivalent to:
int rem = src.remaining();
int written = conduit.write(src);
if(written == rem) {
conduit.terminateWrites()
}
writeFinal
in interface StreamSinkConduit
src
- The data to writeIOException
public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException
StreamSinkConduit
StreamSinkConduit.write(java.nio.ByteBuffer[], int, int)
. If all the data is written
out then the conduit will have its writes terminated.writeFinal
in interface StreamSinkConduit
srcs
- 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 - offsetIOException
public long transferTo(long position, long count, FileChannel target) throws IOException
StreamSourceConduit
transferTo
in interface StreamSourceConduit
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 target) throws IOException
StreamSourceConduit
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.transferTo
in interface StreamSourceConduit
count
- the number of bytes to be transferredthroughBuffer
- the buffer to copy through.target
- the destination to write toIOException
- if an I/O error occurspublic long read(ByteBuffer[] dsts, int offset, int length) throws IOException
StreamSourceConduit
read
in interface StreamSourceConduit
offset
- the offset into the buffer arraylength
- the number of buffers to fillSourceConduit.terminateReads()
method was previously calledIOException
- if an error occurspublic int read(ByteBuffer dst) throws IOException
StreamSourceConduit
read
in interface StreamSourceConduit
SourceConduit.terminateReads()
method was previously calledIOException
- if an error occurspublic long transferFrom(FileChannel src, long position, long count) throws IOException
StreamSinkConduit
transferFrom
in interface StreamSinkConduit
src
- 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
StreamSinkConduit
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.transferFrom
in interface StreamSinkConduit
source
- 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 suspendReads()
SourceConduit
ReadReadyHandler
should be suspended.suspendReads
in interface SourceConduit
public void terminateReads() throws IOException
SourceConduit
terminateReads
in interface SourceConduit
IOException
- if there was a problempublic boolean isReadShutdown()
SourceConduit
isReadShutdown
in interface SourceConduit
true
if writes are shut down, false
otherwisepublic void resumeReads()
SourceConduit
ReadReadyHandler
should be invoked as soon as data can be read
without blocking.resumeReads
in interface SourceConduit
public boolean isReadResumed()
SourceConduit
isReadResumed
in interface SourceConduit
true
if read notifications are enabledpublic void wakeupReads()
SourceConduit
ReadReadyHandler
should be invoked immediately, and then again as soon
as data can be read without blocking.wakeupReads
in interface SourceConduit
public void awaitReadable() throws IOException
SourceConduit
awaitReadable
in interface SourceConduit
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 time, TimeUnit timeUnit) throws IOException
SourceConduit
awaitReadable
in interface SourceConduit
time
- 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 XnioIoThread getReadThread()
SourceConduit
getReadThread
in interface SourceConduit
public void setReadReadyHandler(ReadReadyHandler handler)
SourceConduit
setReadReadyHandler
in interface SourceConduit
public void terminateWrites() throws IOException
SinkConduit
SinkConduit.flush()
ed before it is considered
to be shut down.terminateWrites
in interface SinkConduit
IOException
public boolean isWriteShutdown()
SinkConduit
isWriteShutdown
in interface SinkConduit
true
if writes are fully shut down, false
otherwisepublic void resumeWrites()
SinkConduit
WriteReadyHandler
should be invoked as soon as data can be written
without blocking.resumeWrites
in interface SinkConduit
public void suspendWrites()
SinkConduit
WriteReadyHandler
should be suspended.suspendWrites
in interface SinkConduit
public void wakeupWrites()
SinkConduit
WriteReadyHandler
should be invoked immediately, and then again as soon
as data can be written without blocking.wakeupWrites
in interface SinkConduit
public boolean isWriteResumed()
SinkConduit
isWriteResumed
in interface SinkConduit
true
if write notifications are enabledpublic void awaitWritable() throws IOException
SinkConduit
awaitWritable
in interface SinkConduit
InterruptedIOException
- if the operation is interrupted; the thread's interrupt flag will be set
as wellIOException
- if an I/O error occurspublic void awaitWritable(long time, TimeUnit timeUnit) throws IOException
SinkConduit
awaitWritable
in interface SinkConduit
time
- 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 XnioIoThread getWriteThread()
SinkConduit
getWriteThread
in interface SinkConduit
null
if none is configured or availablepublic void setWriteReadyHandler(WriteReadyHandler handler)
SinkConduit
setWriteReadyHandler
in interface SinkConduit
public void truncateWrites() throws IOException
SinkConduit
truncateWrites
in interface SinkConduit
IOException
- if channel termination failed for some reasonpublic boolean flush() throws IOException
SinkConduit
flush
in interface SinkConduit
true
if everything is flushed, false
otherwiseIOException
- if flush failspublic XnioWorker getWorker()
Conduit
public long getIdleTimeout()
public void setIdleTimeout(long idleTimeout)
Copyright © 2017 JBoss by Red Hat. All rights reserved.