Package org.eclipse.paho.client.mqttv3
Class MqttConnectOptions
- java.lang.Object
-
- org.eclipse.paho.client.mqttv3.MqttConnectOptions
-
public class MqttConnectOptions extends Object
Holds the set of options that control how the client connects to a server.
-
-
Field Summary
Fields Modifier and Type Field Description static intCONNECTION_TIMEOUT_DEFAULTThe default connection timeout in seconds if one is not specified.static intKEEP_ALIVE_INTERVAL_DEFAULTThe default keep alive interval in seconds if one is not specified.static intMQTT_VERSION_3_1_1Mqtt Version 3.1.1.
-
Constructor Summary
Constructors Constructor Description MqttConnectOptions()Constructs a newMqttConnectOptionsobject using the default values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetConnectionTimeout()Returns the connection timeout value in seconds.intgetKeepAliveInterval()Returns the "keep alive" interval.intgetMqttVersion()Returns the MQTT version.char[]getPassword()Returns the password to use for the connection.SocketFactorygetSocketFactory()Returns the socket factory that will be used when connecting, ornullif one has not been set.StringgetUserName()Returns the user name to use for the connection.booleanisCleanSession()Returns whether the client and server should remember state for the client across reconnects.voidsetConnectionTimeout(int connectionTimeout)Sets the connection timeout value.voidsetKeepAliveInterval(int keepAliveInterval)Sets the "keep alive" interval.voidsetPassword(char[] password)Sets the password to use for the connection.voidsetSocketFactory(SocketFactory socketFactory)Sets theSocketFactoryto use.voidsetUserName(String userName)Sets the user name to use for the connection.
-
-
-
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 newMqttConnectOptionsobject 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
-
-
Method Detail
-
getPassword
@Nullable public char[] getPassword()
Returns the password to use for the connection.- Returns:
- the password to use for the connection, or
nullif 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
nullif 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 IllegalArgumentExceptionSets 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, ornullif one has not been set.- Returns:
- The Socket Factory
-
setSocketFactory
public void setSocketFactory(SocketFactory socketFactory)
Sets theSocketFactoryto use. This allows an application to apply its own policies around the creation of network sockets. If using an SSL connection, anSSLSocketFactorycan 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
-
-