|
|
|
@ -29,8 +29,6 @@ import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService
|
|
|
|
|
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.controlqueue.xmpp.XmppConfig;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.DeviceData;
|
|
|
|
@ -46,11 +44,19 @@ import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.scep.SC
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.ws.rs.Consumes;
|
|
|
|
|
import javax.ws.rs.FormParam;
|
|
|
|
|
import javax.ws.rs.GET;
|
|
|
|
|
import javax.ws.rs.POST;
|
|
|
|
|
import javax.ws.rs.Path;
|
|
|
|
|
import javax.ws.rs.PathParam;
|
|
|
|
|
import javax.ws.rs.Produces;
|
|
|
|
|
import javax.ws.rs.QueryParam;
|
|
|
|
|
import javax.ws.rs.core.Context;
|
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
@ -77,135 +83,10 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
|
|
|
|
|
// holds a mapping of the IP addresses to Device-IDs for HTTP communication
|
|
|
|
|
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
private boolean waitForServerStartup() {
|
|
|
|
|
while (!IoTServerStartupListener.isServerReady()) {
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetches the `SecurityManager` specific to this VirtualFirealarm controller service.
|
|
|
|
|
*
|
|
|
|
|
* @return the 'SecurityManager' instance bound to the 'securityManager' variable of this service.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("Unused")
|
|
|
|
|
public SecurityManager getSecurityManager() {
|
|
|
|
|
return securityManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the `securityManager` variable of this VirtualFirealarm controller service.
|
|
|
|
|
*
|
|
|
|
|
* @param securityManager a 'SecurityManager' object that handles the encryption, decryption, signing and validation
|
|
|
|
|
* of incoming messages from VirtualFirealarm device-types.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("Unused")
|
|
|
|
|
public void setSecurityManager(SecurityManager securityManager) {
|
|
|
|
|
this.securityManager = securityManager;
|
|
|
|
|
securityManager.initVerificationManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetches the `VirtualFireAlarmXMPPConnector` specific to this VirtualFirealarm controller service.
|
|
|
|
|
*
|
|
|
|
|
* @return the 'VirtualFireAlarmXMPPConnector' instance bound to the 'virtualFireAlarmXMPPConnector' variable of
|
|
|
|
|
* this service.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("Unused")
|
|
|
|
|
public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() {
|
|
|
|
|
return virtualFireAlarmXMPPConnector;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the `virtualFireAlarmXMPPConnector` variable of this VirtualFirealarm controller service.
|
|
|
|
|
*
|
|
|
|
|
* @param virtualFireAlarmXMPPConnector a 'VirtualFireAlarmXMPPConnector' object that handles all XMPP related
|
|
|
|
|
* communications of any connected VirtualFirealarm device-type
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("Unused")
|
|
|
|
|
public void setVirtualFireAlarmXMPPConnector(
|
|
|
|
|
final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) {
|
|
|
|
|
Runnable connector = new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
if (waitForServerStartup()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
VirtualFireAlarmControllerServiceImpl.this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector;
|
|
|
|
|
|
|
|
|
|
if (XmppConfig.getInstance().isEnabled()) {
|
|
|
|
|
Runnable xmppStarter = new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
virtualFireAlarmXMPPConnector.initConnector();
|
|
|
|
|
virtualFireAlarmXMPPConnector.connect();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Thread xmppStarterThread = new Thread(xmppStarter);
|
|
|
|
|
xmppStarterThread.setDaemon(true);
|
|
|
|
|
xmppStarterThread.start();
|
|
|
|
|
} else {
|
|
|
|
|
log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Thread connectorThread = new Thread(connector);
|
|
|
|
|
connectorThread.setDaemon(true);
|
|
|
|
|
connectorThread.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetches the `VirtualFireAlarmMQTTConnector` specific to this VirtualFirealarm controller service.
|
|
|
|
|
*
|
|
|
|
|
* @return the 'VirtualFireAlarmMQTTConnector' instance bound to the 'virtualFireAlarmMQTTConnector' variable of
|
|
|
|
|
* this service.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("Unused")
|
|
|
|
|
public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() {
|
|
|
|
|
return virtualFireAlarmMQTTConnector;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the `virtualFireAlarmMQTTConnector` variable of this VirtualFirealarm controller service.
|
|
|
|
|
*
|
|
|
|
|
* @param virtualFireAlarmMQTTConnector a 'VirtualFireAlarmMQTTConnector' object that handles all MQTT related
|
|
|
|
|
* communications of any connected VirtualFirealarm device-type
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("Unused")
|
|
|
|
|
public void setVirtualFireAlarmMQTTConnector(
|
|
|
|
|
final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) {
|
|
|
|
|
Runnable connector = new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
if (waitForServerStartup()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
VirtualFireAlarmControllerServiceImpl.this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector;
|
|
|
|
|
//The delay is added for the server starts up.
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(5000);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
|
}
|
|
|
|
|
if (MqttConfig.getInstance().isEnabled()) {
|
|
|
|
|
synchronized (virtualFireAlarmMQTTConnector) {
|
|
|
|
|
virtualFireAlarmMQTTConnector.connect();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Thread connectorThread = new Thread(connector);
|
|
|
|
|
connectorThread.setDaemon(true);
|
|
|
|
|
connectorThread.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort, HttpServletRequest request) {
|
|
|
|
|
@POST
|
|
|
|
|
@Path("device/register/{deviceId}/{ip}/{port}")
|
|
|
|
|
public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
|
|
|
|
|
@PathParam("port") String devicePort, @Context HttpServletRequest request) {
|
|
|
|
|
String result;
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId);
|
|
|
|
@ -219,7 +100,10 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
|
|
|
|
|
return Response.ok().entity(result).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Response switchBuzzer(String deviceId, String protocol, String state) {
|
|
|
|
|
@POST
|
|
|
|
|
@Path("device/{deviceId}/buzz")
|
|
|
|
|
public Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
|
|
|
|
@FormParam("state") String state) {
|
|
|
|
|
String switchToState = state.toUpperCase();
|
|
|
|
|
if (!switchToState.equals(VirtualFireAlarmConstants.STATE_ON) && !switchToState.equals(
|
|
|
|
|
VirtualFireAlarmConstants.STATE_OFF)) {
|
|
|
|
@ -257,43 +141,9 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Response requestTemperature(String deviceId, String protocol) {
|
|
|
|
|
org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord sensorRecord = null;
|
|
|
|
|
String protocolString = protocol.toUpperCase();
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Sending request to read virtual-firealarm-temperature of device " +
|
|
|
|
|
"[" + deviceId + "] via " + protocolString);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
switch (protocolString) {
|
|
|
|
|
case HTTP_PROTOCOL:
|
|
|
|
|
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
|
|
|
|
|
if (deviceHTTPEndpoint == null) {
|
|
|
|
|
return Response.status(Response.Status.PRECONDITION_FAILED).build();
|
|
|
|
|
}
|
|
|
|
|
String temperatureValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(
|
|
|
|
|
deviceHTTPEndpoint, VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, false);
|
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP,
|
|
|
|
|
temperatureValue,
|
|
|
|
|
Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
break;
|
|
|
|
|
case XMPP_PROTOCOL:
|
|
|
|
|
String xmppResource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", "");
|
|
|
|
|
virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, xmppResource, "");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
String mqttResource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", "");
|
|
|
|
|
virtualFireAlarmMQTTConnector.publishDeviceData(deviceId, mqttResource, "");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, VirtualFireAlarmConstants
|
|
|
|
|
.SENSOR_TEMP);
|
|
|
|
|
return Response.ok().entity(sensorRecord).build();
|
|
|
|
|
} catch (DeviceManagementException | DeviceControllerException | TransportHandlerException e) {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|
@Path("device/temperature")
|
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
|
public Response pushTemperatureData(final DeviceData dataMsg) {
|
|
|
|
|
String deviceId = dataMsg.deviceId;
|
|
|
|
|
String deviceIp = dataMsg.reply;
|
|
|
|
@ -308,16 +158,15 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
|
|
|
|
|
" is already registered under some other IP. Re-registration required");
|
|
|
|
|
return Response.status(Response.Status.CONFLICT).build();
|
|
|
|
|
}
|
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP,
|
|
|
|
|
String.valueOf(temperature),
|
|
|
|
|
Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
if (!VirtualFireAlarmServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
return Response.ok().build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Response scepRequest(String operation, String message) {
|
|
|
|
|
@GET
|
|
|
|
|
@Path("device/scep")
|
|
|
|
|
public Response scepRequest(@QueryParam("operation") String operation, @QueryParam("message") String message) {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Invoking SCEP operation " + operation);
|
|
|
|
|
}
|
|
|
|
@ -367,7 +216,6 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Invoking GetCACaps");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils.
|
|
|
|
|
getCertificateManagementService();
|
|
|
|
@ -378,16 +226,15 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
|
|
|
|
|
} catch (VirtualFireAlarmException e) {
|
|
|
|
|
log.error("Error occurred while enrolling the device", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
log.error("Invalid SCEP operation " + operation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Response.serverError().build();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Response scepRequestPost(String operation, InputStream inputStream) {
|
|
|
|
|
@POST
|
|
|
|
|
@Path("device/scep")
|
|
|
|
|
public Response scepRequestPost(@QueryParam("operation") String operation, InputStream inputStream) {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Invoking SCEP operation " + operation);
|
|
|
|
|
}
|
|
|
|
@ -409,7 +256,14 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
|
|
|
|
|
return Response.serverError().build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Response getVirtualFirealarmStats(String deviceId, String sensor, String user, long from, long to) {
|
|
|
|
|
@Path("device/stats/{deviceId}/sensors/{sensorName}")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public Response getVirtualFirealarmStats(@PathParam("deviceId") String deviceId,
|
|
|
|
|
@PathParam("sensorName") String sensor,
|
|
|
|
|
@QueryParam("username") String user, @QueryParam("from") long from,
|
|
|
|
|
@QueryParam("to") long to) {
|
|
|
|
|
String fromDate = String.valueOf(from);
|
|
|
|
|
String toDate = String.valueOf(to);
|
|
|
|
|
String query = "owner:" + user + " AND deviceId:" + deviceId + " AND deviceType:" +
|
|
|
|
@ -431,6 +285,126 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean waitForServerStartup() {
|
|
|
|
|
while (!IoTServerStartupListener.isServerReady()) {
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetches the `SecurityManager` specific to this VirtualFirealarm controller service.
|
|
|
|
|
*
|
|
|
|
|
* @return the 'SecurityManager' instance bound to the 'securityManager' variable of this service.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("Unused")
|
|
|
|
|
public SecurityManager getSecurityManager() {
|
|
|
|
|
return securityManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the `securityManager` variable of this VirtualFirealarm controller service.
|
|
|
|
|
*
|
|
|
|
|
* @param securityManager a 'SecurityManager' object that handles the encryption, decryption, signing and validation
|
|
|
|
|
* of incoming messages from VirtualFirealarm device-types.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("Unused")
|
|
|
|
|
public void setSecurityManager(SecurityManager securityManager) {
|
|
|
|
|
this.securityManager = securityManager;
|
|
|
|
|
securityManager.initVerificationManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetches the `VirtualFireAlarmXMPPConnector` specific to this VirtualFirealarm controller service.
|
|
|
|
|
*
|
|
|
|
|
* @return the 'VirtualFireAlarmXMPPConnector' instance bound to the 'virtualFireAlarmXMPPConnector' variable of
|
|
|
|
|
* this service.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("Unused")
|
|
|
|
|
public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() {
|
|
|
|
|
return virtualFireAlarmXMPPConnector;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the `virtualFireAlarmXMPPConnector` variable of this VirtualFirealarm controller service.
|
|
|
|
|
*
|
|
|
|
|
* @param virtualFireAlarmXMPPConnector a 'VirtualFireAlarmXMPPConnector' object that handles all XMPP related
|
|
|
|
|
* communications of any connected VirtualFirealarm device-type
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("Unused")
|
|
|
|
|
public void setVirtualFireAlarmXMPPConnector(
|
|
|
|
|
final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) {
|
|
|
|
|
Runnable connector = new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
if (waitForServerStartup()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
VirtualFireAlarmControllerServiceImpl.this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector;
|
|
|
|
|
|
|
|
|
|
if (XmppConfig.getInstance().isEnabled()) {
|
|
|
|
|
Runnable xmppStarter = new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
virtualFireAlarmXMPPConnector.initConnector();
|
|
|
|
|
virtualFireAlarmXMPPConnector.connect();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Thread xmppStarterThread = new Thread(xmppStarter);
|
|
|
|
|
xmppStarterThread.setDaemon(true);
|
|
|
|
|
xmppStarterThread.start();
|
|
|
|
|
} else {
|
|
|
|
|
log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Thread connectorThread = new Thread(connector);
|
|
|
|
|
connectorThread.setDaemon(true);
|
|
|
|
|
connectorThread.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetches the `VirtualFireAlarmMQTTConnector` specific to this VirtualFirealarm controller service.
|
|
|
|
|
*
|
|
|
|
|
* @return the 'VirtualFireAlarmMQTTConnector' instance bound to the 'virtualFireAlarmMQTTConnector' variable of
|
|
|
|
|
* this service.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("Unused")
|
|
|
|
|
public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() {
|
|
|
|
|
return virtualFireAlarmMQTTConnector;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the `virtualFireAlarmMQTTConnector` variable of this VirtualFirealarm controller service.
|
|
|
|
|
*
|
|
|
|
|
* @param virtualFireAlarmMQTTConnector a 'VirtualFireAlarmMQTTConnector' object that handles all MQTT related
|
|
|
|
|
* communications of any connected VirtualFirealarm device-type
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("Unused")
|
|
|
|
|
public void setVirtualFireAlarmMQTTConnector(
|
|
|
|
|
final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) {
|
|
|
|
|
Runnable connector = new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
if (waitForServerStartup()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
VirtualFireAlarmControllerServiceImpl.this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector;
|
|
|
|
|
if (MqttConfig.getInstance().isEnabled()) {
|
|
|
|
|
virtualFireAlarmMQTTConnector.connect();
|
|
|
|
|
} else {
|
|
|
|
|
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Thread connectorThread = new Thread(connector);
|
|
|
|
|
connectorThread.setDaemon(true);
|
|
|
|
|
connectorThread.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get the event table from the sensor name.
|
|
|
|
|
*/
|
|
|
|
|