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`

public class AssembledMessageChannel extends Object implements MessageChannel
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

Constructors
Constructor
Description
`AssembledMessageChannel(CloseableChannel closeable, ReadableMessageChannel readable, WritableMessageChannel writable)`
Construct a new instance.
`AssembledMessageChannel(ReadableMessageChannel readable, WritableMessageChannel writable)`
Construct a new instance.

## Method Summary

Modifier and Type
Method
Description
`void`
`awaitReadable()`
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.
`void`
`awaitWritable()`
Block until this channel becomes writable again.
`void`
`awaitWritable(long time, TimeUnit timeUnit)`
Block until this channel becomes writable again, or until the timeout expires.
`void`
`close()`
Close this channel.
`boolean`
`flush()`
Flush any waiting partial send or write.
`ChannelListener.Setter<? extends AssembledMessageChannel>`
`getCloseSetter()`
Get the setter which can be used to change the close listener for this channel.
`XnioIoThread`
`getIoThread()`
Get the I/O thread associated with this channel.
`<T> T`
`getOption(Option<T> option)`
Get the value of a channel option.
`ChannelListener.Setter<? extends AssembledMessageChannel>`
`getReadSetter()`
Get the setter which can be used to change the read listener for this channel.
`XnioExecutor`
`getReadThread()`
Deprecated.
`XnioWorker`
`getWorker()`
Get the worker for this channel.
`ChannelListener.Setter<? extends AssembledMessageChannel>`
`getWriteSetter()`
Get the setter which can be used to change the write listener for this channel.
`XnioExecutor`
`getWriteThread()`
Deprecated.
`boolean`
`isOpen()`
Determine whether this channel is open.
`boolean`
`isReadResumed()`
Determine whether reads are resumed.
`boolean`
`isWriteResumed()`
Determine whether writes are resumed.
`int`
`receive(ByteBuffer buffer)`
Receive a message.
`long`
`receive(ByteBuffer[] buffers)`
Receive a message.
`long`
`receive(ByteBuffer[] buffers, int offs, int len)`
Receive a message.
`void`
`resumeReads()`
Resume reads on this channel.
`void`
`resumeWrites()`
Resume writes on this channel.
`boolean`
`send(ByteBuffer buffer)`
Send a complete message.
`boolean`
`send(ByteBuffer[] buffers)`
Send a complete message.
`boolean`
`send(ByteBuffer[] buffers, int offs, int len)`
Send a complete message.
`boolean`
`sendFinal(ByteBuffer buffer)`
Send a complete message.
`boolean`
`sendFinal(ByteBuffer[] buffers)`
Send a complete message.
`boolean`
`sendFinal(ByteBuffer[] buffers, int offs, int len)`
Send a complete message.
`<T> T`
`setOption(Option<T> option, T value)`
Set an option for this channel.
`void`
`shutdownReads()`
Places this readable channel at "end of stream".
`void`
`shutdownWrites()`
Indicate that writing is complete for this channel.
`boolean`
`supportsOption(Option<?> option)`
Determine whether an option is supported on this channel.
`void`
`suspendReads()`
Suspend further read notifications on this channel.
`void`
`suspendWrites()`
Suspend further write notifications on this channel.
`void`
`wakeupReads()`
`Resume reads` on this channel, and force the read listener to be triggered even if the channel isn't actually readable.
`void`
`wakeupWrites()`
`Resume writes` on this channel, and force the write listener to be triggered even if the channel isn't actually writable.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### AssembledMessageChannel

public AssembledMessageChannel(CloseableChannel closeable, ReadableMessageChannel readable, WritableMessageChannel writable)
Construct a new instance.

Parameters:
  `closeable` - the single central closeable channel
  `readable` - the read channel
  `writable` - the write channel

### AssembledMessageChannel

public AssembledMessageChannel(ReadableMessageChannel readable, WritableMessageChannel writable)
Construct a new instance.

Parameters:
  `readable` - the read channel
  `writable` - the write channel

## Method Details

### getIoThread

public XnioIoThread getIoThread()
Description copied from interface: `CloseableChannel`
Get the I/O thread associated with this channel.

Specified by:
  `getIoThread` in interface `CloseableChannel`
Returns:
  the I/O thread associated with this channel

### getReadSetter

public ChannelListener.Setter<? extends AssembledMessageChannel> getReadSetter()
Description copied from interface: `MessageChannel`
Get the setter which can be used to change the read listener for this channel.

Specified by:
  `getReadSetter` in interface `MessageChannel`
Specified by:
  `getReadSetter` in interface `ReadableMessageChannel`
Specified by:
  `getReadSetter` in interface `SuspendableChannel`
Specified by:
  `getReadSetter` in interface `SuspendableReadChannel`
Returns:
  the setter

### suspendReads

public void suspendReads()
Description copied from interface: `SuspendableReadChannel`
Suspend further read notifications on this channel.

Specified by:
  `suspendReads` in interface `SuspendableReadChannel`

### 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 interface `SuspendableReadChannel`

### isReadResumed

public boolean isReadResumed()
Description copied from interface: `SuspendableReadChannel`
Determine whether reads are resumed.

Specified by:
  `isReadResumed` in interface `SuspendableReadChannel`
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 interface `SuspendableReadChannel`

### shutdownReads

public void shutdownReads() throws IOException
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 cause `CloseableChannel.close()` to be called automatically.

Specified by:
  `shutdownReads` in interface `SuspendableReadChannel`
Throws:
  `IOException` - if an I/O error occurs

### awaitReadable

public void awaitReadable() throws IOException
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 interface `SuspendableReadChannel`
Throws:
  `IOException` - if an I/O error occurs

### awaitReadable

public void awaitReadable(long time, TimeUnit timeUnit) throws IOException
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 interface `SuspendableReadChannel`
Parameters:
  `time` - the time to wait
  `timeUnit` - the time unit
Throws:
  `IOException` - if an I/O error occurs

### getReadThread

@Deprecated public XnioExecutor getReadThread()
Deprecated.
Description copied from interface: `SuspendableReadChannel`
Get the read thread for this channel.

Specified by:
  `getReadThread` in interface `SuspendableReadChannel`
Returns:
  the thread, or `null` if none is configured or available

### receive

public int receive(ByteBuffer buffer) throws IOException
Description copied from interface: `ReadableMessageChannel`
Receive a message.

Specified by:
  `receive` in interface `ReadableMessageChannel`
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

public long receive(ByteBuffer[] buffers) throws IOException
Description copied from interface: `ReadableMessageChannel`
Receive a message.

Specified by:
  `receive` in interface `ReadableMessageChannel`
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

public long receive(ByteBuffer[] buffers, int offs, int len) throws IOException
Description copied from interface: `ReadableMessageChannel`
Receive a message.

Specified by:
  `receive` in interface `ReadableMessageChannel`
Parameters:
  `buffers` - the buffers that will hold the message
  `offs` - the offset into the array of buffers of the first buffer to read into
  `len` - 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

public ChannelListener.Setter<? extends AssembledMessageChannel> getWriteSetter()
Description copied from interface: `MessageChannel`
Get the setter which can be used to change the write listener for this channel.

Specified by:
  `getWriteSetter` in interface `MessageChannel`
Specified by:
  `getWriteSetter` in interface `SuspendableChannel`
Specified by:
  `getWriteSetter` in interface `SuspendableWriteChannel`
Specified by:
  `getWriteSetter` in interface `WritableMessageChannel`
Returns:
  the setter

### suspendWrites

public void suspendWrites()
Description copied from interface: `SuspendableWriteChannel`
Suspend further write notifications on this channel.

Specified by:
  `suspendWrites` in interface `SuspendableWriteChannel`

### resumeWrites

public void resumeWrites()
Description copied from interface: `SuspendableWriteChannel`
Resume writes on this channel. The write listener will be called as soon as the channel becomes writable.

Specified by:
  `resumeWrites` in interface `SuspendableWriteChannel`

### isWriteResumed

public boolean isWriteResumed()
Description copied from interface: `SuspendableWriteChannel`
Determine whether writes are resumed.

Specified by:
  `isWriteResumed` in interface `SuspendableWriteChannel`
Returns:
  `true` if writes are resumed, `false` if writes are suspended

### wakeupWrites

public void wakeupWrites()
Description copied from interface: `SuspendableWriteChannel`
`Resume writes` on this channel, and force the write listener to be triggered even if the channel isn't actually writable.

Specified by:
  `wakeupWrites` in interface `SuspendableWriteChannel`

### shutdownWrites

public void shutdownWrites() throws IOException
Description copied from interface: `SuspendableWriteChannel`
Indicate 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 the `SuspendableWriteChannel.flush()` method; once this is done, if the read side of the channel was shut down, the channel will automatically close.

Specified by:
  `shutdownWrites` in interface `SuspendableWriteChannel`
Throws:
  `IOException` - if an I/O error occurs

### awaitWritable

public void awaitWritable() throws IOException
Description copied from interface: `SuspendableWriteChannel`
Block until this channel becomes writable again. This method may return spuriously before the channel becomes writable.

Specified by:
  `awaitWritable` in interface `SuspendableWriteChannel`
Throws:
  `IOException` - if an I/O error occurs

### awaitWritable

public void awaitWritable(long time, TimeUnit timeUnit) throws IOException
Description copied from interface: `SuspendableWriteChannel`
Block 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:
  `awaitWritable` in interface `SuspendableWriteChannel`
Parameters:
  `time` - the time to wait
  `timeUnit` - the time unit
Throws:
  `IOException` - if an I/O error occurs

### getWriteThread

@Deprecated public XnioExecutor getWriteThread()
Deprecated.
Description copied from interface: `SuspendableWriteChannel`
Get the write thread for this channel.

Specified by:
  `getWriteThread` in interface `SuspendableWriteChannel`
Returns:
  the thread, or `null` if none is configured or available

### send

public boolean send(ByteBuffer buffer) throws IOException
Description copied from interface: `WritableMessageChannel`
Send a complete message.

Specified by:
  `send` in interface `WritableMessageChannel`
Parameters:
  `buffer` - the message to send
Returns:
  the result of the send operation; `true` if the message was sent, or `false` if it would block
Throws:
  `IOException` - if an I/O error occurs

### send

public boolean send(ByteBuffer[] buffers) throws IOException
Description copied from interface: `WritableMessageChannel`
Send a complete message.

Specified by:
  `send` in interface `WritableMessageChannel`
Parameters:
  `buffers` - the buffers holding the message to send
Returns:
  the result of the send operation; `true` if the message was sent, or `false` if it would block
Throws:
  `IOException` - if an I/O error occurs

### send

public boolean send(ByteBuffer[] buffers, int offs, int len) throws IOException
Description copied from interface: `WritableMessageChannel`
Send a complete message.

Specified by:
  `send` in interface `WritableMessageChannel`
Parameters:
  `buffers` - the buffers holding the message to send
  `offs` - the offset into the buffer array of the first buffer
  `len` - the number of buffers that contain data to send
Returns:
  the result of the send operation; `true` if the message was sent, or `false` if it would block
Throws:
  `IOException` - if an I/O error occurs

### sendFinal

public boolean sendFinal(ByteBuffer buffer) throws IOException
Description copied from interface: `WritableMessageChannel`
Send a complete message. If the message was successfully sent the channel with have its writes shutdown.

Specified by:
  `sendFinal` in interface `WritableMessageChannel`
Parameters:
  `buffer` - the message to send
Returns:
  the result of the send operation; `true` if the message was sent, or `false` if it would block
Throws:
  `IOException` - if an I/O error occurs

### sendFinal

public boolean sendFinal(ByteBuffer[] buffers) throws IOException
Description copied from interface: `WritableMessageChannel`
Send a complete message. If the message was successfully sent the channel with have its writes shutdown.

Specified by:
  `sendFinal` in interface `WritableMessageChannel`
Parameters:
  `buffers` - the buffers holding the message to send
Returns:
  the result of the send operation; `true` if the message was sent, or `false` if it would block
Throws:
  `IOException` - if an I/O error occurs

### sendFinal

public boolean sendFinal(ByteBuffer[] buffers, int offs, int len) throws IOException
Description copied from interface: `WritableMessageChannel`
Send a complete message. If the message was successfully sent the channel with have its writes shutdown.

Specified by:
  `sendFinal` in interface `WritableMessageChannel`
Parameters:
  `buffers` - the buffers holding the message to send
  `offs` - the offset into the buffer array of the first buffer
  `len` - the number of buffers that contain data to send
Returns:
  the result of the send operation; `true` if the message was sent, or `false` if it would block
Throws:
  `IOException` - if an I/O error occurs

### flush

public boolean flush() throws IOException
Description copied from interface: `SuspendableWriteChannel`
Flush any waiting partial send or write. If there is no data to flush, or if the flush completed successfully, this method will return `true`. If there is data to flush which cannot be immediately written, this method will return `false`. If this method returns `true` after `SuspendableWriteChannel.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:
  `flush` in interface `SuspendableWriteChannel`
