Package org.xnio.conduits

# Class FramingMessageSourceConduit

java.lang.Object
org.xnio.conduits.AbstractConduit<StreamSourceConduit>
org.xnio.conduits.AbstractSourceConduit<StreamSourceConduit>
org.xnio.conduits.FramingMessageSourceConduit

All Implemented Interfaces:
  `Conduit`, `MessageSourceConduit`, `SourceConduit`

public final class FramingMessageSourceConduit extends AbstractSourceConduit<StreamSourceConduit> implements MessageSourceConduit
A message source 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
`FramingMessageSourceConduit(StreamSourceConduit next, Pooled<ByteBuffer> receiveBuffer)`
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 conduit becomes readable again, or until the timeout expires.
`int`
`receive(ByteBuffer dst)`
Receive a message.
`long`
`receive(ByteBuffer[] dsts, int offs, int len)`
Receive a message.
`void`
`resumeReads()`
Indicate that the conduit's `ReadReadyHandler` should be invoked as soon as data can be read without blocking.
`void`
`terminateReads()`
Indicate that no more data will be read from this conduit.

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

`getReadThread, isReadResumed, isReadShutdown, setReadReadyHandler, suspendReads, wakeupReads`

### 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.SourceConduit

`getReadThread, isReadResumed, isReadShutdown, setReadReadyHandler, suspendReads, wakeupReads`

## Constructor Details

### FramingMessageSourceConduit

public FramingMessageSourceConduit(StreamSourceConduit next, Pooled<ByteBuffer> receiveBuffer)
Construct a new instance.

Parameters:
  `next` - the delegate conduit to set
  `receiveBuffer` - the transmit buffer to use

## Method Details

### resumeReads

public void resumeReads()
Description copied from interface: `SourceConduit`
Indicate that the conduit's `ReadReadyHandler` should be invoked as soon as data can be read without blocking.

Specified by:
  `resumeReads` in interface `SourceConduit`
Overrides:
  `resumeReads` in class `AbstractSourceConduit<StreamSourceConduit>`

### awaitReadable

public void awaitReadable(long time, TimeUnit timeUnit) throws IOException
Description copied from interface: `SourceConduit`
Block until this conduit becomes readable again, or until the timeout expires. This method may return spuriously before the conduit becomes readable or the timeout expires.

Specified by:
  `awaitReadable` in interface `SourceConduit`
Overrides:
  `awaitReadable` in class `AbstractSourceConduit<StreamSourceConduit>`
Parameters:
  `time` - the time to wait
  `timeUnit` - the time unit
Throws:
  `IOException` - if an I/O error occurs

### awaitReadable

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

Specified by:
  `awaitReadable` in interface `SourceConduit`
Overrides:
  `awaitReadable` in class `AbstractSourceConduit<StreamSourceConduit>`
Throws:
  `IOException` - if an I/O error occurs

### terminateReads

public void terminateReads() throws IOException
Description copied from interface: `SourceConduit`
Indicate that no more data will be read from this conduit. If unread data exists, an exception may be thrown.

Specified by:
  `terminateReads` in interface `SourceConduit`
Overrides:
  `terminateReads` in class `AbstractSourceConduit<StreamSourceConduit>`
Throws:
  `IOException` - if there was a problem

### receive

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

Specified by:
  `receive` in interface `MessageSourceConduit`
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[] dsts, int offs, int len) throws IOException
Description copied from interface: `MessageSourceConduit`
Receive a message.

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