From 8a9ad21e742367d2ce14753f9d453912b524b0d3 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Mon, 27 Jun 2016 00:13:15 +0530 Subject: [PATCH] few changes added to transport adapters after testing with the cluster --- .../mgt/iot/input/adapter/mqtt/MQTTEventAdapter.java | 7 +++++-- .../iot/input/adapter/mqtt/util/MQTTAdapterListener.java | 6 ++++++ .../mgt/iot/input/adapter/xmpp/XMPPEventAdapter.java | 6 ++++-- .../iot/input/adapter/xmpp/util/XMPPAdapterListener.java | 7 +++++++ .../plugin/impl/util/VirtualFirealarmStartupListener.java | 3 ++- 5 files changed, 24 insertions(+), 5 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/MQTTEventAdapter.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/MQTTEventAdapter.java index 0c42d056f..de5c073e2 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/MQTTEventAdapter.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/MQTTEventAdapter.java @@ -96,7 +96,10 @@ public class MQTTEventAdapter implements InputEventAdapter { @Override public void connect() { - mqttAdapterListener.createConnection(); + if (!mqttAdapterListener.isConnectionInitialized()) { + mqttAdapterListener.createConnection(); + } + } @Override @@ -147,7 +150,7 @@ public class MQTTEventAdapter implements InputEventAdapter { @Override public boolean isPolling() { - return true; + return mqttAdapterListener.isConnectionInitialized(); } } 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 87c77d177..ec630d0ce 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 @@ -58,6 +58,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { private MqttClient mqttClient; private MqttConnectOptions connectionOptions; private boolean cleanSession; + private boolean connectionInitialized; private MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration; private String topic; @@ -279,6 +280,11 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { } public void createConnection() { + connectionInitialized = true; new Thread(this).start(); } + + public boolean isConnectionInitialized() { + return connectionInitialized; + } } 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/XMPPEventAdapter.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/XMPPEventAdapter.java index 936e85282..7bfe7989a 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/XMPPEventAdapter.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/XMPPEventAdapter.java @@ -103,7 +103,9 @@ public class XMPPEventAdapter implements InputEventAdapter { @Override public void connect() { - xmppAdapterListener.createConnection(); + if (xmppAdapterListener.isConnectionInitialized()) { + xmppAdapterListener.createConnection(); + } } @Override @@ -142,7 +144,7 @@ public class XMPPEventAdapter implements InputEventAdapter { @Override public boolean isPolling() { - return true; + return xmppAdapterListener.isConnectionInitialized(); } } 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 47f1e1fb6..9821b3f42 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 @@ -21,6 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.ReconnectionManager; import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; @@ -53,6 +54,7 @@ public class XMPPAdapterListener implements Runnable { private ContentValidator contentValidator; private ContentTransformer contentTransformer; private PacketListener packetListener; + private boolean connectionInitialized; private InputEventAdapterListener eventAdapterListener = null; @@ -217,6 +219,11 @@ public class XMPPAdapterListener implements Runnable { } public void createConnection() { + connectionInitialized = true; new Thread(this).start(); } + + public boolean isConnectionInitialized() { + return connectionInitialized; + } } diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFirealarmStartupListener.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFirealarmStartupListener.java index 394a14883..b9075fcf0 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFirealarmStartupListener.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/plugin/impl/util/VirtualFirealarmStartupListener.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.core.ServerStartupObserver; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.VirtualFirealarmManagementDataHolder; import java.io.IOException; @@ -36,7 +37,7 @@ public class VirtualFirealarmStartupListener implements ServerStartupObserver { try { VirtualFireAlarmUtils.setupMqttInputAdapter(); VirtualFireAlarmUtils.setupXmppInputAdapter(); - + VirtualFirealarmManagementDataHolder.getInstance().getInputEventAdapterService().start(); } catch (IOException e) { log.error("Failed to intilaize the virtual firealarm input adapter", e); }