changed log from printing stack trace to meaning logs stating waiting for either broker or key manager

revert-dabc3590
ayyoob 8 years ago
parent 39097abcec
commit 01edaeeab4

@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHeader;
@ -131,7 +132,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
} }
} }
public void startListener() throws MqttException { public boolean startListener() throws MqttException {
if (this.mqttBrokerConnectionConfiguration.getUsername() != null && if (this.mqttBrokerConnectionConfiguration.getUsername() != null &&
this.mqttBrokerConnectionConfiguration.getDcrUrl() != null) { this.mqttBrokerConnectionConfiguration.getDcrUrl() != null) {
String username = this.mqttBrokerConnectionConfiguration.getUsername(); String username = this.mqttBrokerConnectionConfiguration.getUsername();
@ -182,21 +183,29 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
log.error(msg, e); log.error(msg, e);
} }
} }
} catch (HttpHostConnectException e) {
log.error("Keymanager is unreachable, Waiting....");
return false;
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
log.error("Invalid dcrUrl : " + dcrUrlString); log.error("Invalid dcrUrl : " + dcrUrlString);
return false;
} catch (JWTClientException | UserStoreException e) { } catch (JWTClientException | UserStoreException e) {
log.error("Failed to create an oauth token with jwt grant type.", e); log.error("Failed to create an oauth token with jwt grant type.", e);
return false;
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | IOException e) { } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | IOException e) {
log.error("Failed to create a http connection.", e); log.error("Failed to create a http connection.", e);
return false;
} }
} }
} }
try { try {
mqttClient.connect(connectionOptions); mqttClient.connect(connectionOptions);
} catch (MqttException e) { } catch (MqttException e) {
log.error("Broker is unreachable, Waiting....."); log.warn("Broker is unreachable, Waiting.....");
return false;
} }
mqttClient.subscribe(topic); mqttClient.subscribe(topic);
return true;
} }
@ -271,10 +280,14 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
while (!connectionSucceeded) { while (!connectionSucceeded) {
try { try {
connectionDuration = connectionDuration * MQTTEventAdapterConstants.RECONNECTION_PROGRESS_FACTOR; connectionDuration = connectionDuration * MQTTEventAdapterConstants.RECONNECTION_PROGRESS_FACTOR;
if (connectionDuration > MQTTEventAdapterConstants.MAXIMUM_RECONNECTION_DURATION) {
connectionDuration = MQTTEventAdapterConstants.MAXIMUM_RECONNECTION_DURATION;
}
Thread.sleep(connectionDuration); Thread.sleep(connectionDuration);
startListener(); if (startListener()) {
connectionSucceeded = true; connectionSucceeded = true;
log.info("MQTT Connection successful"); log.info("MQTT Connection successful");
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.error("Interruption occurred while waiting for reconnection", e); log.error("Interruption occurred while waiting for reconnection", e);
} catch (MqttException e) { } catch (MqttException e) {

@ -50,6 +50,7 @@ public class MQTTEventAdapterConstants {
public static final int INITIAL_RECONNECTION_DURATION = 4000; public static final int INITIAL_RECONNECTION_DURATION = 4000;
public static final int RECONNECTION_PROGRESS_FACTOR = 2; public static final int RECONNECTION_PROGRESS_FACTOR = 2;
public static final int MAXIMUM_RECONNECTION_DURATION = 60000;
public static final String EMPTY_STRING = ""; public static final String EMPTY_STRING = "";
public static final String GRANT_TYPE_PARAM_NAME = "grant_type"; public static final String GRANT_TYPE_PARAM_NAME = "grant_type";

Loading…
Cancel
Save