com.ibm.wiotp.sdk

Class AbstractClient

  • Direct Known Subclasses:
    ApplicationClient, DeviceClient


    public abstract class AbstractClient
    extends Object
    A client that handles connections with the IBM Watson IoT Platform.
    This is an abstract class which has to be extended
    • Field Detail

      • DEFAULT_MAX_CONNECT_ATTEMPTS

        public static final int DEFAULT_MAX_CONNECT_ATTEMPTS
        See Also:
        Constant Field Values
      • DEFAULT_ACTION_TIMEOUT

        public static final long DEFAULT_ACTION_TIMEOUT
        See Also:
        Constant Field Values
      • DEFAULT_MAX_INFLIGHT_MESSAGES

        public static final int DEFAULT_MAX_INFLIGHT_MESSAGES
        See Also:
        Constant Field Values
      • DEFAULT_DISCONNECTED_BUFFER_SIZE

        public static final int DEFAULT_DISCONNECTED_BUFFER_SIZE
        See Also:
        Constant Field Values
      • disconnectRequested

        protected volatile boolean disconnectRequested
      • gson

        protected static final com.google.gson.Gson gson
      • messageCount

        protected int messageCount
      • mqttAsyncClient

        protected org.eclipse.paho.client.mqttv3.MqttAsyncClient mqttAsyncClient
      • mqttClientOptions

        protected org.eclipse.paho.client.mqttv3.MqttConnectOptions mqttClientOptions
      • mqttCallback

        protected org.eclipse.paho.client.mqttv3.MqttCallback mqttCallback
      • mqttClient

        protected org.eclipse.paho.client.mqttv3.MqttClient mqttClient
      • persistence

        protected org.eclipse.paho.client.mqttv3.persist.MemoryPersistence persistence
    • Constructor Detail

      • AbstractClient

        public AbstractClient(AbstractConfig config)
        Note that this class does not have a default constructor
        Parameters:
        config - Configuration object for the client
    • Method Detail

      • connect

        public void connect()
                     throws org.eclipse.paho.client.mqttv3.MqttException,
                            KeyManagementException,
                            NoSuchAlgorithmException

        Connects the device to IBM Watson IoT Platform and retries when there is an exception based on the value set in retry parameter.
        This method does not retry when the following exceptions occur.

        • MqttSecurityException - One or more credentials are wrong
        • UnKnownHostException - Host doesn't exist. For example, a wrong organization name is used to connect.
        Throws:
        org.eclipse.paho.client.mqttv3.MqttException - One or more credentials are wrong
        NoSuchAlgorithmException - Problems with TLS
        KeyManagementException - Problems with TLS
      • configureMqttClient

        protected void configureMqttClient(org.eclipse.paho.client.mqttv3.MqttCallbackExtended callback)
                                    throws KeyManagementException,
                                           NoSuchAlgorithmException
        configureMqtt() is called when the User does not provide an Organization value and intends to connect to Watson IoT Platform using the QUICKSTART mode. This type of connection is In-secure in nature and is usually done over the 1883 Port Number.
        Parameters:
        callback - The handler for MQTT callbacks
        Throws:
        NoSuchAlgorithmException - Problems with TLS
        KeyManagementException - Problems with TLS
      • disconnect

        public void disconnect()
        Disconnect the device from the IBM Watson IoT Platform
      • close

        public void close()
                   throws org.eclipse.paho.client.mqttv3.MqttException
        Close and free all MQTT client resources
        Throws:
        org.eclipse.paho.client.mqttv3.MqttException - Thrown if an error occurs
      • isConnected

        public boolean isConnected()
        Determine whether this device is currently connected to the IBM Watson Internet of Things Platform.
        Returns:
        Whether the device is connected to the IBM Watson IoT Platform
      • toString

        public String toString()
        Provides a human readable String representation of this Device, including the number of messages sent and the current connect status.
        Overrides:
        toString in class Object
        Returns:
        String representation of the Device.

Copyright © 2019. All rights reserved.