-
public class MqttConnectOptionsHolds the set of options that control how the client connects to a server.
-
-
Field Summary
Fields Modifier and Type Field Description public final static intKEEP_ALIVE_INTERVAL_DEFAULTpublic final static intCONNECTION_TIMEOUT_DEFAULTpublic final static intHANDSHAKE_TIMEOUT_DEFAULTpublic final static intREAD_TIMEOUT_DEFAULTpublic final static booleanCLEAN_SESSION_DEFAULTprivate intkeepAliveIntervalprivate intkeepAliveIntervalServerprivate StringwillDestinationprivate MqttMessagewillMessageprivate StringuserNameprivate Array<char>passwordprivate SocketFactorysocketFactoryprivate booleancleanSessionprivate intconnectionTimeoutprivate inthandshakeTimeoutprivate intreadTimeoutprivate StringprotocolNameprivate intprotocolLevelprivate Array<String>serverURIsprivate List<UserProperty>userPropertyList
-
Constructor Summary
Constructors Constructor Description MqttConnectOptions()Constructs a new MqttConnectOptionsobject using the default values.
-
Method Summary
Modifier and Type Method Description intgetKeepAliveInterval()Returns the "keep alive" interval. voidsetKeepAliveInterval(int keepAliveInterval)Sets the "keep alive" interval. intgetKeepAliveIntervalServer()voidsetKeepAliveIntervalServer(int keepAliveInterval)StringgetWillDestination()Returns the topic to be used for last will and testament (LWT). MqttMessagegetWillMessage()Returns the message to be sent as last will and testament (LWT). StringgetUserName()Returns the user name to use for the connection. voidsetUserName(String userName)Sets the user name to use for the connection. Array<char>getPassword()Returns the password to use for the connection. voidsetPassword(Array<char> password)Sets the password to use for the connection. SocketFactorygetSocketFactory()Returns the socket factory that will be used when connecting, or nullif one has not been set.voidsetSocketFactory(SocketFactory socketFactory)Sets the SocketFactoryto use.voidsetCleanSession(boolean cleanSession)Sets whether the client and server should remember state across restarts and reconnects. intgetConnectionTimeout()Returns the connection timeout value. voidsetConnectionTimeout(int connectionTimeout)Sets the connection timeout value. intgetHandshakeTimeout()Returns the handshake timeout value. voidsetHandshakeTimeout(int handshakeTimeout)Sets the handshake timeout value. intgetReadTimeout()Returns the read timeout value. voidsetReadTimeout(int readTimeout)Sets the read timeout value. StringgetProtocolName()voidsetProtocolName(String protocolName)intgetProtocolLevel()voidsetProtocolLevel(int protocolLevel)Array<String>getServerURIs()Return a list of serverURIs the client may connect to voidsetServerURIs(Array<String> array)Set a list of one or more serverURIs the client may connect to. List<UserProperty>getUserPropertyList()voidsetUserPropertyList(List<UserProperty> userPropertyList)voidsetWill(MqttTopic topic, Array<byte> payload, int qos, boolean retained)Sets the "Last Will and Testament" (LWT) for the connection. voidsetWill(String topic, Array<byte> payload, int qos, boolean retained)Sets the "Last Will and Testament" (LWT) for the connection. PropertiesgetSSLProperties()Returns the SSL properties for the connection. voidsetSSLProperties(Properties props)Sets the SSL properties for the connection. booleanisCleanSession()Returns whether the client and server should remember state for the client across reconnects. PropertiesgetDebug()-
-
Method Detail
-
getKeepAliveInterval
int getKeepAliveInterval()
Returns the "keep alive" interval.
-
setKeepAliveInterval
void setKeepAliveInterval(int keepAliveInterval)
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.
-
getKeepAliveIntervalServer
int getKeepAliveIntervalServer()
-
setKeepAliveIntervalServer
void setKeepAliveIntervalServer(int keepAliveInterval)
-
getWillDestination
String getWillDestination()
Returns the topic to be used for last will and testament (LWT).
-
getWillMessage
MqttMessage getWillMessage()
Returns the message to be sent as last will and testament (LWT). The returned object is "read only". Calling any "setter" methods on the returned object will result in an
IllegalStateExceptionbeing thrown.
-
getUserName
String getUserName()
Returns the user name to use for the connection.
-
setUserName
void setUserName(String userName)
Sets the user name to use for the connection.
-
getPassword
Array<char> getPassword()
Returns the password to use for the connection.
-
setPassword
void setPassword(Array<char> password)
Sets the password to use for the connection.
-
getSocketFactory
SocketFactory getSocketFactory()
Returns the socket factory that will be used when connecting, or
nullif one has not been set.
-
setSocketFactory
void setSocketFactory(SocketFactory socketFactory)
Sets the
SocketFactoryto 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.
-
setCleanSession
void setCleanSession(boolean cleanSession)
Sets whether the client and server should remember state across restarts and reconnects.
- If set to false both the client and server will maintain state across restarts of the client, the server and the connection. As state is maintained:
- Message delivery will be reliable meeting the specified QOS even if the client, server or connection are restarted.
- The server will treat a subscription as durable.
- If set to true the client and server will not maintain state across restarts of the client, the server or the connection. This means
- Message delivery to the specified QOS cannot be maintained if the client, server or connection are restarted
- The server will treat a subscription as non-durable
- If set to false both the client and server will maintain state across restarts of the client, the server and the connection. As state is maintained:
-
getConnectionTimeout
int getConnectionTimeout()
Returns the connection timeout value.
-
setConnectionTimeout
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.
-
getHandshakeTimeout
int getHandshakeTimeout()
Returns the handshake timeout value.
-
setHandshakeTimeout
void setHandshakeTimeout(int handshakeTimeout)
Sets the handshake timeout value.
- Parameters:
handshakeTimeout- the timeout value, measured in seconds.
-
getReadTimeout
int getReadTimeout()
Returns the read timeout value.
-
setReadTimeout
void setReadTimeout(int readTimeout)
Sets the read timeout value. This value, measured in seconds, defines the maximum time interval a read() call on the InputStream associated with this Socket will block for. The default timeout is 360 seconds. A value of 0 is interpreted as an infinite timeout.
- Parameters:
readTimeout- the timeout value, measured in seconds.
-
getProtocolName
String getProtocolName()
-
setProtocolName
void setProtocolName(String protocolName)
-
getProtocolLevel
int getProtocolLevel()
-
setProtocolLevel
void setProtocolLevel(int protocolLevel)
-
getServerURIs
Array<String> getServerURIs()
Return a list of serverURIs the client may connect to
-
setServerURIs
void setServerURIs(Array<String> array)
Set a list of one or more serverURIs the client may connect to.
Each
serverURIspecifies the address of a server that the client may connect to. Two types of connection are supportedtcp://for a TCP connection andssl://for a TCP connection secured by SSL/TLS. For example:tcp://localhost:1883ssl://localhost:8883
tcp://" URIs, and 8883 forssl://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:
- High Availability and reliable message delivery
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.
- Hunt List
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
- Parameters:
array- of serverURIs
-
getUserPropertyList
List<UserProperty> getUserPropertyList()
-
setUserPropertyList
void setUserPropertyList(List<UserProperty> userPropertyList)
-
setWill
void setWill(MqttTopic topic, Array<byte> payload, int qos, boolean retained)
Sets the "Last Will and Testament" (LWT) for the connection. In the event that this client unexpectedly loses its connection to the server, the server will publish a message to itself using the supplied details.
- Parameters:
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.
-
setWill
void setWill(String topic, Array<byte> payload, int qos, boolean retained)
Sets the "Last Will and Testament" (LWT) for the connection. In the event that this client unexpectedly loses its connection to the server, the server will publish a message to itself using the supplied details.
- Parameters:
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.
-
getSSLProperties
Properties getSSLProperties()
Returns the SSL properties for the connection.
-
setSSLProperties
void setSSLProperties(Properties props)
Sets the SSL properties for the connection. Note that these properties are only valid if an implementation of the Java Secure Socket Extensions (JSSE) is available. These properties are not used if a SocketFactory has been set using setSocketFactory. The following properties can be used:
-
isCleanSession
boolean isCleanSession()
Returns whether the client and server should remember state for the client across reconnects.
-
getDebug
Properties getDebug()
-
-
-
-