+
+ private workerEventStarted = (data: ChargingStationData) => {
+ this.uiServer?.chargingStations.set(data.stationInfo.hashId, data);
+ ++this.numberOfStartedChargingStations;
+ logger.info(
+ `${this.logPrefix()} ${moduleName}.workerEventStarted: Charging station ${
+ data.stationInfo.chargingStationId
+ } (hashId: ${data.stationInfo.hashId}) started (${
+ this.numberOfStartedChargingStations
+ } started from ${this.numberOfChargingStations})`,
+ );
+ };
+
+ private workerEventStopped = (data: ChargingStationData) => {
+ this.uiServer?.chargingStations.set(data.stationInfo.hashId, data);
+ --this.numberOfStartedChargingStations;
+ logger.info(
+ `${this.logPrefix()} ${moduleName}.workerEventStopped: Charging station ${
+ data.stationInfo.chargingStationId
+ } (hashId: ${data.stationInfo.hashId}) stopped (${
+ this.numberOfStartedChargingStations
+ } started from ${this.numberOfChargingStations})`,
+ );
+ };
+
+ private workerEventUpdated = (data: ChargingStationData) => {
+ this.uiServer?.chargingStations.set(data.stationInfo.hashId, data);
+ };
+
+ private workerEventPerformanceStatistics = (data: Statistics) => {
+ this.storage.storePerformanceStatistics(data) as void;
+ };
+
+ private initializeCounters() {
+ if (this.initializedCounters === false) {
+ this.resetCounters();
+ const stationTemplateUrls = Configuration.getStationTemplateUrls()!;
+ if (isNotEmptyArray(stationTemplateUrls)) {
+ this.numberOfChargingStationTemplates = stationTemplateUrls.length;
+ for (const stationTemplateUrl of stationTemplateUrls) {
+ this.numberOfChargingStations += stationTemplateUrl.numberOfStations ?? 0;
+ }
+ } else {
+ console.warn(
+ chalk.yellow("'stationTemplateUrls' not defined or empty in configuration, exiting"),
+ );
+ process.exit(exitCodes.missingChargingStationsConfiguration);
+ }
+ if (this.numberOfChargingStations === 0) {
+ console.warn(
+ chalk.yellow('No charging station template enabled in configuration, exiting'),
+ );
+ process.exit(exitCodes.noChargingStationTemplates);
+ }
+ this.initializedCounters = true;
+ }
+ }
+
+ private resetCounters(): void {
+ this.numberOfChargingStationTemplates = 0;
+ this.numberOfChargingStations = 0;
+ this.numberOfStartedChargingStations = 0;
+ }
+
+ private async startChargingStation(
+ index: number,
+ stationTemplateUrl: StationTemplateUrl,
+ ): Promise<void> {
+ await this.workerImplementation?.addElement({
+ index,
+ templateFile: join(
+ dirname(fileURLToPath(import.meta.url)),
+ 'assets',
+ 'station-templates',
+ stationTemplateUrl.file,
+ ),
+ });
+ }
+
+ private gracefulShutdown = (): void => {
+ console.info(`${chalk.green('Graceful shutdown')}`);
+ this.stop()
+ .then(() => {
+ process.exit(0);
+ })
+ .catch((error) => {
+ console.error(chalk.red('Error while shutdowning charging stations simulator: '), error);
+ process.exit(1);
+ });
+ };
+
+ private logPrefix = (): string => {
+ return logPrefix(' Bootstrap |');
+ };