Package org.bluezoo.gumdrop.mqtt.broker
Class RetainedMessageStore
java.lang.Object
org.bluezoo.gumdrop.mqtt.broker.RetainedMessageStore
In-memory store for MQTT retained messages.
Each topic holds at most one retained message. Publishing a retained message with an empty payload removes the retained message for that topic.
Thread-safe via ConcurrentHashMap.
- Author:
- Chris Burdess
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn immutable retained message. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all retained messages.Returns the retained message for the given topic, or null.Returns all retained messages matching the given topic filter.voidset(String topic, MQTTMessageContent content, QoS qos) Sets or removes a retained message for the given topic.intsize()Returns the number of retained messages.
-
Constructor Details
-
RetainedMessageStore
public RetainedMessageStore()
-
-
Method Details
-
set
Sets or removes a retained message for the given topic.If the content is null or has zero size, the retained message for the topic is removed and any previously stored content is released. If a previous retained message exists for the topic, its content is released before the new one is stored.
- Parameters:
topic- the topic namecontent- the message content (null or empty to remove)qos- the message QoS
-
get
Returns the retained message for the given topic, or null. -
match
Returns all retained messages matching the given topic filter.- Parameters:
topicFilter- a topic filter (may contain + and # wildcards)- Returns:
- matching retained messages
-
clear
public void clear()Removes all retained messages. -
size
public int size()Returns the number of retained messages.
-