Class PooledMessage
java.lang.Object
io.deephaven.enterprise.niowrapper.sched.PooledMessage
- All Implemented Interfaces:
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThis is the interface for message pools. -
Constructor Summary
ConstructorsConstructorDescriptionPooledMessage(ByteBuffer buffer, PooledMessage.Pool pool, boolean keeper) Construct a new message which wraps a buffer, and is connected with a given pool. -
Method Summary
Modifier and TypeMethodDescriptionvoiddropView(ByteBuffer view) Drop a view buffer for this message.voidfinished()Signal that the message creator has completed the message.Return the buffer for this message.booleanReturn the keeper flag.getPool()Return the pool from which this message came.getState()Show current state as a string, for debugging.getView()Get a view buffer for this message.hexDump()dump this message's buffer.hexDump(int n) dump the first n bytes of this message's buffer.static StringhexDump(ByteBuffer buf) Dump a buffer in hex and ascii.static StringhexDump(ByteBuffer buf, int n) Dump the first n bytes of a buffer (following its position()) in hex and ascii.static StringhexDump(ByteBuffer buf, int pos, int n) Dump n bytes of a buffer in hex and ascii.
-
Constructor Details
-
PooledMessage
Construct a new message which wraps a buffer, and is connected with a given pool.
-
-
Method Details
-
getBuffer
Return the buffer for this message. -
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. -
getView
Get a view buffer for this message. -
dropView
Drop a view buffer for this message. -
hexDump
Dump a buffer in hex and ascii. -
hexDump
Dump the first n bytes of a buffer (following its position()) in hex and ascii. -
hexDump
Dump n bytes of a buffer in hex and ascii. -
hexDump
dump this message's buffer.- Returns:
- hex dump of this message's buffer in a string
-
hexDump
dump the first n bytes of this message's buffer.- Returns:
- hex dump of this message's buffer in a string
-
getState
Show current state as a string, for debugging.- Returns:
- useful internal state information, as a string
-