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.
  • Constructor Details

    • MessageSequenceSink

      public MessageSequenceSink(PooledMessage.Pool pool)
      Construct a new message sequence.
    • MessageSequenceSink

      public MessageSequenceSink(PooledMessage.Pool pool, ByteOrder byteOrder)
      Construct a new message sequence.
  • Method Details

    • acceptBuffer

      public ByteBuffer acceptBuffer(ByteBuffer b, int need)
      Accepts an incoming message by pushing it into the sequence.
      Specified by:
      acceptBuffer in interface com.fishlib.io.streams.ByteBufferSink
    • acceptExternalMessage

      public ByteBuffer 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.
      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

      public void close(ByteBuffer b)
      Accepts the final buffer of a sequence.
      Specified by:
      close in interface com.fishlib.io.streams.ByteBufferSink
    • getBuffer

      public ByteBuffer getBuffer()
      Specified by:
      getBuffer in interface com.fishlib.io.streams.CurrentByteBufferSink
    • getCurrentMessage

      public Message getCurrentMessage()
      Returns the current message.
    • getMessages

      public 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

      public void write(IOJob job) throws IOException
      Write the sequence to an IOJob, recycling the message and resetting the byte count.
      Throws:
      IOException
    • write

      public void write(IOJob job, boolean allowFlush) throws IOException
      Throws:
      IOException
    • finish

      public void finish()
      Finish all of the messages in the sink
    • getBytes

      @Deprecated public ByteBuffer 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.