Class CMMqttManager


public class CMMqttManager extends CMServiceManager
The CMMqttManager class represents a CM service object with which an application can request Mqtt service.
The protocol of the CMMqttManager class conforms to MQTT version 3.1.1. (http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html)
CM wraps all MQTT messages in CM events so that CM nodes can run as a publisher or a subscriber.
  • Constructor Details

    • CMMqttManager

      public CMMqttManager(CMInfo cmInfo)
  • Method Details

    • connect

      public boolean connect()
      Connects to the default server for the CM publish-subscribe service.

      A CM client that has logged in to the default server must call the connect() method before it uses the CM publish-subscribe service.
      This method is same as connect(null,null,false,(byte)0, false,false,0) of the connect(String, String, boolean, byte, boolean, boolean) method.

      Returns:
      true if the connect succeeds; false otherwise.
    • connect

      public boolean connect(String strWillTopic, String strWillMessage, boolean bWillRetain, byte willQoS, boolean bWillFlag, boolean bCleanSession)
      Connects to the default server for the CM publish-subscribe service.

      A CM client that has logged in to the default server must call the connect() method before it uses the CM publish-subscribe service.

      Parameters:
      strWillTopic - - will topic
      strWillMessage - - will message
      bWillRetain - - will retain
      willQoS - - will QoS
      bWillFlag - - will flag
      bCleanSession - - clean session flag
      Returns:
      true if the connect succeeds; false otherwise.
    • publish

      public boolean publish(String strTopic, String strMsg)
      Publishes a message.

      This method is the same as publish(strTopic, strMsg, (byte)0, false, false) of the publish(String, String, byte, boolean, boolean) method.

      Parameters:
      strTopic - - topic
      strMsg - - message
      Returns:
      true if the message is successfully published; false otherwise.
      See Also:
    • publish

      public boolean publish(String strTopic, String strMsg, byte qos)
      Publishes a message.

      This method is the same as publish(strTopic, strMsg, qos, false, false) of the publish(String, String, byte, boolean, boolean) method.

      Parameters:
      strTopic - - topic
      strMsg - - message
      qos - - QoS level
      Returns:
      true if the message is successfully published; false otherwise.
      See Also:
    • publish

      public boolean publish(String strTopic, String strMsg, byte qos, boolean bDupFlag, boolean bRetainFlag)
      Publishes a message.
      Parameters:
      strTopic - - topic
      strMsg - - message
      qos - - QoS level
      bDupFlag - - DUP flag
      bRetainFlag - - retain flag
      Returns:
      true if the message is successfully published; false otherwise.
      See Also:
    • publishFromServerToOneClient

      public boolean publishFromServerToOneClient(String strTopic, String strMsg, byte qos, boolean bDupFlag, boolean bRetainFlag, String strClient, CMMqttSession session)
    • sendAndClearPendingTransPublish

      public boolean sendAndClearPendingTransPublish(String strReceiver, CMMqttSession session)
    • resendSentUnAckPublish

      public boolean resendSentUnAckPublish(String strReceiver, CMMqttSession session)
    • resendSentUnAckPubrel

      public boolean resendSentUnAckPubrel(String strReceiver, CMMqttSession session)
    • isTopicMatch

      public static boolean isTopicMatch(String strTopic, String strFilter)
    • subscribe

      public boolean subscribe(String strTopicFilter, byte qos)
      Subscribes a topic filter.
      Parameters:
      strTopicFilter - - topic filter
      qos - - requested QoS level
      Returns:
      true if the topic filter is successfully subscribed; false otherwise.
      See Also:
    • subscribe

      public boolean subscribe(CMList<CMMqttTopicQoS> topicQoSList)
      Subscribes a list of topic filters.
      Parameters:
      topicQoSList - - the list of topic filters
      Returns:
      true if the topic filters are successfully subscribed; false otherwise.
      See Also:
    • unsubscribe

      public boolean unsubscribe(String strTopic)
      Unsubscribes a topic filter.
      Parameters:
      strTopic - - the topic filter
      Returns:
      true if the topic filter is successfully unsubscribed; false otherwise.
    • unsubscribe

      public boolean unsubscribe(CMList<String> topicList)
      Unsubscribes a list of topic filters.
      Parameters:
      topicList - - the list of topic filters
      Returns:
      true if the topic filters are successfully unsubscribed; false otherwise.
    • requestPing

      public boolean requestPing()
    • disconnect

      public boolean disconnect()
      Disconnects the publish-subscribe service.

      This method only stops the publish-subscribe service, and the client can still continue to use the other CM services.

      Returns:
      true if the client successfully disconnects the publish-subscribe service; false otherwise.
    • getMySessionInfo

      public String getMySessionInfo()
      Returns the string that contains session information of a CM client.

      Only a CM client can call this method.

      Returns:
      the session information of the client.
    • getSessionInfo

      public String getSessionInfo(String strUserName)
      Returns the string that contains session information of a CM client.

      Only a CM server can call this method.

      Parameters:
      strUserName - - the user (client) name
      Returns:
      the session information of the user.
    • getAllSessionInfo

      public String getAllSessionInfo()
      Returns the string that contains session information of all CM clients.

      Only a CM server can call this method.

      Returns:
      the all session information.
    • getAllRetainInfo

      public String getAllRetainInfo()
      Returns all retain information.

      Only a CM server can call this method.

      Returns:
      the all retain information.
    • sendMqttWill

      public boolean sendMqttWill(String strUser)