public class MessageAggregator extends java.lang.Object implements LCMSubscriber
LCM
normally delivers messages asynchronously by invoking the
messageReceived
method on a subscriber as soon as a message is received. This class provides an
alternate way to receive messages by storing them in an internal queue, and then
delivering them to synchronously to the user.
The aggregator has configurable limits. If too many messages are aggregated without having been retrieved, then older messages are discarded.
Modifier and Type | Class and Description |
---|---|
class |
MessageAggregator.Message
A received message.
|
Constructor and Description |
---|
MessageAggregator() |
Modifier and Type | Method and Description |
---|---|
long |
getMaxBufferSize()
Retrieves the maximum amount of memory that will be used to store messages.
|
int |
getMaxMessages()
Retrieves the maximum number of unretrieved message that will be queued
up by the aggregator.
|
MessageAggregator.Message |
getNextMessage()
Retrieves the next message, waiting if necessary.
|
MessageAggregator.Message |
getNextMessage(long timeout_ms)
Attempt to retrieve the next received LCM message.
|
void |
messageReceived(LCM lcm,
java.lang.String channel,
LCMDataInputStream dins)
Internal method, called by LCM when a message is received.
|
int |
numMessagesAvailable()
Returns the number of received messages waiting to be retrieved.
|
void |
setMaxBufferSize(long val)
Sets the maximum amount of memory that will be used to store messages.
|
void |
setMaxMessages(int val)
Sets the maximum number of unretrieved message that will be queued up by
the aggregator.
|
public void messageReceived(LCM lcm, java.lang.String channel, LCMDataInputStream dins)
messageReceived
in interface LCMSubscriber
lcm
- the LCM instance that received the message.channel
- the channel on which the message was received.dins
- the message contents.public void setMaxBufferSize(long val)
val
- memory limit, in bytes.public long getMaxBufferSize()
public void setMaxMessages(int val)
public int getMaxMessages()
public MessageAggregator.Message getNextMessage(long timeout_ms)
timeout_ms
- Max # of milliseconds to wait for a message. If 0,
then don't wait. If less than 0, then wait indefinitely.public MessageAggregator.Message getNextMessage()
public int numMessagesAvailable()