Returns:
  `true` if the message was flushed, or `false` if the result would block
Throws:
  `IOException` - if an I/O error occurs

### getCloseSetter

public ChannelListener.Setter<? extends AssembledMessageChannel> getCloseSetter()
Description copied from interface: `MessageChannel`
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 interface `CloseableChannel`
Specified by:
  `getCloseSetter` in interface `MessageChannel`
Specified by:
  `getCloseSetter` in interface `ReadableMessageChannel`
Specified by:
  `getCloseSetter` in interface `SuspendableChannel`
Specified by:
  `getCloseSetter` in interface `SuspendableReadChannel`
Specified by:
  `getCloseSetter` in interface `SuspendableWriteChannel`
Specified by:
  `getCloseSetter` in interface `WritableMessageChannel`
Returns:
  the setter

### getWorker

public XnioWorker getWorker()
Description copied from interface: `CloseableChannel`
Get the worker for this channel.

Specified by:
  `getWorker` in interface `CloseableChannel`
Returns:
  the worker

### close

public void close() throws IOException
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 interface `AutoCloseable`
Specified by:
  `close` in interface `Channel`
Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `CloseableChannel`
Specified by:
  `close` in interface `InterruptibleChannel`
Specified by:
  `close` in interface `SuspendableWriteChannel`
