Processor class introduced

This commit is contained in:
Wolfgang Hottgenroth
2017-08-09 11:37:22 +02:00
parent 09d7ea8ace
commit 16313c868f
7 changed files with 124 additions and 55 deletions

42
dist/main.js vendored
View File

@ -2,28 +2,22 @@
Object.defineProperty(exports, "__esModule", { value: true });
const log = require("./log");
const mqtt = require("./mqttdispatcher");
class Dispatcher {
constructor() {
this._mqttDispatcher = new mqtt.MqttDispatcher();
this._mqttDispatcher.register('IoT/test', 'print1', (message) => {
log.info("Callback for IoT/test");
log.info(`message is ${message}`);
return `<<${message}>>`;
});
this._mqttDispatcher.register('IoT/test', 'print2', (message) => {
log.info("Callback for IoT/test");
log.info(`message is ${message}`);
return `<<${message}>>`;
});
this._mqttDispatcher.register('IoT/test', 'null1', mqtt.passThrough);
this._mqttDispatcher.register('IoT/test', 'null2', mqtt.passThrough);
}
exec() {
log.info("Dispatcher starting");
this._mqttDispatcher.exec();
log.info("Dispatcher running");
}
}
const dispatcher = new Dispatcher();
dispatcher.exec();
const plugintest1 = require("./plugintest1");
log.info("Dispatcher starting");
exports.dispatcher = new mqtt.MqttDispatcher();
exports.dispatcher.register('IoT/test', 'print1', (message) => {
log.info("Callback for IoT/test");
log.info(`message is ${message}`);
return `<<${message}>>`;
});
exports.dispatcher.register('IoT/test', 'print2', (message) => {
log.info("Callback for IoT/test");
log.info(`message is ${message}`);
return `<<${message}>>`;
});
exports.dispatcher.register('IoT/test', 'null1', mqtt.passThrough);
exports.dispatcher.register('IoT/test', 'null2', mqtt.passThrough);
plugintest1.pluginTest1Start(exports.dispatcher);
exports.dispatcher.exec();
log.info("Dispatcher running");
//# sourceMappingURL=main.js.map

15
dist/plugintest1.js vendored Normal file
View File

@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log = require("./log");
const processor = require("./processor");
var exRoute = new processor.ExProc1('label1');
function pluginTest1Start(dispatcher) {
log.info("starting plugintest1");
dispatcher.register('IoT/test', "plugintest1", (message) => {
log.info(`plugintest1 runs: ${message}`);
exRoute.in(message);
return message;
});
}
exports.pluginTest1Start = pluginTest1Start;
//# sourceMappingURL=plugintest1.js.map

24
dist/processor.js vendored Normal file
View File

@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const log = require("./log");
const events = require("events");
class AProcessor extends events.EventEmitter {
constructor(label) {
super();
this._label = label;
this.addListener('input', this.process);
log.info(`Processor object instanciated: ${this.constructor.name}, ${this._label}`);
}
in(message) {
log.info(`Routing ${message} to Processor class ${this.constructor.name}, ${this._label}`);
this.emit('input', message);
}
}
exports.AProcessor = AProcessor;
class ExProc1 extends AProcessor {
process(message) {
log.info(`ExRoute1.process: ${this._label}, ${message}`);
}
}
exports.ExProc1 = ExProc1;
//# sourceMappingURL=processor.js.map