diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java
index f4eccbb54f..5fb6883c82 100644
--- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java
+++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java
@@ -31,107 +31,115 @@ import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireA
import java.util.Calendar;
public class VirtualFireAlarmXMPPConnector extends XmppConnector {
- private static Log log = LogFactory.getLog(VirtualFireAlarmXMPPConnector.class);
-
- private static String xmppServerIP;
- // private static int xmppServerPort;
- private static String xmppAdminUsername;
- private static String xmppAdminPassword;
- private static String xmppAdminAccountJID;
-
- private VirtualFireAlarmXMPPConnector() {
- super(XmppConfig.getInstance().getXmppServerIP(),
- XmppConfig.getInstance().getSERVER_CONNECTION_PORT());
- }
-
- public void initConnector() {
- xmppServerIP = XmppConfig.getInstance().getXmppServerIP();
- xmppAdminUsername = XmppConfig.getInstance().getXmppUsername();
- xmppAdminPassword = XmppConfig.getInstance().getXmppPassword();
- xmppAdminAccountJID = xmppAdminUsername + "@" + xmppServerIP;
- }
-
- public void connectAndLogin() {
- try {
- super.connectAndLogin(xmppAdminUsername, xmppAdminPassword, null);
- super.setMessageFilterOnReceiver(xmppAdminAccountJID);
- } catch (DeviceManagementException e) {
- log.error("Connect/Login attempt to XMPP Server at: " + xmppServerIP + " failed");
- retryXMPPConnection();
- }
- }
-
- @Override
- protected void processXMPPMessage(Message xmppMessage) {
- String from = xmppMessage.getFrom();
- String subject = xmppMessage.getSubject();
- String message = xmppMessage.getBody();
-
- int indexOfAt = from.indexOf("@");
- int indexOfSlash = from.indexOf("/");
-
- String deviceId = from.substring(0, indexOfAt);
- String owner = from.substring(indexOfSlash + 1, from.length());
-
- log.info("Received XMPP message for: {OWNER-" + owner + "} & {DEVICE.ID-" + deviceId + "}");
-
- if (subject.equals("PUBLISHER")) {
- log.info("XMPP: Publisher Message [" + message + "] from [" + from + "]");
-
- float temperature = Float.parseFloat(message.split(":")[1]);
- if(!VirtualFireAlarmServiceUtils.publishToDAS(owner, deviceId, temperature)) {
- log.error("XMPP Connector: Publishing data to DAS failed.");
- }
-
- if(log.isDebugEnabled()) {
- log.debug("XMPP Connector: Published data to DAS successfully.");
- }
- } else if(subject.equals("CONTROL-REPLY")) {
- log.info("XMPP: Reply Message [" + message + "] from [" + from + "]");
- String temperature = message.split(":")[1];
- SensorDataManager.getInstance().setSensorRecord(deviceId,VirtualFireAlarmConstants.SENSOR_TEMPERATURE, temperature, Calendar.getInstance().getTimeInMillis());
- } else {
- log.info("SOME XMPP Message [" + message + "] from " + from + "]");
- }
-
- }
-
- private void retryXMPPConnection() {
- Thread retryToConnect = new Thread() {
- @Override
- public void run() {
-
- while (true) {
- if (!isConnected()) {
- if (log.isDebugEnabled()) {
- log.debug("Re-trying to reach XMPP Server....");
- }
-
- try {
- VirtualFireAlarmXMPPConnector.super.connectAndLogin(xmppAdminUsername,
- xmppAdminPassword,
- null);
- VirtualFireAlarmXMPPConnector.super.setMessageFilterOnReceiver(
- xmppAdminAccountJID);
- } catch (DeviceManagementException e1) {
- if (log.isDebugEnabled()) {
- log.debug("Attempt to re-connect to XMPP-Server failed");
- }
- }
- } else {
- break;
- }
-
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e1) {
- log.error("XMPP: Thread Sleep Interrupt Exception");
- }
- }
- }
- };
-
- retryToConnect.setDaemon(true);
- retryToConnect.start();
- }
+ private static Log log = LogFactory.getLog(VirtualFireAlarmXMPPConnector.class);
+
+ private static String xmppServerIP;
+ // private static int xmppServerPort;
+ private static String xmppAdminUsername;
+ private static String xmppAdminPassword;
+ private static String xmppAdminAccountJID;
+
+ private VirtualFireAlarmXMPPConnector() {
+ super(XmppConfig.getInstance().getXmppServerIP(),
+ XmppConfig.getInstance().getSERVER_CONNECTION_PORT());
+ }
+
+ public void initConnector() {
+ xmppServerIP = XmppConfig.getInstance().getXmppServerIP();
+ xmppAdminUsername = XmppConfig.getInstance().getXmppUsername();
+ xmppAdminPassword = XmppConfig.getInstance().getXmppPassword();
+ xmppAdminAccountJID = xmppAdminUsername + "@" + xmppServerIP;
+ }
+
+ public void connectAndLogin() {
+ try {
+ super.connectAndLogin(xmppAdminUsername, xmppAdminPassword, null);
+ super.setMessageFilterOnReceiver(xmppAdminAccountJID);
+ } catch (DeviceManagementException e) {
+ log.error("Connect/Login attempt to XMPP Server at: " + xmppServerIP + " failed");
+ retryXMPPConnection();
+ }
+ }
+
+ @Override
+ protected void processXMPPMessage(Message xmppMessage) {
+ String from = xmppMessage.getFrom();
+ String subject = xmppMessage.getSubject();
+ String message = xmppMessage.getBody();
+
+ int indexOfAt = from.indexOf("@");
+ int indexOfSlash = from.indexOf("/");
+
+ String deviceId = from.substring(0, indexOfAt);
+ String owner = from.substring(indexOfSlash + 1, from.length());
+
+ log.info("Received XMPP message for: {OWNER-" + owner + "} & {DEVICE.ID-" + deviceId + "}");
+
+ if (subject != null) {
+ switch (subject) {
+ case "PUBLISHER":
+ float temperature = Float.parseFloat(message.split(":")[1]);
+ if (!VirtualFireAlarmServiceUtils.publishToDAS(owner, deviceId, temperature)) {
+ log.error("XMPP Connector: Publishing data to DAS failed.");
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("XMPP: Publisher Message [" + message + "] from [" + from + "]");
+ log.debug("XMPP Connector: Published data to DAS successfully.");
+ }
+ break;
+ case "CONTROL-REPLY":
+ if (log.isDebugEnabled()) {
+ log.debug("XMPP: Reply Message [" + message + "] from [" + from + "]");
+ }
+ String tempVal = message.split(":")[1];
+ SensorDataManager.getInstance().setSensorRecord(deviceId,
+ VirtualFireAlarmConstants.SENSOR_TEMPERATURE,
+ tempVal, Calendar.getInstance().getTimeInMillis());
+ break;
+ default:
+ log.info("Unknown XMPP Message [" + message + "] from [" + from + "] received");
+ break;
+ }
+ }
+ }
+
+ private void retryXMPPConnection() {
+ Thread retryToConnect = new Thread() {
+ @Override
+ public void run() {
+
+ while (true) {
+ if (!isConnected()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Re-trying to reach XMPP Server....");
+ }
+
+ try {
+ VirtualFireAlarmXMPPConnector.super.connectAndLogin(xmppAdminUsername,
+ xmppAdminPassword,
+ null);
+ VirtualFireAlarmXMPPConnector.super.setMessageFilterOnReceiver(
+ xmppAdminAccountJID);
+ } catch (DeviceManagementException e1) {
+ if (log.isDebugEnabled()) {
+ log.debug("Attempt to re-connect to XMPP-Server failed");
+ }
+ }
+ } else {
+ break;
+ }
+
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e1) {
+ log.error("XMPP: Thread Sleep Interrupt Exception");
+ }
+ }
+ }
+ };
+
+ retryToConnect.setDaemon(true);
+ retryToConnect.start();
+ }
}
diff --git a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/configs/virtual_firealarm.xml b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/configs/virtual_firealarm.xml
index f997831fe4..341eac74df 100644
--- a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/configs/virtual_firealarm.xml
+++ b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/configs/virtual_firealarm.xml
@@ -18,6 +18,8 @@
-->
-
-
+
+ jdbc/VirtualFireAlarmDM_DB
+
+
diff --git a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/datasources/virtual_firealarm-datasources.xml b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/datasources/virtual_firealarm-datasources.xml
new file mode 100644
index 0000000000..a724d94d1f
--- /dev/null
+++ b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/datasources/virtual_firealarm-datasources.xml
@@ -0,0 +1,48 @@
+
+
+
+
+ org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader
+
+
+
+
+ VirtualFireAlarmDM_DB
+ The datasource used for the Virtual-Firealarm database
+
+ jdbc/VirtualFireAlarmDM_DB
+
+
+
+ jdbc:h2:repository/database/VirtualFireAlarmDM_DB;DB_CLOSE_ON_EXIT=FALSE
+
+ wso2carbon
+ wso2carbon
+ org.h2.Driver
+ 50
+ 60000
+ true
+ SELECT 1
+ 30000
+
+
+
+
+
+
diff --git a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/p2.inf b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/p2.inf
index 6dc2bfa939..877c812342 100644
--- a/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/p2.inf
+++ b/features/device-mgt-iot-virtualfirealarm-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/p2.inf
@@ -13,3 +13,5 @@ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../featur
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/dbscripts/,target:${installFolder}/../../../dbscripts/cdm/plugins/virtual_firealarm,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/jaggeryapps/);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/jaggeryapps/,target:${installFolder}/../../deployment/server/jaggeryapps/,overwrite:true);\
+org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../conf/datasources/devicemgt/);\
+org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/datasources/,target:${installFolder}/../../conf/datasources/devicemgt,overwrite:true);\