Class PooledMessage

java.lang.Object
io.deephaven.enterprise.niowrapper.sched.PooledMessage
All Implemented Interfaces:
Message

public class PooledMessage extends Object implements Message
A wrapper for byte buffers which provides a protocol for message pooling and multiple, independent consumers of the message content. The producer of the message obtains an empty message by calling Message.Pool.get(). It then proceeds to write data into the message's buffer, and distributes it to the message consumers. Afterwards, it *must* call Message.finished() to indicate that the production of the message is complete. The consumers of a message each obtain a view onto the message contents by calling Message.getView(), which returns a view buffer set up for reading the message data. When the consumer has processed the message, it *must* call Message.dropView() to indicate that it is finished. When the producer and all of the consumers have indicated completion, the message can be returned to the pool for use in another cycle. Whether this occurs is a decision made in the specific implementation of Message.Pool from which the message was obtained. The protocol can be summarized as follows:
    Message m = pool.get();         // producer
    m.getBuffer().put(...);         // producer
    ByteBuffer b = m.getView();     // consumer(s)
    m.finished();                   // producer
    b.get(...);                     // consumer(s)
    m.dropView(b)                   // consumer(s)
 
Order constraints: -- if getView() is to be used, it must be called before finished() -- there is no order constraint between finished() and dropView() -- dropView() cannot be called before getView(), since getView() returns the argument to dropView() -- if the buffer is modified after a call to getView(), the results are undefined Created by IntelliJ IDEA. User: jrauser Date: Feb 5, 2007 Time: 8:15:59 PM To change this template use File | Settings | File Templates.
  • Constructor Details

    • PooledMessage

      public PooledMessage(ByteBuffer buffer, PooledMessage.Pool pool, boolean keeper)
      Construct a new message which wraps a buffer, and is connected with a given pool.
  • Method Details

    • getBuffer

      public ByteBuffer getBuffer()
      Return the buffer for this message.
      Specified by:
      getBuffer in interface Message
    • getPool

      public PooledMessage.Pool getPool()
      Return the pool from which this message came.
    • getKeeper

      public boolean getKeeper()
      Return the keeper flag.
    • finished

      public void finished()
      Signal that the message creator has completed the message.
      Specified by:
      finished in interface Message
    • getView

      public ByteBuffer getView()
      Get a view buffer for this message.
      Specified by:
      getView in interface Message
      Returns:
      A read-only view of the ByteBuffer backing this message.
    • dropView

      public void dropView(ByteBuffer view)
      Drop a view buffer for this message.
      Specified by:
      dropView in interface Message
      Parameters:
      view - the view to drop
    • hexDump

      public static String hexDump(ByteBuffer buf)
      Dump a buffer in hex and ascii.
    • hexDump

      public static String hexDump(ByteBuffer buf, int n)
      Dump the first n bytes of a buffer (following its position()) in hex and ascii.
    • hexDump

      public static String hexDump(ByteBuffer buf, int pos, int n)
      Dump n bytes of a buffer in hex and ascii.
    • hexDump

      public String hexDump()
      dump this message's buffer.
      Returns:
      hex dump of this message's buffer in a string
    • hexDump

      public String hexDump(int n)
      dump the first n bytes of this message's buffer.
      Returns:
      hex dump of this message's buffer in a string
    • getState

      public String getState()
      Show current state as a string, for debugging.
      Returns:
      useful internal state information, as a string