Merge branch 'IoTS-1.0.0-M1' of https://github.com/wso2/carbon-device-mgt-plugins into IoTS-1.0.0-M1

charithag 9 years ago
commit 88cab6ef53

@ -31,107 +31,115 @@ import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireA
import java.util.Calendar; import java.util.Calendar;
public class VirtualFireAlarmXMPPConnector extends XmppConnector { public class VirtualFireAlarmXMPPConnector extends XmppConnector {
private static Log log = LogFactory.getLog(VirtualFireAlarmXMPPConnector.class); private static Log log = LogFactory.getLog(VirtualFireAlarmXMPPConnector.class);
private static String xmppServerIP; private static String xmppServerIP;
// private static int xmppServerPort; // private static int xmppServerPort;
private static String xmppAdminUsername; private static String xmppAdminUsername;
private static String xmppAdminPassword; private static String xmppAdminPassword;
private static String xmppAdminAccountJID; private static String xmppAdminAccountJID;
private VirtualFireAlarmXMPPConnector() { private VirtualFireAlarmXMPPConnector() {
super(XmppConfig.getInstance().getXmppServerIP(), super(XmppConfig.getInstance().getXmppServerIP(),
XmppConfig.getInstance().getSERVER_CONNECTION_PORT()); XmppConfig.getInstance().getSERVER_CONNECTION_PORT());
} }
public void initConnector() { public void initConnector() {
xmppServerIP = XmppConfig.getInstance().getXmppServerIP(); xmppServerIP = XmppConfig.getInstance().getXmppServerIP();
xmppAdminUsername = XmppConfig.getInstance().getXmppUsername(); xmppAdminUsername = XmppConfig.getInstance().getXmppUsername();
xmppAdminPassword = XmppConfig.getInstance().getXmppPassword(); xmppAdminPassword = XmppConfig.getInstance().getXmppPassword();
xmppAdminAccountJID = xmppAdminUsername + "@" + xmppServerIP; xmppAdminAccountJID = xmppAdminUsername + "@" + xmppServerIP;
} }
public void connectAndLogin() { public void connectAndLogin() {
try { try {
super.connectAndLogin(xmppAdminUsername, xmppAdminPassword, null); super.connectAndLogin(xmppAdminUsername, xmppAdminPassword, null);
super.setMessageFilterOnReceiver(xmppAdminAccountJID); super.setMessageFilterOnReceiver(xmppAdminAccountJID);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Connect/Login attempt to XMPP Server at: " + xmppServerIP + " failed"); log.error("Connect/Login attempt to XMPP Server at: " + xmppServerIP + " failed");
retryXMPPConnection(); retryXMPPConnection();
} }
} }
@Override @Override
protected void processXMPPMessage(Message xmppMessage) { protected void processXMPPMessage(Message xmppMessage) {
String from = xmppMessage.getFrom(); String from = xmppMessage.getFrom();
String subject = xmppMessage.getSubject(); String subject = xmppMessage.getSubject();
String message = xmppMessage.getBody(); String message = xmppMessage.getBody();
int indexOfAt = from.indexOf("@"); int indexOfAt = from.indexOf("@");
int indexOfSlash = from.indexOf("/"); int indexOfSlash = from.indexOf("/");
String deviceId = from.substring(0, indexOfAt); String deviceId = from.substring(0, indexOfAt);
String owner = from.substring(indexOfSlash + 1, from.length()); String owner = from.substring(indexOfSlash + 1, from.length());
log.info("Received XMPP message for: {OWNER-" + owner + "} & {DEVICE.ID-" + deviceId + "}"); log.info("Received XMPP message for: {OWNER-" + owner + "} & {DEVICE.ID-" + deviceId + "}");
if (subject.equals("PUBLISHER")) { if (subject != null) {
log.info("XMPP: Publisher Message [" + message + "] from [" + from + "]"); switch (subject) {
case "PUBLISHER":
float temperature = Float.parseFloat(message.split(":")[1]); float temperature = Float.parseFloat(message.split(":")[1]);
if(!VirtualFireAlarmServiceUtils.publishToDAS(owner, deviceId, temperature)) { if (!VirtualFireAlarmServiceUtils.publishToDAS(owner, deviceId, temperature)) {
log.error("XMPP Connector: Publishing data to DAS failed."); log.error("XMPP Connector: Publishing data to DAS failed.");
} }
if(log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("XMPP Connector: Published data to DAS successfully."); log.debug("XMPP: Publisher Message [" + message + "] from [" + from + "]");
} log.debug("XMPP Connector: Published data to DAS successfully.");
} else if(subject.equals("CONTROL-REPLY")) { }
log.info("XMPP: Reply Message [" + message + "] from [" + from + "]"); break;
String temperature = message.split(":")[1]; case "CONTROL-REPLY":
SensorDataManager.getInstance().setSensorRecord(deviceId,VirtualFireAlarmConstants.SENSOR_TEMPERATURE, temperature, Calendar.getInstance().getTimeInMillis()); if (log.isDebugEnabled()) {
} else { log.debug("XMPP: Reply Message [" + message + "] from [" + from + "]");
log.info("SOME XMPP Message [" + message + "] from " + from + "]"); }
} String tempVal = message.split(":")[1];
SensorDataManager.getInstance().setSensorRecord(deviceId,
} VirtualFireAlarmConstants.SENSOR_TEMPERATURE,
tempVal, Calendar.getInstance().getTimeInMillis());
private void retryXMPPConnection() { break;
Thread retryToConnect = new Thread() { default:
@Override log.info("Unknown XMPP Message [" + message + "] from [" + from + "] received");
public void run() { break;
}
while (true) { }
if (!isConnected()) { }
if (log.isDebugEnabled()) {
log.debug("Re-trying to reach XMPP Server...."); private void retryXMPPConnection() {
} Thread retryToConnect = new Thread() {
@Override
try { public void run() {
VirtualFireAlarmXMPPConnector.super.connectAndLogin(xmppAdminUsername,
xmppAdminPassword, while (true) {
null); if (!isConnected()) {
VirtualFireAlarmXMPPConnector.super.setMessageFilterOnReceiver( if (log.isDebugEnabled()) {
xmppAdminAccountJID); log.debug("Re-trying to reach XMPP Server....");
} catch (DeviceManagementException e1) { }
if (log.isDebugEnabled()) {
log.debug("Attempt to re-connect to XMPP-Server failed"); try {
} VirtualFireAlarmXMPPConnector.super.connectAndLogin(xmppAdminUsername,
} xmppAdminPassword,
} else { null);
break; VirtualFireAlarmXMPPConnector.super.setMessageFilterOnReceiver(
} xmppAdminAccountJID);
} catch (DeviceManagementException e1) {
try { if (log.isDebugEnabled()) {
Thread.sleep(5000); log.debug("Attempt to re-connect to XMPP-Server failed");
} catch (InterruptedException e1) { }
log.error("XMPP: Thread Sleep Interrupt Exception"); }
} } else {
} break;
} }
};
try {
retryToConnect.setDaemon(true); Thread.sleep(5000);
retryToConnect.start(); } catch (InterruptedException e1) {
} log.error("XMPP: Thread Sleep Interrupt Exception");
}
}
}
};
retryToConnect.setDaemon(true);
retryToConnect.start();
}
} }

@ -18,6 +18,8 @@
--> -->
<DeviceTypeConfigurations> <DeviceTypeConfigurations>
<DeviceTypeConfig type="virtual_firealarm">
<DatasourceName>jdbc/VirtualFireAlarmDM_DB</DatasourceName>
<!--ApiApplicationName>firealarm</ApiApplicationName-->
</DeviceTypeConfig>
</DeviceTypeConfigurations> </DeviceTypeConfigurations>

@ -0,0 +1,48 @@
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<datasources-configuration xmlns:svns="http://org.wso2.securevault/configuration">
<providers>
<provider>org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader</provider>
</providers>
<datasources>
<datasource>
<name>VirtualFireAlarmDM_DB</name>
<description>The datasource used for the Virtual-Firealarm database</description>
<jndiConfig>
<name>jdbc/VirtualFireAlarmDM_DB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:h2:repository/database/VirtualFireAlarmDM_DB;DB_CLOSE_ON_EXIT=FALSE
</url>
<username>wso2carbon</username>
<password>wso2carbon</password>
<driverClassName>org.h2.Driver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1</validationQuery>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
</datasources>
</datasources-configuration>

@ -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.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.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.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);\

Loading…
Cancel
Save