- java.lang.Object
-
- org.xnio.conduits.AbstractConduit<D>
-
- 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<java.nio.ByteBuffer> receiveBuffer)
Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
awaitReadable()
Block until this channel becomes readable again.void
awaitReadable(long time, java.util.concurrent.TimeUnit timeUnit)
Block until this conduit becomes readable again, or until the timeout expires.int
receive(java.nio.ByteBuffer dst)
Receive a message.long
receive(java.nio.ByteBuffer[] dsts, int offs, int len)
Receive a message.void
resumeReads()
Indicate that the conduit'sReadReadyHandler
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.SourceConduit
getReadThread, isReadResumed, isReadShutdown, setReadReadyHandler, suspendReads, wakeupReads
-
-
-
-
Constructor Detail
-
FramingMessageSourceConduit
public FramingMessageSourceConduit(StreamSourceConduit next, Pooled<java.nio.ByteBuffer> receiveBuffer)
Construct a new instance.- Parameters:
next
- the delegate conduit to setreceiveBuffer
- the transmit buffer to use
-
-
Method Detail
-
resumeReads
public void resumeReads()
Description copied from interface:SourceConduit
Indicate that the conduit'sReadReadyHandler
should be invoked as soon as data can be read without blocking.- Specified by:
resumeReads
in interfaceSourceConduit
- Overrides:
resumeReads
in classAbstractSourceConduit<StreamSourceConduit>
-
awaitReadable
public void awaitReadable(long time, java.util.concurrent.TimeUnit timeUnit) throws java.io.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 interfaceSourceConduit
- Overrides:
awaitReadable
in classAbstractSourceConduit<StreamSourceConduit>
- 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
-
awaitReadable
public void awaitReadable() throws java.io.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 interfaceSourceConduit
- Overrides:
awaitReadable
in classAbstractSourceConduit<StreamSourceConduit>
- 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
-
terminateReads
public void terminateReads() throws java.io.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 interfaceSourceConduit
- Overrides:
terminateReads
in classAbstractSourceConduit<StreamSourceConduit>
- Throws:
java.io.IOException
- if there was a problem
-
receive
public int receive(java.nio.ByteBuffer dst) throws java.io.IOException
Description copied from interface:MessageSourceConduit
Receive a message.- Specified by:
receive
in interfaceMessageSourceConduit
- 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, int offs, int len) throws java.io.IOException
Description copied from interface:MessageSourceConduit
Receive a message.- Specified by:
receive
in interfaceMessageSourceConduit
offs
- 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:
java.io.IOException
- if an I/O error occurs
-
-