Configured a check for configs before starting XMPP or MQTT

Shabirmean 9 years ago
parent a392dd799b
commit d2afed15f0

@ -37,6 +37,7 @@ import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
import org.wso2.carbon.device.mgt.iot.arduino.service.dto.DeviceJSON;
import org.wso2.carbon.device.mgt.iot.arduino.service.transport.ArduinoMQTTSubscriber;
import org.wso2.carbon.device.mgt.iot.arduino.service.util.ArduinoServiceUtils;
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.exception.AccessTokenException;
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
@ -99,6 +100,7 @@ public class ArduinoService {
final ArduinoMQTTSubscriber arduinoMQTTSubscriber) {
this.arduinoMQTTSubscriber = arduinoMQTTSubscriber;
if (MqttConfig.getInstance().isEnabled()) {
Runnable xmppStarter = new Runnable() {
@Override
public void run() {
@ -110,6 +112,9 @@ public class ArduinoService {
Thread xmppStarterThread = new Thread(xmppStarter);
xmppStarterThread.setDaemon(true);
xmppStarterThread.start();
} else {
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, ArduinoMQTTSubscriber not started.");
}
}
/**

@ -24,6 +24,7 @@ import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.device.DeviceType;
import org.wso2.carbon.apimgt.annotations.device.feature.Feature;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.exception.DigitalDisplayException;
import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.transport.CommunicationHandlerException;
import org.wso2.carbon.device.mgt.iot.digitaldisplay.api.util.DigitalDisplayMqttCommunicationHandler;
@ -54,9 +55,12 @@ public class DigitalDisplayControllerService {
public void setDigitalDisplayMqttCommunicationHandler(
DigitalDisplayMqttCommunicationHandler digitalDisplayMqttCommunicationHandler) {
DigitalDisplayControllerService.digitalDisplayMqttCommunicationHandler = digitalDisplayMqttCommunicationHandler;
if (MqttConfig.getInstance().isEnabled()) {
digitalDisplayMqttCommunicationHandler.connect();
} else {
log.warn("MQTT disabled in 'devicemgt-config.xml'. " +
"Hence, DigitalDisplayMqttCommunicationHandler not started.");
}
}
/**

@ -15,10 +15,6 @@ import java.util.UUID;
import java.util.concurrent.ScheduledFuture;
/**
* Created by nuwan on 11/16/15.
*/
public class DigitalDisplayMqttCommunicationHandler extends MQTTCommunicationHandler {
private static Log log = LogFactory.getLog(DigitalDisplayMqttCommunicationHandler.class);

@ -19,6 +19,8 @@ package org.wso2.carbon.device.mgt.iot.droneanalyzer.service;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.transport.DroneAnalyzerXMPPConnector;
import org.wso2.carbon.device.mgt.iot.droneanalyzer.service.trasformer.MessageTransformer;
@ -37,7 +39,12 @@ public class DroneRealTimeService {
public DroneRealTimeService() {
messageController = new MessageTransformer();
xmppConnector = new DroneAnalyzerXMPPConnector(messageController);
if (XmppConfig.getInstance().isEnabled()){
xmppConnector.connectLoginAndSetFilterOnReceiver();
} else {
log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started.");
}
}

@ -32,6 +32,7 @@ import org.wso2.carbon.device.mgt.iot.DeviceManagement;
import org.wso2.carbon.device.mgt.iot.DeviceValidator;
import org.wso2.carbon.device.mgt.iot.apimgt.AccessTokenInfo;
import org.wso2.carbon.device.mgt.iot.apimgt.TokenClient;
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient;
@ -96,6 +97,7 @@ public class RaspberryPiService {
final RaspberryPiMQTTSubscriber raspberryPiMQTTSubscriber) {
this.raspberryPiMQTTSubscriber = raspberryPiMQTTSubscriber;
if (MqttConfig.getInstance().isEnabled()) {
Runnable xmppStarter = new Runnable() {
@Override
public void run() {
@ -107,6 +109,9 @@ public class RaspberryPiService {
Thread xmppStarterThread = new Thread(xmppStarter);
xmppStarterThread.setDaemon(true);
xmppStarterThread.start();
} else {
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started.");
}
}
/**

@ -36,6 +36,7 @@ import org.wso2.carbon.device.mgt.iot.DeviceManagement;
import org.wso2.carbon.device.mgt.iot.DeviceValidator;
import org.wso2.carbon.device.mgt.iot.apimgt.AccessTokenInfo;
import org.wso2.carbon.device.mgt.iot.apimgt.TokenClient;
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient;
@ -104,9 +105,7 @@ public class VirtualFireAlarmService {
private VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector;
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
/**
*
* @param verificationManager
*/
public void setVerificationManager(
@ -116,13 +115,13 @@ public class VirtualFireAlarmService {
}
/**
*
* @param virtualFireAlarmXMPPConnector
*/
public void setVirtualFireAlarmXMPPConnector(
final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) {
this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector;
if (MqttConfig.getInstance().isEnabled()) {
Runnable mqttStarter = new Runnable() {
@Override
public void run() {
@ -134,30 +133,25 @@ public class VirtualFireAlarmService {
Thread mqttStarterThread = new Thread(mqttStarter);
mqttStarterThread.setDaemon(true);
mqttStarterThread.start();
} else {
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started.");
}
}
/**
*
* @param virtualFireAlarmMQTTConnector
*/
public void setVirtualFireAlarmMQTTConnector(
final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) {
this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector;
// Runnable xmppStarter = new Runnable() {
// @Override
// public void run() {
if (XmppConfig.getInstance().isEnabled()) {
virtualFireAlarmMQTTConnector.connect();
// }
// };
//
// Thread xmppStarterThread = new Thread(xmppStarter);
// xmppStarterThread.setDaemon(true);
// xmppStarterThread.start();
} else {
log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started.");
}
}
/**
*
* @return
*/
public VerificationManager getVerificationManager() {
@ -165,7 +159,6 @@ public class VirtualFireAlarmService {
}
/**
*
* @return
*/
public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() {
@ -173,7 +166,6 @@ public class VirtualFireAlarmService {
}
/**
*
* @return
*/
public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() {
@ -186,7 +178,6 @@ public class VirtualFireAlarmService {
--------------------------------------------------------------------------------------- */
/**
*
* @param deviceId
* @param name
* @param owner
@ -238,7 +229,6 @@ public class VirtualFireAlarmService {
}
/**
*
* @param deviceId
* @param response
*/
@ -267,7 +257,6 @@ public class VirtualFireAlarmService {
}
/**
*
* @param deviceId
* @param name
* @param response
@ -312,7 +301,6 @@ public class VirtualFireAlarmService {
}
/**
*
* @param deviceId
* @return
*/
@ -340,7 +328,6 @@ public class VirtualFireAlarmService {
}
/**
*
* @param username
* @return
*/
@ -377,7 +364,6 @@ public class VirtualFireAlarmService {
}
/**
*
* @param owner
* @param customDeviceName
* @param sketchType
@ -411,7 +397,6 @@ public class VirtualFireAlarmService {
}
/**
*
* @param owner
* @param customDeviceName
* @param sketchType
@ -439,7 +424,6 @@ public class VirtualFireAlarmService {
}
/**
*
* @param owner
* @param customDeviceName
* @param sketchType
@ -507,7 +491,6 @@ public class VirtualFireAlarmService {
}
/**
*
* @return
*/
private static String shortUUID() {
@ -522,7 +505,6 @@ public class VirtualFireAlarmService {
--------------------------------------------------------------------------------------- */
/**
*
* @param owner
* @param deviceId
* @param deviceIP
@ -563,7 +545,6 @@ public class VirtualFireAlarmService {
Called by an external client intended to control the Virtual FireAlarm bulb */
/**
*
* @param owner
* @param deviceId
* @param protocol
@ -648,7 +629,6 @@ public class VirtualFireAlarmService {
/**
*
* @param owner
* @param deviceId
* @param protocol
@ -695,7 +675,8 @@ public class VirtualFireAlarmService {
}
replyMsg = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint,
VirtualFireAlarmConstants.HUMIDITY_CONTEXT,
VirtualFireAlarmConstants
.HUMIDITY_CONTEXT,
false);
break;
@ -727,7 +708,6 @@ public class VirtualFireAlarmService {
/**
*
* @param owner
* @param deviceId
* @param protocol
@ -806,7 +786,6 @@ public class VirtualFireAlarmService {
}
/**
*
* @param dataMsg
* @param response
*/
@ -844,7 +823,6 @@ public class VirtualFireAlarmService {
/**
*
* @param operation
* @param message
* @return
@ -927,7 +905,6 @@ public class VirtualFireAlarmService {
}
/**
*
* @param operation
* @param inputStream
* @return

@ -285,9 +285,10 @@ public abstract class MQTTTransportHandler
*/
@Override
public void connectionLost(Throwable throwable) {
log.warn("Lost Connection for client: " + this.clientId +
" to " + this.mqttBrokerEndPoint + ".\nThis was due to - " +
throwable.getMessage());
if (log.isDebugEnabled()) {
log.warn("Lost Connection for client: " + this.clientId + " to " + this.mqttBrokerEndPoint + "." +
"\nThis was due to - " + throwable.getMessage());
}
Thread reconnectThread = new Thread() {
public void run() {

Loading…
Cancel
Save