public MQTTInbound(MqttClient connection, String sitewhereTopic, String commandTopic, IAgentCommandProcessor processor, ISiteWhereEventDispatcher dispatcher) { this.connection = connection; this.sitewhereTopic = sitewhereTopic; this.commandTopic = commandTopic; this.processor = processor; this.dispatcher = dispatcher; }
/** * Create an instance of the command processor. FOs * @return * * @throws SiteWhereAgentException */ protected IAgentCommandProcessor createProcessor() { try { var classname = getCommandProcessorClassname(); IAgentCommandProcessor processor = (IAgentCommandProcessor)System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(classname); processor.processProto = ProcessProtocolEnum.ProtoBuf; return(processor); } catch (Exception e) { throw new SiteWhereAgentException(e); } }
/** * Start the agent. */ public void start(IAgentCommandProcessor processor) { LOGGER.info("SiteWhere agent starting..."); this.mqtt = new MqttClient(getMqttHostname(), getMqttPort(), false, null, null, MqttSslProtocols.None); mqtt.MqttMsgPublishReceived += Mqtt_MqttMsgPublishReceived; LOGGER.info("Connecting to MQTT broker at '" + getMqttHostname() + ":" + getMqttPort() + "'..."); try { mqtt.Connect(hardwareId); } catch (Exception e) { throw new SiteWhereAgentException("Unable to establish MQTT connection.", e); } LOGGER.info("Connected to MQTT broker."); // Create outbound message processor. outbound = new MQTTOutbound(mqtt, getOutboundSiteWhereTopic()); // Create an instance of the command processor. if (processor == null) { processor = createProcessor(); } _processor = processor; processor.setHardwareId(hardwareId); processor.setSpecificationToken(specificationToken); processor.setEventDispatcher(outbound); // Create inbound message processing thread. //inboundThread = new Thread(new ParameterizedThreadStart(RunInbound)); //inboundThread.Start(processor); // Executes any custom startup logic. processor.executeStartupLogic(getHardwareId(), getSpecificationToken(), outbound); LOGGER.info("SiteWhere agent started."); }
public void setProcessor(IAgentCommandProcessor processor) { this.processor = processor; }