import { Storage } from '../performance/storage/Storage';
import { StorageFactory } from '../performance/storage/StorageFactory';
import Utils from '../utils/Utils';
import { Storage } from '../performance/storage/Storage';
import { StorageFactory } from '../performance/storage/StorageFactory';
import Utils from '../utils/Utils';
import WorkerAbstract from '../worker/WorkerAbstract';
import WorkerFactory from '../worker/WorkerFactory';
import chalk from 'chalk';
import WorkerAbstract from '../worker/WorkerAbstract';
import WorkerFactory from '../worker/WorkerFactory';
import chalk from 'chalk';
export default class Bootstrap {
private static instance: Bootstrap | null = null;
private workerImplementation: WorkerAbstract | null = null;
export default class Bootstrap {
private static instance: Bootstrap | null = null;
private workerImplementation: WorkerAbstract | null = null;
private readonly storage: Storage;
private numberOfChargingStations: number;
private readonly version: string = version;
private readonly storage: Storage;
private numberOfChargingStations: number;
private readonly version: string = version;
this.started = false;
this.workerScript = path.join(path.resolve(__dirname, '../'), 'charging-station', 'ChargingStationWorker.js');
this.initWorkerImplementation();
this.started = false;
this.workerScript = path.join(path.resolve(__dirname, '../'), 'charging-station', 'ChargingStationWorker.js');
this.initWorkerImplementation();
this.storage = StorageFactory.getStorage(Configuration.getPerformanceStorage().type, Configuration.getPerformanceStorage().URI, this.logPrefix());
Configuration.setConfigurationChangeCallback(async () => Bootstrap.getInstance().restart());
}
this.storage = StorageFactory.getStorage(Configuration.getPerformanceStorage().type, Configuration.getPerformanceStorage().URI, this.logPrefix());
Configuration.setConfigurationChangeCallback(async () => Bootstrap.getInstance().restart());
}
this.numberOfChargingStations = 0;
await this.storage.open();
await this.workerImplementation.start();
this.numberOfChargingStations = 0;
await this.storage.open();
await this.workerImplementation.start();
// Start ChargingStation object in worker thread
if (Configuration.getStationTemplateURLs()) {
for (const stationURL of Configuration.getStationTemplateURLs()) {
// Start ChargingStation object in worker thread
if (Configuration.getStationTemplateURLs()) {
for (const stationURL of Configuration.getStationTemplateURLs()) {
public async stop(): Promise<void> {
if (isMainThread && this.started) {
await this.workerImplementation.stop();
public async stop(): Promise<void> {
if (isMainThread && this.started) {
await this.workerImplementation.stop();
await this.storage.close();
} else {
console.error(chalk.red('Trying to stop the charging stations simulator while not started'));
await this.storage.close();
} else {
console.error(chalk.red('Trying to stop the charging stations simulator while not started'));