Class BaseMqttConnectionObserver

java.lang.Object
net.solarnetwork.service.support.BasicIdentifiable
net.solarnetwork.central.support.BaseMqttConnectionObserver
All Implemented Interfaces:
net.solarnetwork.common.mqtt.MqttConnectionObserver, net.solarnetwork.service.Identifiable
Direct Known Subclasses:
MqttJsonPublisher

public abstract class BaseMqttConnectionObserver extends net.solarnetwork.service.support.BasicIdentifiable implements net.solarnetwork.common.mqtt.MqttConnectionObserver
Base implementation of MqttConnectionObserver to help with connection observer-based MQTT services.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final net.solarnetwork.common.mqtt.MqttQos
    The publishQos property default value.
    static final int
    The connectTimeoutSeconds property default value.
    static final net.solarnetwork.common.mqtt.MqttQos
    The subscribeQos property default value.
    static final int
    The subscribeTimeoutSeconds property default value.
    static final int
    The transientErrorTries property default value.
    protected final org.slf4j.Logger
    A class-level logger.
    protected final AtomicReference<net.solarnetwork.common.mqtt.MqttConnection>
     

    Fields inherited from interface net.solarnetwork.service.Identifiable

    GROUP_UID_PROPERTY, UID_PROPERTY
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    net.solarnetwork.util.StatTracker
    Get the statistics tracker.
    net.solarnetwork.common.mqtt.MqttQos
    Get the publish QoS.
    int
    Get a publish timeout, in seconds.
    net.solarnetwork.common.mqtt.MqttQos
    Get the subscribe QoS.
    int
    Get the subscribe timeout seconds.
    int
    Get the number of times to try operations that support retry, when transient exceptions occur.
    boolean
    Test if the MQTT connection is established.
    boolean
    Get the retained flag.
    void
    onMqttServerConnectionEstablished(net.solarnetwork.common.mqtt.MqttConnection connection, boolean reconnected)
    Callback when the MQTT connection has been established.
    void
    onMqttServerConnectionLost(net.solarnetwork.common.mqtt.MqttConnection connection, boolean willReconnect, Throwable cause)
    Callback when the MQTT connection has been lost.
    void
    setMqttStats(net.solarnetwork.util.StatTracker mqttStats)
    Set the statistics tracker.
    void
    setPublishQos(net.solarnetwork.common.mqtt.MqttQos publishQos)
    Set the publish QoS.
    void
    setPublishQosLevel(int level)
    Set the publish QoS as a level value.
    void
    setPublishTimeoutSeconds(int publishTimeoutSeconds)
    Set a publish timeout, in seconds.
    void
    setRetained(boolean retained)
    Set the retained flag
    void
    setSubscribeQos(net.solarnetwork.common.mqtt.MqttQos subscribeQos)
    Set the subscribe QoS.
    void
    Set the subscribe QoS as a level value.
    void
    setSubscribeTimeoutSeconds(int subscribeTimeoutSeconds)
    Set the subscribe timeout seconds.
    void
    setTransientErrorTries(int transientErrorTries)
    Set the number of times to try operations that support retry, when transient exceptions occur.
     

    Methods inherited from class net.solarnetwork.service.support.BasicIdentifiable

    basicIdentifiableMetadataSettings, basicIdentifiableSettings, basicIdentifiableSettings, basicIdentifiableSettings, doubleMetadataValue, getDisplayName, getGroupUid, getGroupUID, getMessageSource, getMetadata, getMetadataCount, getUid, getUID, integerMetadataValue, metadataValue, numberMetadataValue, saveMetadataValue, saveMetadataValue, setDisplayName, setGroupUid, setGroupUID, setMessageSource, setMetadata, setMetadataCount, setUid, setUID, smartMetadataValue

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • DEFAULT_PUBLISH_TIMEOUT_SECONDS

      public static final int DEFAULT_PUBLISH_TIMEOUT_SECONDS
      The connectTimeoutSeconds property default value.
      See Also:
    • DEFAULT_SUBSCRIBE_TIMEOUT_SECONDS

      public static final int DEFAULT_SUBSCRIBE_TIMEOUT_SECONDS
      The subscribeTimeoutSeconds property default value.
      See Also:
    • DEFAULT_TRANSIENT_ERROR_TRIES

      public static final int DEFAULT_TRANSIENT_ERROR_TRIES
      The transientErrorTries property default value.
      See Also:
    • DEFAULT_PUBLISH_QOS

      public static final net.solarnetwork.common.mqtt.MqttQos DEFAULT_PUBLISH_QOS
      The publishQos property default value.
    • DEFAULT_SUBSCRIBE_QOS

      public static final net.solarnetwork.common.mqtt.MqttQos DEFAULT_SUBSCRIBE_QOS
      The subscribeQos property default value.
    • log

      protected final org.slf4j.Logger log
      A class-level logger.
    • mqttConnection

      protected final AtomicReference<net.solarnetwork.common.mqtt.MqttConnection> mqttConnection
  • Constructor Details

    • BaseMqttConnectionObserver

      public BaseMqttConnectionObserver()
  • Method Details

    • onMqttServerConnectionEstablished

      public void onMqttServerConnectionEstablished(net.solarnetwork.common.mqtt.MqttConnection connection, boolean reconnected)
      Callback when the MQTT connection has been established.

      Extending classes that override this can call this implementation to store the connection in the mqttConnection reference.

      h
      Specified by:
      onMqttServerConnectionEstablished in interface net.solarnetwork.common.mqtt.MqttConnectionObserver
    • onMqttServerConnectionLost

      public void onMqttServerConnectionLost(net.solarnetwork.common.mqtt.MqttConnection connection, boolean willReconnect, Throwable cause)
      Callback when the MQTT connection has been lost.

      Extending classes that override this can call this implementation to clear the connection from the mqttConnection reference.

      h
      Specified by:
      onMqttServerConnectionLost in interface net.solarnetwork.common.mqtt.MqttConnectionObserver
    • isConnected

      public boolean isConnected()
      Test if the MQTT connection is established.
      Returns:
      true if the MQTT connection is established
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getTransientErrorTries

      public int getTransientErrorTries()
      Get the number of times to try operations that support retry, when transient exceptions occur.
      Returns:
      the number of attempts to try operations that support retry; defaults to DEFAULT_TRANSIENT_ERROR_TRIES
    • setTransientErrorTries

      public void setTransientErrorTries(int transientErrorTries)
      Set the number of times to try operations that support retry, when transient exceptions occur.
      Parameters:
      transientErrorTries - the number of times to attempt operations that support retry; must be greater than 0
    • getMqttStats

      public net.solarnetwork.util.StatTracker getMqttStats()
      Get the statistics tracker.
      Returns:
      the statistics tracker
    • setMqttStats

      public void setMqttStats(net.solarnetwork.util.StatTracker mqttStats)
      Set the statistics tracker.
      Parameters:
      mqttStats - the statistics tracker to set
    • getSubscribeQos

      public net.solarnetwork.common.mqtt.MqttQos getSubscribeQos()
      Get the subscribe QoS.
      Returns:
      the QoS; defaults to DEFAULT_SUBSCRIBE_QOS
    • setSubscribeQos

      public void setSubscribeQos(net.solarnetwork.common.mqtt.MqttQos subscribeQos)
      Set the subscribe QoS.
      Parameters:
      subscribeQos - the subscribe QoS to set
      Throws:
      IllegalArgumentException - if the argument is null
    • setSubscribeQosLevel

      public void setSubscribeQosLevel(int level)
      Set the subscribe QoS as a level value.
      Parameters:
      level - the level to set
      Throws:
      IllegalArgumentException - if the level is not supported
    • getSubscribeTimeoutSeconds

      public int getSubscribeTimeoutSeconds()
      Get the subscribe timeout seconds.
      Returns:
      the timeout seconds; defaults to DEFAULT_SUBSCRIBE_TIMEOUT_SECONDS
    • setSubscribeTimeoutSeconds

      public void setSubscribeTimeoutSeconds(int subscribeTimeoutSeconds)
      Set the subscribe timeout seconds.
      Parameters:
      subscribeTimeoutSeconds - the timeout seconds to set
    • isRetained

      public boolean isRetained()
      Get the retained flag.
      Returns:
      the retained; defaults to false
    • setRetained

      public void setRetained(boolean retained)
      Set the retained flag
      Parameters:
      retained - the retained to set
    • getPublishQos

      public net.solarnetwork.common.mqtt.MqttQos getPublishQos()
      Get the publish QoS.
      Returns:
      the QoS; defaults to DEFAULT_PUBLISH_QOS
    • setPublishQos

      public void setPublishQos(net.solarnetwork.common.mqtt.MqttQos publishQos)
      Set the publish QoS.
      Parameters:
      publishQos - the QoS to set
      Throws:
      IllegalArgumentException - if the argument is null
    • setPublishQosLevel

      public void setPublishQosLevel(int level)
      Set the publish QoS as a level value.
      Parameters:
      level - the QoS level to set
      Throws:
      IllegalArgumentException - if the level is not supported
    • getPublishTimeoutSeconds

      public int getPublishTimeoutSeconds()
      Get a publish timeout, in seconds.
      Returns:
      the timeout seconds; defaults to DEFAULT_PUBLISH_TIMEOUT_SECONDS
    • setPublishTimeoutSeconds

      public void setPublishTimeoutSeconds(int publishTimeoutSeconds)
      Set a publish timeout, in seconds.
      Parameters:
      publishTimeoutSeconds - the timeout to set