Class RetainedMessageStore

java.lang.Object
org.bluezoo.gumdrop.mqtt.broker.RetainedMessageStore

public class RetainedMessageStore extends Object
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
  • Constructor Details

    • RetainedMessageStore

      public RetainedMessageStore()
  • Method Details

    • set

      public void set(String topic, MQTTMessageContent content, QoS qos)
      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 name
      content - the message content (null or empty to remove)
      qos - the message QoS
    • get

      Returns the retained message for the given topic, or null.
    • match

      public List<RetainedMessageStore.RetainedMessage> match(String topicFilter)
      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.