Class MqttConnectOptions


  • public class MqttConnectOptions
    extends Object
    Holds the set of options that control how the client connects to a server.
    • Field Detail

      • KEEP_ALIVE_INTERVAL_DEFAULT

        public static final int KEEP_ALIVE_INTERVAL_DEFAULT
        The default keep alive interval in seconds if one is not specified.
        See Also:
        Constant Field Values
      • CONNECTION_TIMEOUT_DEFAULT

        public static final int CONNECTION_TIMEOUT_DEFAULT
        The default connection timeout in seconds if one is not specified.
        See Also:
        Constant Field Values
      • MQTT_VERSION_3_1_1

        public static final int MQTT_VERSION_3_1_1
        Mqtt Version 3.1.1.
        See Also:
        Constant Field Values
    • Constructor Detail

      • MqttConnectOptions

        public MqttConnectOptions()
        Constructs a new MqttConnectOptions object using the default values. The defaults are:
        • The keepalive interval is 60 seconds
        • The connection timeout period is 30 seconds
        • A standard SocketFactory is used
        More information about these values can be found in the setter methods.
    • Method Detail

      • getPassword

        @Nullable
        public char[] getPassword()
        Returns the password to use for the connection.
        Returns:
        the password to use for the connection, or null if no password is required for the connection. Important Note : The returned char array is not cloned for memory efficiency reasons. Be careful with it.
      • setPassword

        public void setPassword​(char[] password)
        Sets the password to use for the connection.
        Parameters:
        password - A Char Array of the password. Important Note : The char array is not cloned for memory efficiency reasons. Be careful with it.
      • getUserName

        @Nullable
        public String getUserName()
        Returns the user name to use for the connection.
        Returns:
        the user name to use for the connection, or null if no password is required for the connection.
      • setUserName

        public void setUserName​(String userName)
        Sets the user name to use for the connection.
        Parameters:
        userName - The Username as a String
      • getKeepAliveInterval

        public int getKeepAliveInterval()
        Returns the "keep alive" interval.
        Returns:
        the keep alive interval.
        See Also:
        setKeepAliveInterval(int)
      • getMqttVersion

        public int getMqttVersion()
        Returns the MQTT version.
        Returns:
        the MQTT version.
      • setKeepAliveInterval

        public void setKeepAliveInterval​(int keepAliveInterval)
                                  throws IllegalArgumentException
        Sets the "keep alive" interval. This value, measured in seconds, defines the maximum time interval between messages sent or received. It enables the client to detect if the server is no longer available, without having to wait for the TCP/IP timeout. The client will ensure that at least one message travels across the network within each keep alive period. In the absence of a data-related message during the time period, the client sends a very small "ping" message, which the server will acknowledge. A value of 0 disables keepalive processing in the client.

        The default value is 60 seconds

        Parameters:
        keepAliveInterval - the interval, measured in seconds, must be >= 0.
        Throws:
        IllegalArgumentException - if the keepAliveInterval was invalid
      • getConnectionTimeout

        public int getConnectionTimeout()
        Returns the connection timeout value in seconds.
        Returns:
        the connection timeout value in seconds.
        See Also:
        setConnectionTimeout(int)
      • setConnectionTimeout

        public void setConnectionTimeout​(int connectionTimeout)
        Sets the connection timeout value. This value, measured in seconds, defines the maximum time interval the client will wait for the network connection to the MQTT server to be established. The default timeout is 30 seconds. A value of 0 disables timeout processing meaning the client will wait until the network connection is made successfully or fails.
        Parameters:
        connectionTimeout - the timeout value, measured in seconds. It must be >0;
      • getSocketFactory

        @Nullable
        public SocketFactory getSocketFactory()
        Returns the socket factory that will be used when connecting, or null if one has not been set.
        Returns:
        The Socket Factory
      • setSocketFactory

        public void setSocketFactory​(SocketFactory socketFactory)
        Sets the SocketFactory to use. This allows an application to apply its own policies around the creation of network sockets. If using an SSL connection, an SSLSocketFactory can be used to supply application-specific security settings.
        Parameters:
        socketFactory - the factory to use.
      • isCleanSession

        public boolean isCleanSession()
        Returns whether the client and server should remember state for the client across reconnects.
        Returns:
        the clean session flag