3535/**
3636 * Holds the set of options that control how the client connects to a server.
3737 *
38- * Constructs a new {@link MqttConnectionOptions} object using the
39- * default values.
38+ * Constructs a new {@link MqttConnectionOptions} object using the default
39+ * values.
4040 *
4141 * The defaults are:
4242 * <ul>
@@ -70,8 +70,7 @@ enum UriType {
7070 private boolean httpsHostnameVerificationEnabled = true ;
7171 private int maxReconnectDelay = 128000 ;
7272 private boolean sendReasonMessages = false ;
73-
74-
73+
7574 public MqttProperties getConnectionProperties () {
7675 MqttProperties connectionProperties = new MqttProperties ();
7776 connectionProperties .setSessionExpiryInterval (sessionExpiryInterval );
@@ -86,7 +85,6 @@ public MqttProperties getConnectionProperties() {
8685 return connectionProperties ;
8786 }
8887
89-
9088 public MqttProperties getWillMessageProperties () {
9189 return willMessageProperties ;
9290 }
@@ -105,7 +103,7 @@ public void setWillMessageProperties(MqttProperties willMessageProperties) {
105103 private String userName ; // Username
106104 private byte [] password ; // Password
107105 private Long sessionExpiryInterval = null ; // The Session expiry Interval in seconds, null is the default of
108- // never.
106+ // never.
109107 private Integer receiveMaximum = null ; // The Receive Maximum, null defaults to 65,535, cannot be 0.
110108 private Long maximumPacketSize = null ; // The Maximum packet size, null defaults to no limit.
111109 private Integer topicAliasMaximum = null ; // The Topic Alias Maximum, null defaults to 0.
@@ -221,25 +219,56 @@ public boolean isCleanStart() {
221219
222220 /**
223221 * Sets whether the client and server should remember state across restarts and
224- * reconnects.
225- * <ul>
226- * <li>If set to false both the client and server will maintain state across
227- * restarts of the client, the server and the connection. As state is
228- * maintained:
222+ * reconnects. If set to false, the server will retain the session state until
223+ * either:
229224 * <ul>
230- * <li>Message delivery will be reliable meeting the specified QOS even if the
231- * client, server or connection are restarted.
232- * <li>The server will treat a subscription as durable.
225+ * <li>A new connection is made with the client and with the cleanStart flag set
226+ * to true.</li>
227+ * <li>The Session expiry interval is exceeded after the network connection is
228+ * closed, see {@link MqttConnectionOptions#setSessionExpiryInterval}</li>
233229 * </ul>
234- * <li>If set to true the client and server will not maintain state across
235- * restarts of the client, the server or the connection. This means
230+ *
231+ * If set to true, the server will immediately drop any existing session state
232+ * for the given client and will initiate a new session.
233+ *
234+ * In order to implement QoS 1 and QoS 2 protocol flows the Client and Server
235+ * need to associate state with the Client Identifier, this is referred to as
236+ * the Session State. The Server also stores the subscriptions as part of the
237+ * Session State.
238+ *
239+ * The session can continue across a sequence of Network Connections. It lasts
240+ * as long as the latest Network Connection plus the Session Expiry Interval.
241+ *
242+ * The Session State in the Client consists of:
243+ *
236244 * <ul>
237- * <li>Message delivery to the specified QOS cannot be maintained if the client,
238- * server or connection are restarted
239- * <li>The server will treat a subscription as non-durable
245+ * <li>QoS 1 and QoS 2 messages which have been sent to the Server, but have not
246+ * been completely acknowledged.</li>
247+ * <li>QoS 2 messages which have been received from the Server, but have not
248+ * been completely acknowledged.</li>
240249 * </ul>
250+ *
251+ * The Session State in the Server consists of:
252+ * <ul>
253+ * <li>The existence of a Session, even if the rest of the Session State is
254+ * empty.</li>
255+ * <li>The Clients subscriptions, including any Subscription Identifiers.</li>
256+ * <li>QoS 1 and QoS 2 messages which have been sent to the Client, but have not
257+ * been completely acknowledged.</li>
258+ * <li>QoS 1 and QoS 2 messages pending transmission to the Client and
259+ * OPTIONALLY QoS 0 messages pending transmission to the Client.</li>
260+ * <li>QoS 2 messages which have been received from the Client, but have not
261+ * been completely acknowledged.The Will Message and the Will Delay
262+ * Interval</li>
263+ * <li>If the Session is currently not connected, the time at which the Session
264+ * will end and Session State will be discarded.</li>
241265 * </ul>
242266 *
267+ * Retained messages do not form part of the Session State in the Server, they
268+ * are not deleted as a result of a Session ending.
269+ *
270+ *
271+ *
243272 * @param cleanStart
244273 * Set to True to enable cleanSession
245274 */
@@ -275,7 +304,7 @@ public int getKeepAliveInterval() {
275304 * @throws IllegalArgumentException
276305 * if the keepAliveInterval was invalid
277306 */
278- public void setKeepAliveInterval (int keepAliveInterval ){
307+ public void setKeepAliveInterval (int keepAliveInterval ) {
279308 if (keepAliveInterval < 0 ) {
280309 throw new IllegalArgumentException ();
281310 }
@@ -310,22 +339,24 @@ public void setConnectionTimeout(int connectionTimeout) {
310339 }
311340
312341 /**
313- * Get the maximum time (in millis) to wait between reconnects
314- * @return Get the maximum time (in millis) to wait between reconnects
315- */
342+ * Get the maximum time (in millis) to wait between reconnects
343+ *
344+ * @return Get the maximum time (in millis) to wait between reconnects
345+ */
316346 public int getMaxReconnectDelay () {
317347 return maxReconnectDelay ;
318348 }
319349
320350 /**
321351 * Set the maximum time to wait between reconnects
322- * @param maxReconnectDelay the duration (in millis)
323- */
352+ *
353+ * @param maxReconnectDelay
354+ * the duration (in millis)
355+ */
324356 public void setMaxReconnectDelay (int maxReconnectDelay ) {
325357 this .maxReconnectDelay = maxReconnectDelay ;
326358 }
327359
328-
329360 /**
330361 * Return a list of serverURIs the client may connect to
331362 *
@@ -376,8 +407,8 @@ public String[] getServerURIs() {
376407 * <p>
377408 * A set of servers may be specified that are not "equal" (as in the high
378409 * availability option). As no state is shared across the servers reliable
379- * message delivery and durable subscriptions are not valid. The cleanStart
380- * flag must be set to true if the hunt list mode is used
410+ * message delivery and durable subscriptions are not valid. The cleanStart flag
411+ * must be set to true if the hunt list mode is used
381412 * </p>
382413 * </li>
383414 * </ol>
@@ -496,7 +527,6 @@ public void setSessionExpiryInterval(Long sessionExpiryInterval) {
496527 this .sessionExpiryInterval = sessionExpiryInterval ;
497528 }
498529
499-
500530 /**
501531 * Returns the Receive Maximum value. If <code>null</code>, it will default to
502532 * 65,535.
@@ -901,12 +931,10 @@ public boolean isHttpsHostnameVerificationEnabled() {
901931 return httpsHostnameVerificationEnabled ;
902932 }
903933
904-
905934 public void setHttpsHostnameVerificationEnabled (boolean httpsHostnameVerificationEnabled ) {
906935 this .httpsHostnameVerificationEnabled = httpsHostnameVerificationEnabled ;
907936 }
908937
909-
910938 /**
911939 * @return The Debug Properties
912940 */
@@ -940,12 +968,10 @@ public static String generateClientId() {
940968 return CLIENT_ID_PREFIX + System .nanoTime ();
941969 }
942970
943-
944971 public boolean isSendReasonMessages () {
945972 return sendReasonMessages ;
946973 }
947974
948-
949975 public void setSendReasonMessages (boolean sendReasonMessages ) {
950976 this .sendReasonMessages = sendReasonMessages ;
951977 }
0 commit comments