- public async start(): Promise<void> {
- if (isMainThread && this.started === false) {
- this.initializeCounters();
- this.initializeWorkerImplementation();
- await this.workerImplementation?.start();
- await this.storage?.open();
- this.uiServer?.start();
- // Start ChargingStation object instance in worker thread
- for (const stationTemplateUrl of Configuration.getStationTemplateUrls()) {
- try {
- const nbStations = stationTemplateUrl.numberOfStations ?? 0;
- for (let index = 1; index <= nbStations; index++) {
- await this.startChargingStation(index, stationTemplateUrl);
+ public get numberOfChargingStationTemplates (): number {
+ return this.chargingStationsByTemplate.size
+ }
+
+ public get numberOfConfiguredChargingStations (): number {
+ return [...this.chargingStationsByTemplate.values()].reduce(
+ (accumulator, value) => accumulator + value.configured,
+ 0
+ )
+ }
+
+ public getLastIndex (templateName: string): number {
+ return this.chargingStationsByTemplate.get(templateName)?.lastIndex ?? 0
+ }
+
+ public getPerformanceStatistics (): IterableIterator<Statistics> | undefined {
+ return this.storage?.getPerformanceStatistics()
+ }
+
+ private get numberOfAddedChargingStations (): number {
+ return [...this.chargingStationsByTemplate.values()].reduce(
+ (accumulator, value) => accumulator + value.added,
+ 0
+ )
+ }
+
+ private get numberOfStartedChargingStations (): number {
+ return [...this.chargingStationsByTemplate.values()].reduce(
+ (accumulator, value) => accumulator + value.started,
+ 0
+ )
+ }
+
+ public async start (): Promise<void> {
+ if (!this.started) {
+ if (!this.starting) {
+ this.starting = true
+ this.on(ChargingStationWorkerMessageEvents.added, this.workerEventAdded)
+ this.on(ChargingStationWorkerMessageEvents.started, this.workerEventStarted)
+ this.on(ChargingStationWorkerMessageEvents.stopped, this.workerEventStopped)
+ this.on(ChargingStationWorkerMessageEvents.updated, this.workerEventUpdated)
+ this.on(
+ ChargingStationWorkerMessageEvents.performanceStatistics,
+ this.workerEventPerformanceStatistics
+ )
+ this.on(
+ ChargingStationWorkerMessageEvents.workerElementError,
+ (eventError: ChargingStationWorkerEventError) => {
+ logger.error(
+ `${this.logPrefix()} ${moduleName}.start: Error occurred while handling '${eventError.event}' event on worker:`,
+ eventError
+ )