From: Jérôme Benoit Date: Sat, 10 Sep 2022 04:11:50 +0000 (+0200) Subject: Move some status attributes at constructor begin X-Git-Tag: v1.1.73~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=aa428a31b4c462d38925ce60a215507c4b406b38;p=e-mobility-charging-stations-simulator.git Move some status attributes at constructor begin Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 706a4b8d..a09ee7a1 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -35,11 +35,11 @@ export default class AutomaticTransactionGenerator { automaticTransactionGeneratorConfiguration: AutomaticTransactionGeneratorConfiguration, chargingStation: ChargingStation ) { + this.started = false; this.configuration = automaticTransactionGeneratorConfiguration; this.chargingStation = chargingStation; this.connectorsStatus = new Map(); this.stopConnectors(); - this.started = false; } public static getInstance( diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 37cd1e64..d0c40162 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -35,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; @@ -47,6 +47,7 @@ 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', diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index bbb5c6f2..0775bcb9 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -114,6 +114,9 @@ export default class ChargingStation { private readonly chargingStationWorkerBroadcastChannel: ChargingStationWorkerBroadcastChannel; constructor(index: number, templateFile: string) { + this.started = false; + this.wsConnectionRestarted = false; + this.autoReconnectRetryCount = 0; this.index = index; this.templateFile = templateFile; this.connectors = new Map(); @@ -122,9 +125,6 @@ export default class ChargingStation { this.sharedLRUCache = SharedLRUCache.getInstance(); this.authorizedTagsCache = AuthorizedTagsCache.getInstance(); this.chargingStationWorkerBroadcastChannel = new ChargingStationWorkerBroadcastChannel(this); - this.started = false; - this.wsConnectionRestarted = false; - this.autoReconnectRetryCount = 0; this.initialize(); } @@ -1361,16 +1361,15 @@ export default class ChargingStation { if (this.isRegistered()) { if (this.isInAcceptedState()) { await this.startMessageSequence(); - this.wsConnectionRestarted && this.flushMessageBuffer(); } } else { logger.error( `${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})` ); } - this.started === false && (this.started = true); - this.autoReconnectRetryCount = 0; this.wsConnectionRestarted = false; + this.autoReconnectRetryCount = 0; + this.started = true; parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); } else { logger.warn( @@ -1398,7 +1397,7 @@ export default class ChargingStation { code )}' and reason '${reason}'` ); - await this.reconnect(code); + await this.reconnect(); break; } parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); @@ -1814,6 +1813,7 @@ export default class ChargingStation { if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable === true) { this.startAutomaticTransactionGenerator(); } + this.wsConnectionRestarted === true && this.flushMessageBuffer(); } private async stopMessageSequence( @@ -1966,7 +1966,7 @@ export default class ChargingStation { : false; } - private async reconnect(code: number): Promise { + private async reconnect(): Promise { // Stop WebSocket ping this.stopWebSocketPing(); // Stop heartbeat