From 4001dbf8877b68120952c7518d551932b80ccfb7 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Wed, 18 May 2016 19:32:39 +0530 Subject: [PATCH] fixed exponential backup logic --- .../iot/input/adapter/mqtt/util/MQTTAdapterListener.java | 6 +++--- .../input/adapter/mqtt/util/MQTTEventAdapterConstants.java | 2 +- .../iot/input/adapter/xmpp/util/XMPPAdapterListener.java | 6 +++--- .../input/adapter/xmpp/util/XMPPEventAdapterConstants.java | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTAdapterListener.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTAdapterListener.java index 3053671416..2562a00ef3 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTAdapterListener.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTAdapterListener.java @@ -263,11 +263,11 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { @Override public void run() { + int connectionDuration = MQTTEventAdapterConstants.initialReconnectDuration; while (!connectionSucceeded) { try { - MQTTEventAdapterConstants.initialReconnectDuration = MQTTEventAdapterConstants.initialReconnectDuration - * MQTTEventAdapterConstants.reconnectionProgressionFactor; - Thread.sleep(MQTTEventAdapterConstants.initialReconnectDuration); + connectionDuration = connectionDuration * MQTTEventAdapterConstants.reconnectionProgressionFactor; + Thread.sleep(connectionDuration); startListener(); connectionSucceeded = true; log.info("MQTT Connection successful"); diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTEventAdapterConstants.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTEventAdapterConstants.java index 4625c433ac..88ac43171b 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTEventAdapterConstants.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/mqtt/util/MQTTEventAdapterConstants.java @@ -48,7 +48,7 @@ public class MQTTEventAdapterConstants { public static final int ADAPTER_CONF_DEFAULT_KEEP_ALIVE = 60000; public static int initialReconnectDuration = 2000; - public static final int reconnectionProgressionFactor = 4; + public static final int reconnectionProgressionFactor = 2; public static final String EMPTY_STRING = ""; public static final String GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer refresh_token"; diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPAdapterListener.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPAdapterListener.java index bf5c6fde85..b31ac945c0 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPAdapterListener.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPAdapterListener.java @@ -203,10 +203,10 @@ public class XMPPAdapterListener implements Runnable { @Override public void run() { while (!connectionSucceeded) { + int connectionDuration = XMPPEventAdapterConstants.initialReconnectDuration; try { - XMPPEventAdapterConstants.initialReconnectDuration = XMPPEventAdapterConstants.initialReconnectDuration - * XMPPEventAdapterConstants.reconnectionProgressionFactor; - Thread.sleep(XMPPEventAdapterConstants.initialReconnectDuration); + connectionDuration = connectionDuration * XMPPEventAdapterConstants.reconnectionProgressionFactor; + Thread.sleep(connectionDuration); startListener(); connectionSucceeded = true; log.info("XMPP Connection successful"); diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPEventAdapterConstants.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPEventAdapterConstants.java index 304f4578a7..d62f78ab2e 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPEventAdapterConstants.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.input.adapter.xmpp/src/main/java/org/wso2/carbon/device/mgt/iot/input/adapter/xmpp/util/XMPPEventAdapterConstants.java @@ -50,7 +50,7 @@ public class XMPPEventAdapterConstants { public static final int DEFAULT_TIMEOUT_INTERVAL = 5000; public static int initialReconnectDuration = 2000; - public static final int reconnectionProgressionFactor = 4; + public static final int reconnectionProgressionFactor = 2; public static final String DEFAULT = "default";