Class MessageSequenceSink
java.lang.Object
io.deephaven.enterprise.niowrapper.sched.MessageSequenceSink
- All Implemented Interfaces:
com.fishlib.io.streams.ByteBufferSink,com.fishlib.io.streams.CurrentByteBufferSink
public class MessageSequenceSink
extends Object
implements com.fishlib.io.streams.CurrentByteBufferSink
A ByteBuffer sink which provides its stream with buffers from a message pool, and collects filled buffers into an
array of messages.
A MessageSequenceSink always has a "currentMessage" in which new data can be written. The currentMessage is allocated
from the pool when the sink is constructed, and a new one is allocated whenever the stream calls acceptBuffer() to
signify that the buffer is full.
The sink also counts the number of bytes in all of the buffers it receives. The byte count can be fetched and reset
at will.
When the caller is finished writing, it should call flush() on the stream to force the final buffer to be given to
the sink. Then, the sequence can be written to an IOJob with the write() method. This will call finished() on the
messages in the sequence so that they can be recycled.
Created by IntelliJ IDEA. User: jrauser Date: Feb 21, 2007 Time: 7:10:07 PM To change this template use File |
Settings | File Templates.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.fishlib.io.streams.CurrentByteBufferSink
com.fishlib.io.streams.CurrentByteBufferSink.Adapter -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new message sequence.MessageSequenceSink(PooledMessage.Pool pool, ByteOrder byteOrder) Construct a new message sequence. -
Method Summary
Modifier and TypeMethodDescriptionacceptBuffer(ByteBuffer b, int need) Accepts an incoming message by pushing it into the sequence.acceptExternalMessage(Message message, int size, int need) Accept a message from an external source and add it to the stream after any data that's been added to the current message.voidclose(ByteBuffer b) Accepts the final buffer of a sequence.voidfinish()Finish all of the messages in the sinkintReturn the current byte count (pushed, and in current message)getBytes()Deprecated.Returns the current message.Message[]Return the message arrayintReturn the number of messages in the arrayintReset the byte count, returning the current value.voidWrite the sequence to an IOJob, recycling the message and resetting the byte count.voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.fishlib.io.streams.CurrentByteBufferSink
close, ensureSpace, flush
-
Constructor Details
-
MessageSequenceSink
Construct a new message sequence. -
MessageSequenceSink
Construct a new message sequence.
-
-
Method Details
-
acceptBuffer
Accepts an incoming message by pushing it into the sequence.- Specified by:
acceptBufferin interfacecom.fishlib.io.streams.ByteBufferSink
-
acceptExternalMessage
Accept a message from an external source and add it to the stream after any data that's been added to the current message.- Parameters:
message- A message produced externally, not necessarily part of our pool.size- The size of the external message.need- The minimum remaining capacity of the new current Pooledmessage.- Returns:
- The buffer of the new current PooledMessage.
-
close
Accepts the final buffer of a sequence.- Specified by:
closein interfacecom.fishlib.io.streams.ByteBufferSink
-
getBuffer
- Specified by:
getBufferin interfacecom.fishlib.io.streams.CurrentByteBufferSink
-
getCurrentMessage
Returns the current message. -
getMessages
Return the message array -
getNumMessages
public int getNumMessages()Return the number of messages in the array -
getByteCount
public int getByteCount()Return the current byte count (pushed, and in current message) -
resetByteCount
public int resetByteCount()Reset the byte count, returning the current value. This does not including data in the current message, so it should probably only be called after the stream which is writing to this sink has been flush()ed. -
write
Write the sequence to an IOJob, recycling the message and resetting the byte count.- Throws:
IOException
-
write
- Throws:
IOException
-
finish
public void finish()Finish all of the messages in the sink -
getBytes
Deprecated.Concatenate the sequence into a new byte buffer NB: This is public so that TestWObjectUtil can call it. It's only used in unit tests and has no reasonable production use case.
-