public class MqttConnectOptions
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static boolean |
CLEAN_SESSION_DEFAULT
The default clean session setting if one is not specified
|
static int |
CONNECTION_TIMEOUT_DEFAULT
The default connection timeout in seconds if one is not specified
|
static int |
KEEP_ALIVE_INTERVAL_DEFAULT
The default keep alive interval in seconds if one is not specified
|
static int |
MAX_INFLIGHT_DEFAULT
The default max inflight if one is not specified
|
static int |
MQTT_VERSION_3_1 |
static int |
MQTT_VERSION_3_1_1 |
static int |
MQTT_VERSION_DEFAULT
The default MqttVersion is 3.1.1 first, dropping back to 3.1 if that fails
|
Constructor and Description |
---|
MqttConnectOptions()
Constructs a new
MqttConnectOptions object using the
default values. |
Modifier and Type | Method and Description |
---|---|
int |
getConnectionTimeout()
Returns the connection timeout value.
|
java.util.Properties |
getDebug() |
int |
getKeepAliveInterval()
Returns the "keep alive" interval.
|
int |
getMaxInflight()
Returns the "max inflight".
|
int |
getMqttVersion()
Returns the MQTT version.
|
char[] |
getPassword()
Returns the password to use for the connection.
|
java.lang.String[] |
getServerURIs()
Return a list of serverURIs the client may connect to
|
javax.net.SocketFactory |
getSocketFactory()
Returns the socket factory that will be used when connecting, or
null if one has not been set. |
java.util.Properties |
getSSLProperties()
Returns the SSL properties for the connection.
|
java.lang.String |
getUserName()
Returns the user name to use for the connection.
|
java.lang.String |
getWillDestination()
Returns the topic to be used for last will and testament (LWT).
|
MqttMessage |
getWillMessage()
Returns the message to be sent as last will and testament (LWT).
|
boolean |
isAutomaticReconnect()
Returns whether the client will automatically attempt to reconnect to the
server if the connection is lost
|
boolean |
isCleanSession()
Returns whether the client and server should remember state for the client across reconnects.
|
void |
setAutomaticReconnect(boolean automaticReconnect)
Sets whether the client will automatically attempt to reconnect to the
server if the connection is lost.
|
void |
setCleanSession(boolean cleanSession)
Sets whether the client and server should remember state across restarts and reconnects.
|
void |
setConnectionTimeout(int connectionTimeout)
Sets the connection timeout value.
|
void |
setKeepAliveInterval(int keepAliveInterval)
Sets the "keep alive" interval.
|
void |
setMaxInflight(int maxInflight)
Sets the "max inflight".
|
void |
setMqttVersion(int MqttVersion)
Sets the MQTT version.
|
void |
setPassword(char[] password)
Sets the password to use for the connection.
|
void |
setServerURIs(java.lang.String[] array)
Set a list of one or more serverURIs the client may connect to.
|
void |
setSocketFactory(javax.net.SocketFactory socketFactory)
Sets the
SocketFactory to use. |
void |
setSSLProperties(java.util.Properties props)
Sets the SSL properties for the connection.
|
void |
setUserName(java.lang.String userName)
Sets the user name to use for the connection.
|
void |
setWill(MqttTopic topic,
byte[] payload,
int qos,
boolean retained)
Sets the "Last Will and Testament" (LWT) for the connection.
|
void |
setWill(java.lang.String topic,
byte[] payload,
int qos,
boolean retained)
Sets the "Last Will and Testament" (LWT) for the connection.
|
java.lang.String |
toString() |
public static final int KEEP_ALIVE_INTERVAL_DEFAULT
public static final int CONNECTION_TIMEOUT_DEFAULT
public static final int MAX_INFLIGHT_DEFAULT
public static final boolean CLEAN_SESSION_DEFAULT
public static final int MQTT_VERSION_DEFAULT
public static final int MQTT_VERSION_3_1
public static final int MQTT_VERSION_3_1_1
public MqttConnectOptions()
MqttConnectOptions
object using the
default values.
The defaults are:
public char[] getPassword()
public void setPassword(char[] password)
public java.lang.String getUserName()
public void setUserName(java.lang.String userName)
java.lang.IllegalArgumentException
- if the user name is blank or only
contains whitespace characters.public void setWill(MqttTopic topic, byte[] payload, int qos, boolean retained)
topic
- the topic to publish to.payload
- the byte payload for the message.qos
- the quality of service to publish the message at (0, 1 or 2).retained
- whether or not the message should be retained.public void setWill(java.lang.String topic, byte[] payload, int qos, boolean retained)
topic
- the topic to publish to.payload
- the byte payload for the message.qos
- the quality of service to publish the message at (0, 1 or 2).retained
- whether or not the message should be retained.public int getKeepAliveInterval()
setKeepAliveInterval(int)
public int getMqttVersion()
setMqttVersion(int)
public void setKeepAliveInterval(int keepAliveInterval) throws java.lang.IllegalArgumentException
The default value is 60 seconds
keepAliveInterval
- the interval, measured in seconds, must be >= 0.java.lang.IllegalArgumentException
public int getMaxInflight()
setMaxInflight(int)
public void setMaxInflight(int maxInflight)
The default value is 10
maxInflight
- public int getConnectionTimeout()
setConnectionTimeout(int)
public void setConnectionTimeout(int connectionTimeout)
connectionTimeout
- the timeout value, measured in seconds. It must be >0;public javax.net.SocketFactory getSocketFactory()
null
if one has not been set.public void setSocketFactory(javax.net.SocketFactory socketFactory)
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.socketFactory
- the factory to use.public java.lang.String getWillDestination()
null
if LWT is not set.setWill(MqttTopic, byte[], int, boolean)
public MqttMessage getWillMessage()
IllegalStateException
being thrown.null
if LWT is not set.public java.util.Properties getSSLProperties()
public void setSSLProperties(java.util.Properties props)
setSocketFactory(SocketFactory)
.
The following properties can be used:
com.ibm.micro.security.Password.obfuscate(char[] password)
.
This obfuscates the password using a simple and insecure XOR and Base64
encoding mechanism. Note that this is only a simple scrambler to
obfuscate clear-text passwords.com.ibm.micro.security.Password.obfuscate(char[] password)
.
This obfuscates the password using a simple and insecure XOR and Base64
encoding mechanism. Note that this is only a simple scrambler to
obfuscate clear-text passwords.public boolean isCleanSession()
public void setCleanSession(boolean cleanSession)
public java.lang.String[] getServerURIs()
public void setServerURIs(java.lang.String[] array)
Each serverURI
specifies the address of a server that the client may
connect to. Two types of
connection are supported tcp://
for a TCP connection and
ssl://
for a TCP connection secured by SSL/TLS.
For example:
tcp://localhost:1883
ssl://localhost:8883
tcp://
" URIs, and 8883 for ssl://
URIs.
If serverURIs is set then it overrides the serverURI parameter passed in on the constructor of the MQTT client.
When an attempt to connect is initiated the client will start with the first serverURI in the list and work through the list until a connection is established with a server. If a connection cannot be made to any of the servers then the connect attempt fails.
Specifying a list of servers that a client may connect to has several uses:
Some MQTT servers support a high availability feature where two or more "equal" MQTT servers share state. An MQTT client can connect to any of the "equal" servers and be assured that messages are reliably delivered and durable subscriptions are maintained no matter which server the client connects to.
The cleansession flag must be set to false if durable subscriptions and/or reliable message delivery is required.
A set of servers may be specified that are not "equal" (as in the high availability option). As no state is shared across the servers reliable message delivery and durable subscriptions are not valid. The cleansession flag must be set to true if the hunt list mode is used
array
- of serverURIspublic void setMqttVersion(int MqttVersion) throws java.lang.IllegalArgumentException
MqttVersion
- the version of the MQTT protocol.java.lang.IllegalArgumentException
public boolean isAutomaticReconnect()
public void setAutomaticReconnect(boolean automaticReconnect)
automaticReconnect
- public java.util.Properties getDebug()
public java.lang.String toString()
toString
in class java.lang.Object