X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FBootstrap.ts;h=eb437ab08cf5e6e81baa1e8bf69499133200e456;hb=9c5d9fa4cd1904b5e2d4c4a8277bed25865b61b6;hp=5ed378c7894b99e29b754a2c0a98e24dec7d4dda;hpb=452a82cadd0f08148f5f3d5e5b78fa6cac9da0a7;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 5ed378c7..eb437ab0 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -26,7 +26,6 @@ import type WorkerAbstract from '../worker/WorkerAbstract'; import WorkerFactory from '../worker/WorkerFactory'; import { ChargingStationUtils } from './ChargingStationUtils'; import type { AbstractUIServer } from './ui-server/AbstractUIServer'; -import { UIServiceUtils } from './ui-server/ui-services/UIServiceUtils'; import UIServerFactory from './ui-server/UIServerFactory'; const moduleName = 'Bootstrap'; @@ -36,7 +35,7 @@ const noChargingStationTemplatesExitCode = 2; export class Bootstrap { private static instance: Bootstrap | null = null; - private workerImplementation: WorkerAbstract | null = null; + private workerImplementation: WorkerAbstract | null; private readonly uiServer!: AbstractUIServer; private readonly storage!: Storage; private numberOfChargingStationTemplates!: number; @@ -48,18 +47,16 @@ export class Bootstrap { private constructor() { this.started = false; + this.workerImplementation = null; this.workerScript = path.join( path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'), 'charging-station', 'ChargingStationWorker' + path.extname(fileURLToPath(import.meta.url)) ); this.initialize(); - Configuration.getUIServer().enabled && - (this.uiServer = UIServerFactory.getUIServerImplementation(Configuration.getUIServer().type, { - ...Configuration.getUIServer().options, - handleProtocols: UIServiceUtils.handleProtocols, - })); - Configuration.getPerformanceStorage().enabled && + Configuration.getUIServer().enabled === true && + (this.uiServer = UIServerFactory.getUIServerImplementation(Configuration.getUIServer())); + Configuration.getPerformanceStorage().enabled === true && (this.storage = StorageFactory.getStorage( Configuration.getPerformanceStorage().type, Configuration.getPerformanceStorage().uri, @@ -150,10 +147,10 @@ export class Bootstrap { this.workerImplementation = null; this.uiServer?.stop(); await this.storage?.close(); + this.started = false; } else { - console.error(chalk.red('Trying to stop the charging stations simulator while not started')); + console.error(chalk.red('Cannot stop a not started charging stations simulator')); } - this.started = false; } public async restart(): Promise { @@ -163,7 +160,7 @@ export class Bootstrap { } private initializeWorkerImplementation(): void { - !this.workerImplementation && + this.workerImplementation === null && (this.workerImplementation = WorkerFactory.getWorkerImplementation( this.workerScript, Configuration.getWorker().processType, @@ -222,19 +219,19 @@ export class Bootstrap { } } - private workerEventStarted(data: ChargingStationData) { + private workerEventStarted = (data: ChargingStationData) => { this.uiServer?.chargingStations.set(data.stationInfo.hashId, data); ++this.numberOfStartedChargingStations; - } + }; - private workerEventStopped(data: ChargingStationData) { + private workerEventStopped = (data: ChargingStationData) => { this.uiServer?.chargingStations.set(data.stationInfo.hashId, data); --this.numberOfStartedChargingStations; - } + }; - private workerEventUpdated(data: ChargingStationData) { + private workerEventUpdated = (data: ChargingStationData) => { this.uiServer?.chargingStations.set(data.stationInfo.hashId, data); - } + }; private workerEventPerformanceStatistics = (data: Statistics) => { this.storage.storePerformanceStatistics(data) as void;