Package org.xnio.channels
Class AssembledMessageChannel
java.lang.Object
org.xnio.channels.AssembledMessageChannel
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,InterruptibleChannel,CloseableChannel,Configurable,MessageChannel,ReadableMessageChannel,SuspendableChannel,SuspendableReadChannel,SuspendableWriteChannel,WritableMessageChannel
- Direct Known Subclasses:
AssembledConnectedMessageChannel
A bidirectional message channel assembled from a readable and writable message channel.
- Author:
- David M. Lloyd
-
Field Summary
Fields inherited from interface org.xnio.channels.Configurable
EMPTY -
Constructor Summary
ConstructorsConstructorDescriptionAssembledMessageChannel(CloseableChannel closeable, ReadableMessageChannel readable, WritableMessageChannel writable) Construct a new instance.AssembledMessageChannel(ReadableMessageChannel readable, WritableMessageChannel writable) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidBlock until this channel becomes readable again.voidawaitReadable(long time, TimeUnit timeUnit) Block until this channel becomes readable again, or until the timeout expires.voidBlock until this channel becomes writable again.voidawaitWritable(long time, TimeUnit timeUnit) Block until this channel becomes writable again, or until the timeout expires.voidclose()Close this channel.booleanflush()Flush any waiting partial send or write.ChannelListener.Setter<? extends AssembledMessageChannel>Get the setter which can be used to change the close listener for this channel.Get the I/O thread associated with this channel.<T> TGet the value of a channel option.ChannelListener.Setter<? extends AssembledMessageChannel>Get the setter which can be used to change the read listener for this channel.Deprecated.Get the worker for this channel.ChannelListener.Setter<? extends AssembledMessageChannel>Get the setter which can be used to change the write listener for this channel.Deprecated.booleanisOpen()Determine whether this channel is open.booleanDetermine whether reads are resumed.booleanDetermine whether writes are resumed.intreceive(ByteBuffer buffer) Receive a message.longreceive(ByteBuffer[] buffers) Receive a message.longreceive(ByteBuffer[] buffers, int offs, int len) Receive a message.voidResume reads on this channel.voidResume writes on this channel.booleansend(ByteBuffer buffer) Send a complete message.booleansend(ByteBuffer[] buffers) Send a complete message.booleansend(ByteBuffer[] buffers, int offs, int len) Send a complete message.booleansendFinal(ByteBuffer buffer) Send a complete message.booleansendFinal(ByteBuffer[] buffers) Send a complete message.booleansendFinal(ByteBuffer[] buffers, int offs, int len) Send a complete message.<T> TSet an option for this channel.voidPlaces this readable channel at "end of stream".voidIndicate that writing is complete for this channel.booleansupportsOption(Option<?> option) Determine whether an option is supported on this channel.voidSuspend further read notifications on this channel.voidSuspend further write notifications on this channel.voidResume readson this channel, and force the read listener to be triggered even if the channel isn't actually readable.voidResume writeson this channel, and force the write listener to be triggered even if the channel isn't actually writable.
-
Constructor Details
-
AssembledMessageChannel
public AssembledMessageChannel(CloseableChannel closeable, ReadableMessageChannel readable, WritableMessageChannel writable) Construct a new instance.- Parameters:
closeable- the single central closeable channelreadable- the read channelwritable- the write channel
-
AssembledMessageChannel
Construct a new instance.- Parameters:
readable- the read channelwritable- the write channel
-
-
Method Details
-
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
-
getReadSetter
Description copied from interface:MessageChannelGet the setter which can be used to change the read listener for this channel.- Specified by:
getReadSetterin interfaceMessageChannel- Specified by:
getReadSetterin interfaceReadableMessageChannel- Specified by:
getReadSetterin interfaceSuspendableChannel- Specified by:
getReadSetterin interfaceSuspendableReadChannel- Returns:
- the setter
-
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
Description 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:
IOException- if an I/O error occurs
-
awaitReadable
Description 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:
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: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:
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:SuspendableReadChannelGet the read thread for this channel.- Specified by:
getReadThreadin interfaceSuspendableReadChannel- Returns:
- the thread, or
nullif none is configured or available
-
receive
Description copied from interface:ReadableMessageChannelReceive a message.- Specified by:
receivein interfaceReadableMessageChannel- Parameters:
buffer- 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
-
receive
Description copied from interface:ReadableMessageChannelReceive a message.- Specified by:
receivein interfaceReadableMessageChannel- Parameters:
buffers- 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:ReadableMessageChannelReceive a message.- Specified by:
receivein interfaceReadableMessageChannel- Parameters:
buffers- the buffers that will hold the messageoffs- the offset into the array of buffers of the first buffer to read intolen- 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
-
getWriteSetter
Description copied from interface:MessageChannelGet the setter which can be used to change the write listener for this channel.- Specified by:
getWriteSetterin interfaceMessageChannel- Specified by:
getWriteSetterin interfaceSuspendableChannel- Specified by:
getWriteSetterin interfaceSuspendableWriteChannel- Specified by:
getWriteSetterin interfaceWritableMessageChannel- Returns:
- the setter
-
suspendWrites
public void suspendWrites()Description copied from interface:SuspendableWriteChannelSuspend further write notifications on this channel.- Specified by:
suspendWritesin interfaceSuspendableWriteChannel
-
resumeWrites
public void resumeWrites()Description copied from interface:SuspendableWriteChannelResume writes on this channel. The write listener will be called as soon as the channel becomes writable.- Specified by:
resumeWritesin interfaceSuspendableWriteChannel
-
isWriteResumed
public boolean isWriteResumed()Description copied from interface:SuspendableWriteChannelDetermine whether writes are resumed.- Specified by:
isWriteResumedin interfaceSuspendableWriteChannel- Returns:
trueif writes are resumed,falseif writes are suspended
-
wakeupWrites
public void wakeupWrites()Description copied from interface:SuspendableWriteChannelResume writeson this channel, and force the write listener to be triggered even if the channel isn't actually writable.- Specified by:
wakeupWritesin interfaceSuspendableWriteChannel
-
shutdownWrites
Description copied from interface:SuspendableWriteChannelIndicate that writing is complete for this channel. Further attempts to write data to this channel after this method is invoked will result in an exception. If this method was already called, calling this method again will have no additional effect. After this method is called, any remaining data still must be flushed out via theSuspendableWriteChannel.flush()method; once this is done, if the read side of the channel was shut down, the channel will automatically close.- Specified by:
shutdownWritesin interfaceSuspendableWriteChannel- Throws:
IOException- if an I/O error occurs
-
awaitWritable
Description copied from interface:SuspendableWriteChannelBlock until this channel becomes writable again. This method may return spuriously before the channel becomes writable.- Specified by:
awaitWritablein interfaceSuspendableWriteChannel- Throws:
InterruptedIOException- if the operation is interrupted; the thread's interrupt flag will be set as wellIOException- if an I/O error occurs
-
awaitWritable
Description copied from interface:SuspendableWriteChannelBlock until this channel becomes writable again, or until the timeout expires. This method may return spuriously before the channel becomes writable or the timeout expires.- Specified by:
awaitWritablein interfaceSuspendableWriteChannel- 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
-
getWriteThread
Deprecated.Description copied from interface:SuspendableWriteChannelGet the write thread for this channel.- Specified by:
getWriteThreadin interfaceSuspendableWriteChannel- Returns:
- the thread, or
nullif none is configured or available
-
send
Description copied from interface:WritableMessageChannelSend a complete message.- Specified by:
sendin interfaceWritableMessageChannel- Parameters:
buffer- the message to send- Returns:
- the result of the send operation;
trueif the message was sent, orfalseif it would block - Throws:
IOException- if an I/O error occurs
-
send
Description copied from interface:WritableMessageChannelSend a complete message.- Specified by:
sendin interfaceWritableMessageChannel- Parameters:
buffers- the buffers holding the message to send- Returns:
- the result of the send operation;
trueif the message was sent, orfalseif it would block - Throws:
IOException- if an I/O error occurs
-
send
Description copied from interface:WritableMessageChannelSend a complete message.- Specified by:
sendin interfaceWritableMessageChannel- Parameters:
buffers- the buffers holding the message to sendoffs- the offset into the buffer array of the first bufferlen- the number of buffers that contain data to send- Returns:
- the result of the send operation;
trueif the message was sent, orfalseif it would block - Throws:
IOException- if an I/O error occurs
-
sendFinal
Description copied from interface:WritableMessageChannelSend a complete message. If the message was successfully sent the channel with have its writes shutdown.- Specified by:
sendFinalin interfaceWritableMessageChannel- Parameters:
buffer- the message to send- Returns:
- the result of the send operation;
trueif the message was sent, orfalseif it would block - Throws:
IOException- if an I/O error occurs
-
sendFinal
Description copied from interface:WritableMessageChannelSend a complete message. If the message was successfully sent the channel with have its writes shutdown.- Specified by:
sendFinalin interfaceWritableMessageChannel- Parameters:
buffers- the buffers holding the message to send- Returns:
- the result of the send operation;
trueif the message was sent, orfalseif it would block - Throws:
IOException- if an I/O error occurs
-
sendFinal
Description copied from interface:WritableMessageChannelSend a complete message. If the message was successfully sent the channel with have its writes shutdown.- Specified by:
sendFinalin interfaceWritableMessageChannel- Parameters:
buffers- the buffers holding the message to sendoffs- the offset into the buffer array of the first bufferlen- the number of buffers that contain data to send- Returns:
- the result of the send operation;
trueif the message was sent, orfalseif it would block - Throws:
IOException- if an I/O error occurs
-
flush
Description copied from interface:SuspendableWriteChannelFlush any waiting partial send or write. If there is no data to flush, or if the flush completed successfully, this method will returntrue. If there is data to flush which cannot be immediately written, this method will returnfalse. If this method returnstrueafterSuspendableWriteChannel.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.- Specified by:
flushin interfaceSuspendableWriteChannel- Returns:
trueif the message was flushed, orfalseif the result would block- Throws:
IOException- if an I/O error occurs
-
getCloseSetter
Description copied from interface:MessageChannelGet 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 interfaceMessageChannel- Specified by:
getCloseSetterin interfaceReadableMessageChannel- Specified by:
getCloseSetterin interfaceSuspendableChannel- Specified by:
getCloseSetterin interfaceSuspendableReadChannel- Specified by:
getCloseSetterin interfaceSuspendableWriteChannel- Specified by:
getCloseSetterin interfaceWritableMessageChannel- Returns:
- the setter
-
getWorker
Description copied from interface:CloseableChannelGet the worker for this channel.- Specified by:
getWorkerin interfaceCloseableChannel- Returns:
- the worker
-
close
Description 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 interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCloseableChannel- Specified by:
closein interfaceInterruptibleChannel- Specified by:
closein interfaceSuspendableWriteChannel- Throws:
IOException- if the close failed
-
isOpen
public boolean isOpen()Description copied from interface:SuspendableWriteChannelDetermine whether this channel is open. This method will returnfalseif all directions are shut down, even if there is unflushed write data pending.- Specified by:
isOpenin interfaceChannel- Specified by:
isOpenin interfaceSuspendableWriteChannel- Returns:
trueif the channel is open,falseotherwise
-
supportsOption
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
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:
IOException- if an I/O error occurred when reading the option
-
setOption
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:
IllegalArgumentException- if the value is not acceptable for this optionIOException- if an I/O error occurred when modifying the option
-