Package org.xnio.conduits
Class ConduitReadableMessageChannel
java.lang.Object
org.xnio.conduits.ConduitReadableMessageChannel
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Cloneable
,Channel
,InterruptibleChannel
,CloseableChannel
,CloseListenerSettable<ConduitReadableMessageChannel>
,Configurable
,ReadableMessageChannel
,ReadListenerSettable<ConduitReadableMessageChannel>
,SuspendableReadChannel
public final class ConduitReadableMessageChannel
extends Object
implements ReadableMessageChannel, ReadListenerSettable<ConduitReadableMessageChannel>, CloseListenerSettable<ConduitReadableMessageChannel>, Cloneable
A readable message channel which is backed by a message source conduit.
- Author:
- David M. Lloyd
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.xnio.channels.CloseListenerSettable
CloseListenerSettable.Setter<C extends Channel>
Nested classes/interfaces inherited from interface org.xnio.channels.ReadListenerSettable
ReadListenerSettable.Setter<C extends Channel>
-
Field Summary
Fields inherited from interface org.xnio.channels.Configurable
EMPTY
-
Constructor Summary
ConstructorsConstructorDescriptionConduitReadableMessageChannel
(Configurable configurable, MessageSourceConduit conduit) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Block until this channel becomes readable again.void
awaitReadable
(long time, TimeUnit timeUnit) Block until this channel becomes readable again, or until the timeout expires.clone()
Duplicate this channel.void
close()
Close this channel.Get the close listener.Get the setter which can be used to change the close listener for this channel.Get the underlying conduit for this channel.Get the I/O thread associated with this channel.<T> T
Get the value of a channel option.Get the read listener.Get the setter which can be used to change the read listener for this channel.Deprecated.Get the worker for this channel.boolean
isOpen()
boolean
Determine whether reads are resumed.int
receive
(ByteBuffer dst) Receive a message.long
receive
(ByteBuffer[] dsts) Receive a message.long
receive
(ByteBuffer[] dsts, int offset, int length) Receive a message.void
Resume reads on this channel.void
setCloseListener
(ChannelListener<? super ConduitReadableMessageChannel> closeListener) Set the close listener.void
setConduit
(MessageSourceConduit conduit) Set the underlying conduit for this channel.<T> T
Set an option for this channel.void
setReadListener
(ChannelListener<? super ConduitReadableMessageChannel> readListener) Set the read listener.void
Places this readable channel at "end of stream".boolean
supportsOption
(Option<?> option) Determine whether an option is supported on this channel.void
Suspend further read notifications on this channel.void
Resume reads
on this channel, and force the read listener to be triggered even if the channel isn't actually readable.
-
Constructor Details
-
ConduitReadableMessageChannel
Construct a new instance.- Parameters:
configurable
- the configurable to delegate configuration requests toconduit
- the initial conduit to use for data transport
-
-
Method Details
-
getConduit
Get the underlying conduit for this channel.- Returns:
- the underlying conduit for this channel
-
setConduit
Set the underlying conduit for this channel.- Parameters:
conduit
- the underlying conduit for this channel
-
isOpen
public boolean isOpen() -
setReadListener
Description copied from interface:ReadListenerSettable
Set the read listener.- Specified by:
setReadListener
in interfaceReadListenerSettable<ConduitReadableMessageChannel>
- Parameters:
readListener
- the read listener
-
getReadListener
Description copied from interface:ReadListenerSettable
Get the read listener.- Specified by:
getReadListener
in interfaceReadListenerSettable<ConduitReadableMessageChannel>
- Returns:
- the read listener
-
setCloseListener
Description copied from interface:CloseListenerSettable
Set the close listener.- Specified by:
setCloseListener
in interfaceCloseListenerSettable<ConduitReadableMessageChannel>
- Parameters:
closeListener
- the close listener
-
getCloseListener
Description copied from interface:CloseListenerSettable
Get the close listener.- Specified by:
getCloseListener
in interfaceCloseListenerSettable<ConduitReadableMessageChannel>
- Returns:
- the close listener
-
getReadSetter
Description copied from interface:ReadableMessageChannel
Get the setter which can be used to change the read listener for this channel.- Specified by:
getReadSetter
in interfaceReadableMessageChannel
- Specified by:
getReadSetter
in interfaceSuspendableReadChannel
- Returns:
- the setter
-
getCloseSetter
Description copied from interface:ReadableMessageChannel
Get the setter which can be used to change the close listener for this channel. If the channel is already closed, then the listener will not be called.- Specified by:
getCloseSetter
in interfaceCloseableChannel
- Specified by:
getCloseSetter
in interfaceReadableMessageChannel
- Specified by:
getCloseSetter
in interfaceSuspendableReadChannel
- Returns:
- the setter
-
getWorker
Description copied from interface:CloseableChannel
Get the worker for this channel.- Specified by:
getWorker
in interfaceCloseableChannel
- Returns:
- the worker
-
receive
Description copied from interface:ReadableMessageChannel
Receive a message.- Specified by:
receive
in interfaceReadableMessageChannel
- Parameters:
dsts
- the buffers that will hold the messageoffset
- the offset into the array of buffers of the first buffer to read intolength
- the number of buffers to fill- Returns:
- the size of the received message, 0 if no message is available, and -1 if the message channel has reached an end-of-file condition
- Throws:
IOException
- if an I/O error occurs
-
receive
Description copied from interface:ReadableMessageChannel
Receive a message.- Specified by:
receive
in interfaceReadableMessageChannel
- Parameters:
dsts
- the buffers that will hold the message- Returns:
- the size of the received message, 0 if no message is available, and -1 if the message channel has reached an end-of-file condition
- Throws:
IOException
- if an I/O error occurs
-
receive
Description copied from interface:ReadableMessageChannel
Receive a message.- Specified by:
receive
in interfaceReadableMessageChannel
- Parameters:
dst
- the buffer that will hold the message- Returns:
- the size of the received message, 0 if no message is available, and -1 if the message channel has reached an end-of-file condition
- Throws:
IOException
- if an I/O error occurs
-
suspendReads
public void suspendReads()Description copied from interface:SuspendableReadChannel
Suspend further read notifications on this channel.- Specified by:
suspendReads
in interfaceSuspendableReadChannel
-
resumeReads
public void resumeReads()Description copied from interface:SuspendableReadChannel
Resume reads on this channel. The read listener will be called as soon as there is data available to be read.- Specified by:
resumeReads
in interfaceSuspendableReadChannel
-
isReadResumed
public boolean isReadResumed()Description copied from interface:SuspendableReadChannel
Determine whether reads are resumed.- Specified by:
isReadResumed
in interfaceSuspendableReadChannel
- Returns:
true
if reads are resumed,false
if reads are suspended
-
wakeupReads
public void wakeupReads()Description copied from interface:SuspendableReadChannel
Resume reads
on this channel, and force the read listener to be triggered even if the channel isn't actually readable.- Specified by:
wakeupReads
in interfaceSuspendableReadChannel
-
shutdownReads
Description copied from interface:SuspendableReadChannel
Places this readable channel at "end of stream". Further reads will result in EOF. Shutting down all directions of a channel will causeCloseableChannel.close()
to be called automatically.- Specified by:
shutdownReads
in interfaceSuspendableReadChannel
- Throws:
IOException
- if an I/O error occurs
-
awaitReadable
Description copied from interface:SuspendableReadChannel
Block until this channel becomes readable again. This method may return spuriously before the channel becomes readable.- Specified by:
awaitReadable
in interfaceSuspendableReadChannel
- Throws:
InterruptedIOException
- if the operation is interrupted; the thread's interrupt flag will be set as wellIOException
- if an I/O error occurs
-
awaitReadable
Description copied from interface:SuspendableReadChannel
Block until this channel becomes readable again, or until the timeout expires. This method may return spuriously before the channel becomes readable or the timeout expires.- Specified by:
awaitReadable
in interfaceSuspendableReadChannel
- Parameters:
time
- the time to waittimeUnit
- the time unit- Throws:
InterruptedIOException
- if the operation is interrupted; the thread's interrupt flag will be set as wellIOException
- if an I/O error occurs
-
getReadThread
Deprecated.Description copied from interface:SuspendableReadChannel
Get the read thread for this channel.- Specified by:
getReadThread
in interfaceSuspendableReadChannel
- Returns:
- the thread, or
null
if none is configured or available
-
getIoThread
Description copied from interface:CloseableChannel
Get the I/O thread associated with this channel.- Specified by:
getIoThread
in interfaceCloseableChannel
- Returns:
- the I/O thread associated with this channel
-
close
Description copied from interface:CloseableChannel
Close this channel. When a channel is closed, its close listener is invoked. Invoking this method more than once has no additional effect.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceCloseableChannel
- Specified by:
close
in interfaceInterruptibleChannel
- Throws:
IOException
- if the close failed
-
supportsOption
Description copied from interface:Configurable
Determine whether an option is supported on this channel.- Specified by:
supportsOption
in interfaceConfigurable
- Parameters:
option
- the option- Returns:
true
if it is supported
-
getOption
Description copied from interface:Configurable
Get the value of a channel option.- Specified by:
getOption
in interfaceConfigurable
- Type Parameters:
T
- the type of the option value- Parameters:
option
- the option to get- Returns:
- the value of the option, or
null
if it is not set - Throws:
IOException
- if an I/O error occurred when reading the option
-
setOption
Description copied from interface:Configurable
Set an option for this channel. Unsupported options are ignored.- Specified by:
setOption
in interfaceConfigurable
- Type Parameters:
T
- the type of the option value- Parameters:
option
- the option to setvalue
- the value of the option to set- Returns:
- the previous option value, if any
- Throws:
IllegalArgumentException
- if the value is not acceptable for this optionIOException
- if an I/O error occurred when modifying the option
-
clone
Duplicate this channel. Changing the delegate conduit in one channel will not affect the other.
-