X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Findex.js;h=3f47f1fe0b1806b8088014a59c46a05a01edcd1a;hb=8575f275a73cf6269952d6f243fd21b7e65e951f;hp=3591d11c91546bed3e7c8fcdc845c3563e680bae;hpb=7dde0b73302613be132c41e1f28a42de555dc2b6;p=e-mobility-charging-stations-simulator.git diff --git a/src/index.js b/src/index.js index 3591d11c..3f47f1fe 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,4 @@ const Configuration = require('./utils/Configuration'); -const EventEmitter = require('events'); const Utils = require('./utils/Utils'); const Wrk = require('./charging-station/Worker'); const fs = require('fs'); @@ -9,23 +8,22 @@ class Bootstrap { static async start() { try { logger.info('%s Configuration: %j', Utils.basicFormatLog(), Configuration.getConfig()); - if (Configuration.useWorkerPool && Configuration.getWorkerPoolSize() > 10) { - EventEmitter.defaultMaxListeners = Configuration.getWorkerPoolSize() + 1; - } // Start each ChargingStation object in a worker thread if (Configuration.getChargingStationTemplateURLs()) { + let numStationsTotal = 0; Configuration.getChargingStationTemplateURLs().forEach((stationURL) => { try { - // load file + // Load file const fileDescriptor = fs.openSync(stationURL.file, 'r'); const stationTemplate = JSON.parse(fs.readFileSync(fileDescriptor, 'utf8')); fs.closeSync(fileDescriptor); const nbStation = (stationURL.numberOfStation ? stationURL.numberOfStation : 0); + numStationsTotal += nbStation; for (let index = 1; index <= nbStation; index++) { const worker = new Wrk('./src/charging-station/StationWorker.js', { index, template: JSON.parse(JSON.stringify(stationTemplate)), - }); + }, numStationsTotal); worker.start(); } } catch (error) { @@ -39,7 +37,7 @@ class Bootstrap { const worker = new Wrk('./src/charging-station/StationWorker.js', { index, template: JSON.parse(JSON.stringify(Configuration.getChargingStationTemplate())), - }); + }, nbStation); worker.start(); } }