Throws:
  `IOException` - if the close failed

### isOpen

public boolean isOpen()
Description copied from interface: `SuspendableWriteChannel`
Determine whether this channel is open. This method will return `false` if all directions are shut down, even if there is unflushed write data pending.

Specified by:
  `isOpen` in interface `Channel`
Specified by:
  `isOpen` in interface `SuspendableWriteChannel`
Returns:
  `true` if the channel is open, `false` otherwise

### supportsOption

public boolean supportsOption(Option<?> option)
Description copied from interface: `Configurable`
Determine whether an option is supported on this channel.

Specified by:
  `supportsOption` in interface `Configurable`
Parameters:
  `option` - the option
Returns:
  `true` if it is supported

### getOption

public <T> T getOption(Option<T> option) throws IOException
Description copied from interface: `Configurable`
Get the value of a channel option.

Specified by:
  `getOption` in interface `Configurable`
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

public <T> T setOption(Option<T> option, T value) throws IllegalArgumentException, IOException
Description copied from interface: `Configurable`
Set an option for this channel. Unsupported options are ignored.

Specified by:
  `setOption` in interface `Configurable`
Type Parameters:
  `T` - the type of the option value
Parameters:
  `option` - the option to set
  `value` - the value of the option to set
Returns:
  the previous option value, if any
Throws:
  `IllegalArgumentException` - if the value is not acceptable for this option
  `IOException` - if an I/O error occurred when modifying the option