Package lcm.lcm
Class MessageAggregator
java.lang.Object
lcm.lcm.MessageAggregator
- All Implemented Interfaces:
LCMSubscriber
Accumulates received LCM messages in a queue.
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.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlong
Retrieves the maximum amount of memory that will be used to store messages.int
Retrieves the maximum number of unretrieved message that will be queued up by the aggregator.Retrieves the next message, waiting if necessary.getNextMessage
(long timeout_ms) Attempt to retrieve the next received LCM message.void
messageReceived
(LCM lcm, String channel, lcm.lcm.LCMDataInputStream dins) Internal method, called by LCM when a message is received.int
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.
-
Constructor Details
-
MessageAggregator
public MessageAggregator()
-
-
Method Details
-
messageReceived
Internal method, called by LCM when a message is received.- Specified by:
messageReceived
in interfaceLCMSubscriber
- Parameters:
lcm
- the LCM instance that received the message.channel
- the channel on which the message was received.dins
- the message contents.
-
setMaxBufferSize
public void setMaxBufferSize(long val) Sets the maximum amount of memory that will be used to store messages. This is an alternative way to limit the messages stored by the aggregator. Messages are discarded oldest-first to ensure that the total size of unretrieved messages stays under this limit.- Parameters:
val
- memory limit, in bytes.
-
getMaxBufferSize
public long getMaxBufferSize()Retrieves the maximum amount of memory that will be used to store messages. -
setMaxMessages
public void setMaxMessages(int val) Sets the maximum number of unretrieved message that will be queued up by the aggregator. Messages are discarded oldest-first to ensure that the number of unretrieved messages stays under this limit. -
getMaxMessages
public int getMaxMessages()Retrieves the maximum number of unretrieved message that will be queued up by the aggregator. -
getNextMessage
Attempt to retrieve the next received LCM message.- Parameters:
timeout_ms
- Max # of milliseconds to wait for a message. If 0, then don't wait. If less than 0, then wait indefinitely.- Returns:
- a Message, or null if no message was received.
-
getNextMessage
Retrieves the next message, waiting if necessary. -
numMessagesAvailable
public int numMessagesAvailable()Returns the number of received messages waiting to be retrieved.
-