Source:
<code>private void mqttConnect(MqttConnectOptions options) { LOGGER.debug("ready to do mqtt connect"); options.setCleanSession(cleanSession); options.setKeepAliveInterval(userKeepAlive); if (isMetricsEnabled() && !AuthenticationMode.USERNAME_PASSWORD.equals(authMode)) { options.setUserName(userMetaData); } LOGGER.info("metrics collection is " + (isMetricsEnabled() ? "enabled" : "disabled") + ", username: " + options.getUserName()); topicListeners.clear(); mqttMessageQueue.clear(); resetReconnect(); userDisconnect = false; setupCallbackForMqttClient(); try { connectionState = MqttManagerConnectionState.Connecting; userConnectionCallback(); mqttClient.connect(options, null, new IMqttActionListener() { @Override public void onSuccess(IMqttToken asyncActionToken) { LOGGER.info("onSuccess: mqtt connection is successful."); connectionState = MqttManagerConnectionState.Connected; lastConnackTime = getSystemTimeMs(); sessionPresent = asyncActionToken.getSessionPresent(); if (mqttMessageQueue.size() > 0) { publishMessagesFromQueue(); } userConnectionCallback(); } @Override public void onFailure(IMqttToken asyncActionToken, Throwable e) { LOGGER.warn("onFailure: connection failed.", e); if (!userDisconnect && autoReconnect) { connectionState = MqttManagerConnectionState.Reconnecting; userConnectionCallback(e); scheduleReconnect(); } else { connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(e); } sessionPresent = asyncActionToken.getSessionPresent(); } }); <START> } catch (final MqttException e) { <END> switch (e.getReasonCode()) { case MqttException.REASON_CODE_CLIENT_CONNECTED: connectionState = MqttManagerConnectionState.Connected; userConnectionCallback(); break; case MqttException.REASON_CODE_CONNECT_IN_PROGRESS: connectionState = MqttManagerConnectionState.Connecting; userConnectionCallback(); break; default: connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(e); break; } } catch (final Exception exception) { connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(exception); } }</code><technical_language>sense update sessionPresent here? appears mqttClient.connect(...) throw MqttException, recover, call userConnectionCallback()</technical_language>

Target:
private void mqttConnect(MqttConnectOptions options) { LOGGER.debug("ready to do mqtt connect"); options.setCleanSession(cleanSession); options.setKeepAliveInterval(userKeepAlive); if (isMetricsEnabled() && !AuthenticationMode.USERNAME_PASSWORD.equals(authMode)) { options.setUserName(userMetaData); } LOGGER.info("metrics collection is " + (isMetricsEnabled() ? "enabled" : "disabled") + ", username: " + options.getUserName()); topicListeners.clear(); mqttMessageQueue.clear(); resetReconnect(); userDisconnect = false; setupCallbackForMqttClient(); try { connectionState = MqttManagerConnectionState.Connecting; userConnectionCallback(); mqttClient.connect(options, null, new IMqttActionListener() { @Override public void onSuccess(IMqttToken asyncActionToken) { LOGGER.info("onSuccess: mqtt connection is successful."); connectionState = MqttManagerConnectionState.Connected; lastConnackTime = getSystemTimeMs(); sessionPresent = asyncActionToken.getSessionPresent(); if (mqttMessageQueue.size() > 0) { publishMessagesFromQueue(); } userConnectionCallback(); } @Override public void onFailure(IMqttToken asyncActionToken, Throwable e) { LOGGER.warn("onFailure: connection failed.", e); if (!userDisconnect && autoReconnect) { connectionState = MqttManagerConnectionState.Reconnecting; sessionPresent = asyncActionToken.getSessionPresent(); userConnectionCallback(e); scheduleReconnect(); } else { connectionState = MqttManagerConnectionState.Disconnected; sessionPresent = asyncActionToken.getSessionPresent(); userConnectionCallback(e); } sessionPresent = asyncActionToken.getSessionPresent(); } }); } catch (final MqttException e) { switch (e.getReasonCode()) { case MqttException.REASON_CODE_CLIENT_CONNECTED: connectionState = MqttManagerConnectionState.Connected; userConnectionCallback(); break; case MqttException.REASON_CODE_CONNECT_IN_PROGRESS: connectionState = MqttManagerConnectionState.Connecting; userConnectionCallback(); break; default: connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(e); break; } } catch (final Exception exception) { connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(exception); } }