Class MqttWillAndTestament

java.lang.Object
org.openhab.core.io.transport.mqtt.MqttWillAndTestament

@NonNullByDefault public class MqttWillAndTestament extends Object
Class encapsulating the last will and testament that is published after the client has gone offline.
Author:
Markus Mann - Initial contribution
  • Constructor Details

    • MqttWillAndTestament

      public MqttWillAndTestament(String topic, byte @Nullable [] payload, int qos, boolean retain)
      Create a new MqttWillAndTestament with at least a topic name.
      Parameters:
      topic - topic is a normal topic string (no placeholders are allowed)
      payload - The optional payload. Can be null.
      qos - Valid values are 0 (Deliver at most once),1 (Deliver at least once) or 2
    • retain - true if messages shall be retained
  • Method Details

    • fromString

      public static @Nullable MqttWillAndTestament fromString(@Nullable String string)
      Create an instance of the last will using a string with the following format:
      topic:message:qos:retained
      Where
      • topic is a normal topic string (no placeholders are allowed)
      • message the message to send
      • qos Valid values are 0 (Deliver at most once),1 (Deliver at least once) or 2
      • retain true if messages shall be retained
      Parameters:
      string - the string to parse. If null, null is returned
      Returns:
      the will instance, will be null only if parameter is null
    • fromString

      public static @Nullable MqttWillAndTestament fromString(@Nullable String string, @Nullable String topic, byte @Nullable [] payload, @Nullable Integer qos, @Nullable Boolean retain)
    • getTopic

      public String getTopic()
      Returns:
      the topic for the last will.
    • getPayload

      public byte @Nullable [] getPayload()
      Returns:
      the payload of the last will.
    • getQos

      public int getQos()
      Returns:
      quality of service level.
    • isRetain

      public boolean isRetain()
      Returns:
      true if the last will should be retained by the broker.
    • toString

      public String toString()
      Overrides:
      toString in class Object