Package org.xnio.conduits

# Class FramingMessageSinkConduit

java.lang.Object
org.xnio.conduits.AbstractConduit<StreamSinkConduit>
org.xnio.conduits.AbstractSinkConduit<StreamSinkConduit>
org.xnio.conduits.FramingMessageSinkConduit

All Implemented Interfaces:
  `Conduit`, `MessageSinkConduit`, `SinkConduit`

public final class FramingMessageSinkConduit extends AbstractSinkConduit<StreamSinkConduit> implements MessageSinkConduit
A message sink conduit which implements a simple message framing protocol over a stream conduit.

Author:
  David M. Lloyd

## Field Summary

### Fields inherited from class org.xnio.conduits.AbstractConduit

`next`

## Constructor Summary

Constructors
Constructor
Description
`FramingMessageSinkConduit(StreamSinkConduit next, boolean longLengths, Pooled<ByteBuffer> transmitBuffer)`
Construct a new instance.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`flush()`
Flush out any unwritten, buffered output.
`boolean`
`send(ByteBuffer src)`
Send a complete message.
`boolean`
`send(ByteBuffer[] srcs, int offs, int len)`
Send a complete message.
`boolean`
`sendFinal(ByteBuffer src)`
Send a complete message.
`boolean`
`sendFinal(ByteBuffer[] srcs, int offs, int len)`
Send a complete message.
`void`
`terminateWrites()`
Signal that no more write data is forthcoming.
`void`
`truncateWrites()`
Terminate writes and discard any outstanding write data.

### Methods inherited from class org.xnio.conduits.AbstractSinkConduit

`awaitWritable, awaitWritable, getWriteThread, isWriteResumed, isWriteShutdown, resumeWrites, setWriteReadyHandler, suspendWrites, wakeupWrites`

### Methods inherited from class org.xnio.conduits.AbstractConduit

`getWorker`

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

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

### Methods inherited from interface org.xnio.conduits.Conduit

`getWorker`

### Methods inherited from interface org.xnio.conduits.SinkConduit

`awaitWritable, awaitWritable, getWriteThread, isWriteResumed, isWriteShutdown, resumeWrites, setWriteReadyHandler, suspendWrites, wakeupWrites`

## Constructor Details

### FramingMessageSinkConduit

public FramingMessageSinkConduit(StreamSinkConduit next, boolean longLengths, Pooled<ByteBuffer> transmitBuffer)
Construct a new instance.

Parameters:
  `next` - the delegate conduit to set
  `longLengths` - `true` to use 4-byte lengths, `false` to use 2-byte lengths
  `transmitBuffer` - the transmit buffer to use

## Method Details

### send

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

Specified by:
  `send` in interface `MessageSinkConduit`
Parameters:
  `src` - 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[] srcs, int offs, int len) throws IOException
Description copied from interface: `MessageSinkConduit`
Send a complete message.

Specified by:
  `send` in interface `MessageSinkConduit`
Parameters:
  `srcs` - 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 src) throws IOException
Description copied from interface: `MessageSinkConduit`
Send a complete message. If the message is successfully sent then the sink will have its writes terminated.

Specified by:
  `sendFinal` in interface `MessageSinkConduit`
Parameters:
  `src` - 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[] srcs, int offs, int len) throws IOException
Description copied from interface: `MessageSinkConduit`
Send a complete message. If the message is successfully sent then the sink will have its writes terminated.

Specified by:
  `sendFinal` in interface `MessageSinkConduit`
Parameters:
  `srcs` - 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: `SinkConduit`
Flush out any unwritten, buffered output.

Specified by:
  `flush` in interface `SinkConduit`
Overrides:
  `flush` in class `AbstractSinkConduit<StreamSinkConduit>`
Returns:
  `true` if everything is flushed, `false` otherwise
Throws:
  `IOException` - if flush fails

### terminateWrites

public void terminateWrites() throws IOException
Description copied from interface: `SinkConduit`
Signal that no more write data is forthcoming. The conduit must be `SinkConduit.flush()`ed before it is considered to be shut down.

Specified by:
  `terminateWrites` in interface `SinkConduit`
Overrides:
  `terminateWrites` in class `AbstractSinkConduit<StreamSinkConduit>`
Throws:
  `IOException`

### truncateWrites

public void truncateWrites() throws IOException
Description copied from interface: `SinkConduit`
Terminate writes and discard any outstanding write data. The conduit is terminated and flushed regardless of the outcome of this method.

Specified by:
  `truncateWrites` in interface `SinkConduit`
Overrides:
  `truncateWrites` in class `AbstractSinkConduit<StreamSinkConduit>`
Throws:
  `IOException` - if channel termination failed for some reason