Class MQTTHelper.MQTTClientWrapper

  • Enclosing class:
    MQTTHelper

    public class MQTTHelper.MQTTClientWrapper
    extends java.lang.Object
    A wrapper for a Paho MQTT client.
    • Constructor Summary

      Constructors 
      Constructor Description
      MQTTClientWrapper​(jdk.nashorn.api.scripting.ScriptObjectMirror currentObj, int port, java.lang.String host, java.lang.String clientId, boolean rawBytes)
      This constructor creates one Paho MQTT client inside using given parameters.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void end()
      Disconnect from the broker server and close (i.e.
      boolean isConnected()
      Return whether the client is connected to a broker server.
      void publish​(java.lang.String topic, java.lang.Object message, java.lang.Integer qos, boolean retain)
      Publish an MQTT message to subscribers listening to the topic.
      void start()
      Start connection between the client and the broker server.
      void subscribe​(java.lang.String topic, int qos)
      Subscribe a topic using the given maximum QoS level.
      void unsubscribe​(java.lang.String topic)
      Unsubscribe a topic.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MQTTClientWrapper

        public MQTTClientWrapper​(jdk.nashorn.api.scripting.ScriptObjectMirror currentObj,
                                 int port,
                                 java.lang.String host,
                                 java.lang.String clientId,
                                 boolean rawBytes)
                          throws org.eclipse.paho.client.mqttv3.MqttException
        This constructor creates one Paho MQTT client inside using given parameters.
        Parameters:
        currentObj - The JavaScript instance of the WebSocket.
        port - The port number of the broker server.
        host - The host name of the broker server.
        clientId - The id of the client, whiich is passed to MqttAsyncClient();
        rawBytes - True if the payload is raw bytes.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttException
    • Method Detail

      • start

        public void start()
                   throws org.eclipse.paho.client.mqttv3.MqttSecurityException,
                          org.eclipse.paho.client.mqttv3.MqttException
        Start connection between the client and the broker server.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttSecurityException
        org.eclipse.paho.client.mqttv3.MqttException
      • publish

        public void publish​(java.lang.String topic,
                            java.lang.Object message,
                            java.lang.Integer qos,
                            boolean retain)
                     throws org.eclipse.paho.client.mqttv3.MqttException,
                            IllegalActionException
        Publish an MQTT message to subscribers listening to the topic.
        Parameters:
        topic - The topic to which to publish.
        message - The message sent to subscribers.
        qos - The QoS level of the message. (0: At most once, 1: At least once, 2: Exactly once)
        retain - Whether the sever should hold on the message after it has been delivered to current subscribers so that a newly incoming subscriber can receive the message later.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttException - If the publish fails.
        IllegalActionException
      • subscribe

        public void subscribe​(java.lang.String topic,
                              int qos)
                       throws org.eclipse.paho.client.mqttv3.MqttException
        Subscribe a topic using the given maximum QoS level. Start getting messages on the topic.
        Parameters:
        topic - The topic which the client will subscribe.
        qos - The maximum QoS at which to subscribe. Messages published at a lower quality of service will be received at the published QoS. Messages published at a higher quality of service will be received using the QoS specified on the subscribe.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttException
      • unsubscribe

        public void unsubscribe​(java.lang.String topic)
                         throws org.eclipse.paho.client.mqttv3.MqttException
        Unsubscribe a topic. Stop getting messages on the topic.
        Parameters:
        topic - The topic which the client will unsubscribe.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttException
      • end

        public void end()
                 throws org.eclipse.paho.client.mqttv3.MqttException
        Disconnect from the broker server and close (i.e. return all allocated resources) the client.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttException
      • isConnected

        public boolean isConnected()
        Return whether the client is connected to a broker server.
        Returns:
        if the client is connected.