X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FBootstrap.ts;h=2c5d6a7d532b7f7d1eefabd17d8e8923b0c8e08f;hb=42371a2ed3ad187c91417fa759fd260ae86dee7c;hp=15eb4fcef4ad469736d3d180133698ee7933164a;hpb=e1d9a0f4d6ff1a90048e9a694fd12b7031cc6961;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 15eb4fce..2c5d6a7d 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -20,9 +20,13 @@ import { type ChargingStationWorkerMessage, type ChargingStationWorkerMessageData, ChargingStationWorkerMessageEvents, + ConfigurationSection, ProcedureName, type StationTemplateUrl, type Statistics, + type StorageConfiguration, + type UIServerConfiguration, + type WorkerConfiguration, } from '../types'; import { Configuration, @@ -78,12 +82,21 @@ export class Bootstrap extends EventEmitter { dirname(fileURLToPath(import.meta.url)), `ChargingStationWorker${extname(fileURLToPath(import.meta.url))}`, ); - Configuration.getUIServer().enabled === true && - (this.uiServer = UIServerFactory.getUIServerImplementation(Configuration.getUIServer())); - Configuration.getPerformanceStorage().enabled === true && + Configuration.getConfigurationSection(ConfigurationSection.uiServer) + .enabled === true && + (this.uiServer = UIServerFactory.getUIServerImplementation( + Configuration.getConfigurationSection(ConfigurationSection.uiServer), + )); + Configuration.getConfigurationSection( + ConfigurationSection.performanceStorage, + ).enabled === true && (this.storage = StorageFactory.getStorage( - Configuration.getPerformanceStorage().type!, - Configuration.getPerformanceStorage().uri!, + Configuration.getConfigurationSection( + ConfigurationSection.performanceStorage, + ).type!, + Configuration.getConfigurationSection( + ConfigurationSection.performanceStorage, + ).uri!, this.logPrefix(), )); Configuration.setConfigurationChangeCallback(async () => Bootstrap.getInstance().restart()); @@ -130,13 +143,21 @@ export class Bootstrap extends EventEmitter { this.version } started with ${this.numberOfChargingStations.toString()} charging station(s) from ${this.numberOfChargingStationTemplates.toString()} configured charging station template(s) and ${ Configuration.workerDynamicPoolInUse() - ? `${Configuration.getWorker().poolMinSize?.toString()}/` + ? `${Configuration.getConfigurationSection( + ConfigurationSection.worker, + ).poolMinSize?.toString()}/` : '' }${this.workerImplementation?.size}${ Configuration.workerPoolInUse() - ? `/${Configuration.getWorker().poolMaxSize?.toString()}` + ? `/${Configuration.getConfigurationSection( + ConfigurationSection.worker, + ).poolMaxSize?.toString()}` : '' - } worker(s) concurrently running in '${Configuration.getWorker().processType}' mode${ + } worker(s) concurrently running in '${ + Configuration.getConfigurationSection( + ConfigurationSection.worker, + ).processType + }' mode${ !isNullOrUndefined(this.workerImplementation?.maxElementsPerWorker) ? ` (${this.workerImplementation?.maxElementsPerWorker} charging station(s) per worker)` : '' @@ -213,7 +234,10 @@ export class Bootstrap extends EventEmitter { private initializeWorkerImplementation(): void { let elementsPerWorker: number | undefined; - if (Configuration.getWorker()?.elementsPerWorker === 'auto') { + if ( + Configuration.getConfigurationSection(ConfigurationSection.worker) + ?.elementsPerWorker === 'auto' + ) { elementsPerWorker = this.numberOfChargingStations > availableParallelism() ? Math.round(this.numberOfChargingStations / availableParallelism()) @@ -222,14 +246,25 @@ export class Bootstrap extends EventEmitter { this.workerImplementation === null && (this.workerImplementation = WorkerFactory.getWorkerImplementation( this.workerScript, - Configuration.getWorker().processType!, + Configuration.getConfigurationSection(ConfigurationSection.worker) + .processType!, { - workerStartDelay: Configuration.getWorker().startDelay, - elementStartDelay: Configuration.getWorker().elementStartDelay, - poolMaxSize: Configuration.getWorker().poolMaxSize!, - poolMinSize: Configuration.getWorker().poolMinSize!, + workerStartDelay: Configuration.getConfigurationSection( + ConfigurationSection.worker, + ).startDelay, + elementStartDelay: Configuration.getConfigurationSection( + ConfigurationSection.worker, + ).elementStartDelay, + poolMaxSize: Configuration.getConfigurationSection( + ConfigurationSection.worker, + ).poolMaxSize!, + poolMinSize: Configuration.getConfigurationSection( + ConfigurationSection.worker, + ).poolMinSize!, elementsPerWorker: - elementsPerWorker ?? (Configuration.getWorker().elementsPerWorker as number), + elementsPerWorker ?? + (Configuration.getConfigurationSection(ConfigurationSection.worker) + .elementsPerWorker as number), poolOptions: { messageHandler: this.messageHandler.bind(this) as (message: unknown) => void, },