import { AuthorizationStatus, AuthorizeResponse, StartTransactionResponse, StopTransactionReason, StopTransactionResponse } from '../types/ocpp/Transaction';
-import ChargingStation from './ChargingStation';
+import type ChargingStation from './ChargingStation';
import Constants from '../utils/Constants';
import PerformanceStatistics from '../performance/PerformanceStatistics';
import { Status } from '../types/AutomaticTransactionGenerator';
import logger from '../utils/Logger';
export default class AutomaticTransactionGenerator {
+ private static readonly instances: Map<string, AutomaticTransactionGenerator> = new Map<string, AutomaticTransactionGenerator>();
public started: boolean;
private readonly chargingStation: ChargingStation;
private readonly connectorsStatus: Map<number, Status>;
- constructor(chargingStation: ChargingStation) {
+ private constructor(chargingStation: ChargingStation) {
this.chargingStation = chargingStation;
this.connectorsStatus = new Map<number, Status>();
this.stopConnectors();
this.started = false;
}
+ public static getInstance(chargingStation: ChargingStation): AutomaticTransactionGenerator {
+ if (!AutomaticTransactionGenerator.instances.has(chargingStation.id)) {
+ AutomaticTransactionGenerator.instances.set(chargingStation.id, new AutomaticTransactionGenerator(chargingStation));
+ }
+ return AutomaticTransactionGenerator.instances.get(chargingStation.id);
+ }
+
public start(): void {
if (this.started) {
logger.error(`${this.logPrefix()} trying to start while already started`);
private startAutomaticTransactionGenerator() {
if (this.stationInfo.AutomaticTransactionGenerator.enable) {
if (!this.automaticTransactionGenerator) {
- this.automaticTransactionGenerator = new AutomaticTransactionGenerator(this);
+ this.automaticTransactionGenerator = AutomaticTransactionGenerator.getInstance(this);
}
if (!this.automaticTransactionGenerator.started) {
this.automaticTransactionGenerator.start();
import { Client, FTPResponse } from 'basic-ftp';
import { OCPP16AuthorizationStatus, OCPP16StopTransactionReason } from '../../../types/ocpp/1.6/Transaction';
-import ChargingStation from '../../ChargingStation';
+import type ChargingStation from '../../ChargingStation';
import Constants from '../../../utils/Constants';
import { DefaultResponse } from '../../../types/ocpp/Responses';
import { ErrorType } from '../../../types/ocpp/ErrorType';
import { ACElectricUtils, DCElectricUtils } from '../../../utils/ElectricUtils';
import { AuthorizeRequest, OCPP16AuthorizeResponse, OCPP16StartTransactionResponse, OCPP16StopTransactionReason, OCPP16StopTransactionResponse, StartTransactionRequest, StopTransactionRequest } from '../../../types/ocpp/1.6/Transaction';
import { CurrentType, Voltage } from '../../../types/ChargingStationTemplate';
-import { DiagnosticsStatusNotificationRequest, HeartbeatRequest, OCPP16BootNotificationRequest, OCPP16IncomingRequestCommand, OCPP16RequestCommand, StatusNotificationRequest } from '../../../types/ocpp/1.6/Requests';
+import { DiagnosticsStatusNotificationRequest, HeartbeatRequest, OCPP16BootNotificationRequest, OCPP16RequestCommand, StatusNotificationRequest } from '../../../types/ocpp/1.6/Requests';
import { MeterValueUnit, MeterValuesRequest, OCPP16MeterValue, OCPP16MeterValueMeasurand, OCPP16MeterValuePhase } from '../../../types/ocpp/1.6/MeterValues';
-import ChargingStation from '../../ChargingStation';
+import type ChargingStation from '../../ChargingStation';
import Constants from '../../../utils/Constants';
import { ErrorType } from '../../../types/ocpp/ErrorType';
import MeasurandPerPhaseSampledValueTemplates from '../../../types/MeasurandPerPhaseSampledValueTemplates';
import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
import OCPPError from '../../../exception/OCPPError';
import OCPPRequestService from '../OCPPRequestService';
-import OCPPResponseService from '../OCPPResponseService';
+import type OCPPResponseService from '../OCPPResponseService';
import { SendParams } from '../../../types/ocpp/Requests';
import Utils from '../../../utils/Utils';
import logger from '../../../utils/Logger';
import { HeartbeatResponse, OCPP16BootNotificationResponse, OCPP16RegistrationStatus, StatusNotificationResponse } from '../../../types/ocpp/1.6/Responses';
import { MeterValuesRequest, MeterValuesResponse } from '../../../types/ocpp/1.6/MeterValues';
-import ChargingStation from '../../ChargingStation';
+import type ChargingStation from '../../ChargingStation';
import { ErrorType } from '../../../types/ocpp/ErrorType';
import { JsonType } from '../../../types/JsonType';
import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
import { MeterValueContext, MeterValueLocation, MeterValueUnit, OCPP16MeterValue, OCPP16MeterValueMeasurand, OCPP16MeterValuePhase, OCPP16SampledValue } from '../../../types/ocpp/1.6/MeterValues';
-import ChargingStation from '../../ChargingStation';
+import type ChargingStation from '../../ChargingStation';
import { ErrorType } from '../../../types/ocpp/ErrorType';
import OCPPError from '../../../exception/OCPPError';
import { RequestCommand } from '../../../types/ocpp/Requests';
import Constants from '../utils/Constants';
import { PoolOptions } from 'poolifier';
-import WorkerAbstract from './WorkerAbstract';
+import type WorkerAbstract from './WorkerAbstract';
import WorkerDynamicPool from './WorkerDynamicPool';
import WorkerSet from './WorkerSet';
import WorkerStaticPool from './WorkerStaticPool';