/** * Wrapper method to notify user if they have specified a callback. * Maps internal state to user connection statuses. */ void userConnectionCallback() { userConnectionCallback(null); }
@Override public void onFailure(IMqttToken asyncActionToken, Throwable e) { LOGGER.warn("Reconnect failed ", e); if (scheduleReconnect()) { connectionState = MqttManagerConnectionState.Reconnecting; userConnectionCallback(e); } else { connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(e); } } });
@Override public void onFailure(IMqttToken asyncActionToken, Throwable e) { LOGGER.warn("onFailure: connection failed.", e); // Testing shows following reason codes: // REASON_CODE_CLIENT_EXCEPTION = network unavailable / host unresolved // REASON_CODE_CLIENT_EXCEPTION = deactivated certificate // REASON_CODE_CLIENT_EXCEPTION = unknown certificate // REASON_CODE_CONNECTION_LOST = no policy attached // REASON_CODE_CONNECTION_LOST = bad connection policy if (!userDisconnect && autoReconnect) { connectionState = MqttManagerConnectionState.Reconnecting; userConnectionCallback(e); scheduleReconnect(); } else { connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(e); } } });
/** * Disconnect from a mqtt client (close current MQTT session). * * @return true if disconnect finished with success. */ public boolean disconnect() { userDisconnect = true; reset(); topicListeners.clear(); connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(); return true; }
@Override public void onSuccess(IMqttToken asyncActionToken) { LOGGER.info("onSuccess: mqtt connection is successful."); connectionState = MqttManagerConnectionState.Connected; lastConnackTime = getSystemTimeMs(); if (mqttMessageQueue.size() > 0) { publishMessagesFromQueue(); } userConnectionCallback(); }
@Override public void connectionLost(Throwable cause) { LOGGER.warn("connection is Lost"); if (!userDisconnect && autoReconnect) { // If we have been connected longer than the connectionStabilityTime then // restart the reconnect logic from minimum value before scheduling reconnect. if ((lastConnackTime + (connectionStabilityTime * MILLIS_IN_ONE_SECOND)) < getSystemTimeMs()) { resetReconnect(); } if (scheduleReconnect()) { connectionState = MqttManagerConnectionState.Reconnecting; } else { connectionState = MqttManagerConnectionState.Disconnected; } } else { connectionState = MqttManagerConnectionState.Disconnected; } userConnectionCallback(cause); }
@Override public void onSuccess(IMqttToken asyncActionToken) { LOGGER.info("Reconnect successful"); connectionState = MqttManagerConnectionState.Connected; lastConnackTime = getSystemTimeMs(); if (needResubscribe) { resubscribeToTopics(); } if (mqttMessageQueue.size() > 0) { publishMessagesFromQueue(); } userConnectionCallback(); }
userConnectionCallback(); 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; userConnectionCallback(exception);
userConnectionCallback(new AmazonClientException("An error occurred in the MQTT client.", e)); } catch (final Exception e) { connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(e);
/** * Wrapper method to notify user if they have specified a callback. * Maps internal state to user connection statuses. */ void userConnectionCallback() { userConnectionCallback(null); }
connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(e); if (scheduleReconnect()) { connectionState = MqttManagerConnectionState.Reconnecting; userConnectionCallback(e); } else { connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(e);
@Override public void onFailure(IMqttToken asyncActionToken, Throwable e) { LOGGER.warn("Reconnect failed ", e); if (scheduleReconnect()) { connectionState = MqttManagerConnectionState.Reconnecting; userConnectionCallback(e); } else { connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(e); } } });
@Override public void onFailure(IMqttToken asyncActionToken, Throwable e) { LOGGER.warn("onFailure: connection failed.", e); // Testing shows following reason codes: // REASON_CODE_CLIENT_EXCEPTION = network unavailable / host unresolved // REASON_CODE_CLIENT_EXCEPTION = deactivated certificate // REASON_CODE_CLIENT_EXCEPTION = unknown certificate // REASON_CODE_CONNECTION_LOST = no policy attached // REASON_CODE_CONNECTION_LOST = bad connection policy if (!userDisconnect && autoReconnect) { connectionState = MqttManagerConnectionState.Reconnecting; userConnectionCallback(e); scheduleReconnect(); } else { connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(e); } } });
/** * Disconnect from a mqtt client (close current MQTT session). * * @return true if disconnect finished with success. */ public boolean disconnect() { userDisconnect = true; reset(); topicListeners.clear(); connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(); return true; }
@Override public void onSuccess(IMqttToken asyncActionToken) { LOGGER.info("onSuccess: mqtt connection is successful."); connectionState = MqttManagerConnectionState.Connected; lastConnackTime = getSystemTimeMs(); if (mqttMessageQueue.size() > 0) { publishMessagesFromQueue(); } userConnectionCallback(); }
@Override public void onSuccess(IMqttToken asyncActionToken) { LOGGER.info("Reconnect successful"); connectionState = MqttManagerConnectionState.Connected; lastConnackTime = getSystemTimeMs(); if (needResubscribe) { resubscribeToTopics(); } if (mqttMessageQueue.size() > 0) { publishMessagesFromQueue(); } userConnectionCallback(); }
@Override public void connectionLost(Throwable cause) { LOGGER.warn("connection is Lost"); if (!userDisconnect && autoReconnect) { // If we have been connected longer than the connectionStabilityTime then // restart the reconnect logic from minimum value before scheduling reconnect. if ((lastConnackTime + (connectionStabilityTime * MILLIS_IN_ONE_SECOND)) < getSystemTimeMs()) { resetReconnect(); } if (scheduleReconnect()) { connectionState = MqttManagerConnectionState.Reconnecting; } else { connectionState = MqttManagerConnectionState.Disconnected; } } else { connectionState = MqttManagerConnectionState.Disconnected; } userConnectionCallback(cause); }
userConnectionCallback(new AmazonClientException("An error occurred in the MQTT client.", e)); } catch (final Exception e) { connectionState = MqttManagerConnectionState.Disconnected; userConnectionCallback(e);