X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPIncomingRequestService.ts;h=bf5170956f499d4c9e41897f879bc0a1e095c320;hb=492cf6ab7b4e5231974ca1a9c219afbf0d53f4b9;hp=b5f607f534abb3e98a8dfa0c1eb8842740fc88c6;hpb=5cc4b63bd363814ddc657bd4c9b407e5eb3150cb;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index b5f607f5..bf517095 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -5,34 +5,27 @@ import { JsonType } from '../../types/JsonType'; import logger from '../../utils/Logger'; export default abstract class OCPPIncomingRequestService { - private static readonly instances: Map = new Map< - string, - OCPPIncomingRequestService - >(); + private static instance: OCPPIncomingRequestService | null = null; - protected chargingStation: ChargingStation; - - protected constructor(chargingStation: ChargingStation) { - this.chargingStation = chargingStation; + protected constructor() { + // This is intentional } - public static getInstance( - this: new (chargingStation: ChargingStation) => T, - chargingStation: ChargingStation - ): T { - if (!OCPPIncomingRequestService.instances.has(chargingStation.hashId)) { - OCPPIncomingRequestService.instances.set(chargingStation.hashId, new this(chargingStation)); + public static getInstance(this: new () => T): T { + if (!OCPPIncomingRequestService.instance) { + OCPPIncomingRequestService.instance = new this(); } - return OCPPIncomingRequestService.instances.get(chargingStation.hashId) as T; + return OCPPIncomingRequestService.instance as T; } protected handleIncomingRequestError( + chargingStation: ChargingStation, commandName: IncomingRequestCommand, error: Error, params: HandleErrorParams = { throwError: true } ): T { logger.error( - this.chargingStation.logPrefix() + ' Incoming request command %s error: %j', + chargingStation.logPrefix() + ' Incoming request command %s error: %j', commandName, error ); @@ -48,6 +41,7 @@ export default abstract class OCPPIncomingRequestService { } public abstract incomingRequestHandler( + chargingStation: ChargingStation, messageId: string, commandName: IncomingRequestCommand, commandPayload: JsonType