- java.lang.Object
-
- org.xnio.conduits.ConduitReadableMessageChannel
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Cloneable,java.nio.channels.Channel,java.nio.channels.InterruptibleChannel,CloseableChannel,CloseListenerSettable<ConduitReadableMessageChannel>,Configurable,ReadableMessageChannel,ReadListenerSettable<ConduitReadableMessageChannel>,SuspendableReadChannel
public final class ConduitReadableMessageChannel extends java.lang.Object implements ReadableMessageChannel, ReadListenerSettable<ConduitReadableMessageChannel>, CloseListenerSettable<ConduitReadableMessageChannel>, java.lang.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 java.nio.channels.Channel>
-
Nested classes/interfaces inherited from interface org.xnio.channels.ReadListenerSettable
ReadListenerSettable.Setter<C extends java.nio.channels.Channel>
-
-
Field Summary
-
Fields inherited from interface org.xnio.channels.Configurable
EMPTY
-
-
Constructor Summary
Constructors Constructor Description ConduitReadableMessageChannel(Configurable configurable, MessageSourceConduit conduit)Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidawaitReadable()Block until this channel becomes readable again.voidawaitReadable(long time, java.util.concurrent.TimeUnit timeUnit)Block until this channel becomes readable again, or until the timeout expires.ConduitReadableMessageChannelclone()Duplicate this channel.voidclose()Close this channel.ChannelListener<? super ConduitReadableMessageChannel>getCloseListener()Get the close listener.ChannelListener.Setter<ConduitReadableMessageChannel>getCloseSetter()Get the setter which can be used to change the close listener for this channel.MessageSourceConduitgetConduit()Get the underlying conduit for this channel.XnioIoThreadgetIoThread()Get the I/O thread associated with this channel.<T> TgetOption(Option<T> option)Get the value of a channel option.ChannelListener<? super ConduitReadableMessageChannel>getReadListener()Get the read listener.ChannelListener.Setter<ConduitReadableMessageChannel>getReadSetter()Get the setter which can be used to change the read listener for this channel.XnioExecutorgetReadThread()Deprecated.XnioWorkergetWorker()Get the worker for this channel.booleanisOpen()booleanisReadResumed()Determine whether reads are resumed.intreceive(java.nio.ByteBuffer dst)Receive a message.longreceive(java.nio.ByteBuffer[] dsts)Receive a message.longreceive(java.nio.ByteBuffer[] dsts, int offset, int length)Receive a message.voidresumeReads()Resume reads on this channel.voidsetCloseListener(ChannelListener<? super ConduitReadableMessageChannel> closeListener)Set the close listener.voidsetConduit(MessageSourceConduit conduit)Set the underlying conduit for this channel.<T> TsetOption(Option<T> option, T value)Set an option for this channel.voidsetReadListener(ChannelListener<? super ConduitReadableMessageChannel> readListener)Set the read listener.voidshutdownReads()Places this readable channel at "end of stream".booleansupportsOption(Option<?> option)Determine whether an option is supported on this channel.voidsuspendReads()Suspend further read notifications on this channel.voidwakeupReads()Resume readson this channel, and force the read listener to be triggered even if the channel isn't actually readable.
-
-
-
Constructor Detail
-
ConduitReadableMessageChannel
public ConduitReadableMessageChannel(Configurable configurable, MessageSourceConduit conduit)
Construct a new instance.- Parameters:
configurable- the configurable to delegate configuration requests toconduit- the initial conduit to use for data transport
-
-
Method Detail
-
getConduit
public MessageSourceConduit getConduit()
Get the underlying conduit for this channel.- Returns:
- the underlying conduit for this channel
-
setConduit
public void setConduit(MessageSourceConduit conduit)
Set the underlying conduit for this channel.- Parameters:
conduit- the underlying conduit for this channel
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
setReadListener
public void setReadListener(ChannelListener<? super ConduitReadableMessageChannel> readListener)
Description copied from interface:ReadListenerSettableSet the read listener.- Specified by:
setReadListenerin interfaceReadListenerSettable<ConduitReadableMessageChannel>- Parameters:
readListener- the read listener
-
getReadListener
public ChannelListener<? super ConduitReadableMessageChannel> getReadListener()
Description copied from interface:ReadListenerSettableGet the read listener.- Specified by:
getReadListenerin interfaceReadListenerSettable<ConduitReadableMessageChannel>- Returns:
- the read listener
-
setCloseListener
public void setCloseListener(ChannelListener<? super ConduitReadableMessageChannel> closeListener)
Description copied from interface:CloseListenerSettableSet the close listener.- Specified by:
setCloseListenerin interfaceCloseListenerSettable<ConduitReadableMessageChannel>- Parameters:
closeListener- the close listener
-
getCloseListener
public ChannelListener<? super ConduitReadableMessageChannel> getCloseListener()
Description copied from interface:CloseListenerSettableGet the close listener.- Specified by:
getCloseListenerin interfaceCloseListenerSettable<ConduitReadableMessageChannel>- Returns:
- the close listener
-
getReadSetter
public ChannelListener.Setter<ConduitReadableMessageChannel> getReadSetter()
Description copied from interface:ReadableMessageChannelGet the setter which can be used to change the read listener for this channel.- Specified by:
getReadSetterin interfaceReadableMessageChannel- Specified by:
getReadSetterin interfaceSuspendableReadChannel- Returns:
- the setter
-
getCloseSetter
public ChannelListener.Setter<ConduitReadableMessageChannel> getCloseSetter()
Description copied from interface:ReadableMessageChannelGet 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:
getCloseSetterin interfaceCloseableChannel- Specified by:
getCloseSetterin interfaceReadableMessageChannel- Specified by:
getCloseSetterin interfaceSuspendableReadChannel- Returns:
- the setter
-
getWorker
public XnioWorker getWorker()
Description copied from interface:CloseableChannelGet the worker for this channel.- Specified by:
getWorkerin interfaceCloseableChannel- Returns:
- the worker
-
receive
public long receive(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOExceptionDescription copied from interface:ReadableMessageChannelReceive a message.- Specified by:
receivein 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:
java.io.IOException- if an I/O error occurs
-
receive
public long receive(java.nio.ByteBuffer[] dsts) throws java.io.IOExceptionDescription copied from interface:ReadableMessageChannelReceive a message.- Specified by:
receivein 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:
java.io.IOException- if an I/O error occurs
-
receive
public int receive(java.nio.ByteBuffer dst) throws java.io.IOExceptionDescription copied from interface:ReadableMessageChannelReceive a message.- Specified by:
receivein 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:
java.io.IOException- if an I/O error occurs
-
suspendReads
public void suspendReads()
Description copied from interface:SuspendableReadChannelSuspend further read notifications on this channel.- Specified by:
suspendReadsin interfaceSuspendableReadChannel
-
resumeReads
public void resumeReads()
Description copied from interface:SuspendableReadChannelResume reads on this channel. The read listener will be called as soon as there is data available to be read.- Specified by:
resumeReadsin interfaceSuspendableReadChannel
-
isReadResumed
public boolean isReadResumed()
Description copied from interface:SuspendableReadChannelDetermine whether reads are resumed.- Specified by:
isReadResumedin interfaceSuspendableReadChannel- Returns:
trueif reads are resumed,falseif reads are suspended
-
wakeupReads
public void wakeupReads()
Description copied from interface:SuspendableReadChannelResume readson this channel, and force the read listener to be triggered even if the channel isn't actually readable.- Specified by:
wakeupReadsin interfaceSuspendableReadChannel
-
shutdownReads
public void shutdownReads() throws java.io.IOExceptionDescription copied from interface:SuspendableReadChannelPlaces 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:
shutdownReadsin interfaceSuspendableReadChannel- Throws:
java.io.IOException- if an I/O error occurs
-
awaitReadable
public void awaitReadable() throws java.io.IOExceptionDescription copied from interface:SuspendableReadChannelBlock until this channel becomes readable again. This method may return spuriously before the channel becomes readable.- Specified by:
awaitReadablein interfaceSuspendableReadChannel- Throws:
java.io.InterruptedIOException- if the operation is interrupted; the thread's interrupt flag will be set as welljava.io.IOException- if an I/O error occurs
-
awaitReadable
public void awaitReadable(long time, java.util.concurrent.TimeUnit timeUnit) throws java.io.IOExceptionDescription copied from interface:SuspendableReadChannelBlock 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:
awaitReadablein interfaceSuspendableReadChannel- Parameters:
time- the time to waittimeUnit- the time unit- Throws:
java.io.InterruptedIOException- if the operation is interrupted; the thread's interrupt flag will be set as welljava.io.IOException- if an I/O error occurs
-
getReadThread
@Deprecated public XnioExecutor getReadThread()
Deprecated.Description copied from interface:SuspendableReadChannelGet the read thread for this channel.- Specified by:
getReadThreadin interfaceSuspendableReadChannel- Returns:
- the thread, or
nullif none is configured or available
-
getIoThread
public XnioIoThread getIoThread()
Description copied from interface:CloseableChannelGet the I/O thread associated with this channel.- Specified by:
getIoThreadin interfaceCloseableChannel- Returns:
- the I/O thread associated with this channel
-
close
public void close() throws java.io.IOExceptionDescription copied from interface:CloseableChannelClose this channel. When a channel is closed, its close listener is invoked. Invoking this method more than once has no additional effect.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceCloseableChannel- Specified by:
closein interfacejava.nio.channels.InterruptibleChannel- Throws:
java.io.IOException- if the close failed
-
supportsOption
public boolean supportsOption(Option<?> option)
Description copied from interface:ConfigurableDetermine whether an option is supported on this channel.- Specified by:
supportsOptionin interfaceConfigurable- Parameters:
option- the option- Returns:
trueif it is supported
-
getOption
public <T> T getOption(Option<T> option) throws java.io.IOException
Description copied from interface:ConfigurableGet the value of a channel option.- Specified by:
getOptionin interfaceConfigurable- Type Parameters:
T- the type of the option value- Parameters:
option- the option to get- Returns:
- the value of the option, or
nullif it is not set - Throws:
java.io.IOException- if an I/O error occurred when reading the option
-
setOption
public <T> T setOption(Option<T> option, T value) throws java.lang.IllegalArgumentException, java.io.IOException
Description copied from interface:ConfigurableSet an option for this channel. Unsupported options are ignored.- Specified by:
setOptionin 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:
java.lang.IllegalArgumentException- if the value is not acceptable for this optionjava.io.IOException- if an I/O error occurred when modifying the option
-
clone
public ConduitReadableMessageChannel clone()
Duplicate this channel. Changing the delegate conduit in one channel will not affect the other.- Overrides:
clonein classjava.lang.Object- Returns:
- the cloned channel
-
-