Package org.xnio.conduits
Class FramingMessageSinkConduit
java.lang.Object
org.xnio.conduits.AbstractConduit<D>
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
ConstructorsConstructorDescriptionFramingMessageSinkConduit(StreamSinkConduit next, boolean longLengths, Pooled<ByteBuffer> transmitBuffer) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionbooleanflush()Flush out any unwritten, buffered output.booleansend(ByteBuffer src) Send a complete message.booleansend(ByteBuffer[] srcs, int offs, int len) Send a complete message.booleansendFinal(ByteBuffer src) Send a complete message.booleansendFinal(ByteBuffer[] srcs, int offs, int len) Send a complete message.voidSignal that no more write data is forthcoming.voidTerminate writes and discard any outstanding write data.Methods inherited from class org.xnio.conduits.AbstractSinkConduit
awaitWritable, awaitWritable, getWriteThread, isWriteResumed, isWriteShutdown, resumeWrites, setWriteReadyHandler, suspendWrites, wakeupWritesMethods inherited from class org.xnio.conduits.AbstractConduit
getWorkerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 setlongLengths-trueto use 4-byte lengths,falseto use 2-byte lengthstransmitBuffer- the transmit buffer to use
-
-
Method Details
-
send
Description copied from interface:MessageSinkConduitSend a complete message.- Specified by:
sendin interfaceMessageSinkConduit- Parameters:
src- 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:MessageSinkConduitSend a complete message.- Specified by:
sendin interfaceMessageSinkConduit- Parameters:
srcs- 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:MessageSinkConduitSend a complete message. If the message is successfully sent then the sink will have its writes terminated.- Specified by:
sendFinalin interfaceMessageSinkConduit- Parameters:
src- 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:MessageSinkConduitSend a complete message. If the message is successfully sent then the sink will have its writes terminated.- Specified by:
sendFinalin interfaceMessageSinkConduit- Parameters:
srcs- 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:SinkConduitFlush out any unwritten, buffered output.- Specified by:
flushin interfaceSinkConduit- Overrides:
flushin classAbstractSinkConduit<StreamSinkConduit>- Returns:
trueif everything is flushed,falseotherwise- Throws:
IOException- if flush fails
-
terminateWrites
Description copied from interface:SinkConduitSignal that no more write data is forthcoming. The conduit must beSinkConduit.flush()ed before it is considered to be shut down.- Specified by:
terminateWritesin interfaceSinkConduit- Overrides:
terminateWritesin classAbstractSinkConduit<StreamSinkConduit>- Throws:
IOException
-
truncateWrites
Description copied from interface:SinkConduitTerminate writes and discard any outstanding write data. The conduit is terminated and flushed regardless of the outcome of this method.- Specified by:
truncateWritesin interfaceSinkConduit- Overrides:
truncateWritesin classAbstractSinkConduit<StreamSinkConduit>- Throws:
IOException- if channel termination failed for some reason
-