server.
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
"key": "AuthorizeRemoteTxRequests",
"readonly": false,
"value": "false"
+ },
+ {
+ "key": "WebSocketPingInterval",
+ "readonly": false,
+ "value": "60"
}
]
},
"key": "AuthorizeRemoteTxRequests",
"readonly": false,
"value": "false"
+ },
+ {
+ "key": "WebSocketPingInterval",
+ "readonly": false,
+ "value": "60"
}
]
},
"key": "AuthorizeRemoteTxRequests",
"readonly": false,
"value": "false"
+ },
+ {
+ "key": "WebSocketPingInterval",
+ "readonly": false,
+ "value": "60"
}
]
},
"key": "AuthorizeRemoteTxRequests",
"readonly": false,
"value": "false"
+ },
+ {
+ "key": "WebSocketPingInterval",
+ "readonly": false,
+ "value": "60"
}
]
},
"key": "AuthorizeRemoteTxRequests",
"readonly": false,
"value": "false"
+ },
+ {
+ "key": "WebSocketPingInterval",
+ "readonly": false,
+ "value": "60"
}
]
},
"key": "AuthorizeRemoteTxRequests",
"readonly": false,
"value": "false"
+ },
+ {
+ "key": "WebSocketPingInterval",
+ "readonly": false,
+ "value": "60"
}
]
},
"key": "AuthorizeRemoteTxRequests",
"readonly": false,
"value": "false"
+ },
+ {
+ "key": "WebSocketPingInterval",
+ "readonly": false,
+ "value": "60"
}
]
},
private constructor() {
this.started = false;
this.workerScript = path.join(path.resolve(__dirname, '../'), 'charging-station', 'StationWorker.js');
- Configuration.setConfigurationChangeCallback(async () => await Bootstrap.getInstance().restart());
+ Configuration.setConfigurationChangeCallback(async () => Bootstrap.getInstance().restart());
}
public static getInstance(): Bootstrap {
}
public start(): void {
+ if (this.getEnableStatistics()) {
+ this.performanceStatistics.start();
+ }
this.openWSConnection();
// Monitor authorization file
this.startAuthorizationFileMonitoring();
if (this.isWebSocketOpen()) {
this.wsConnection.close();
}
+ if (this.getEnableStatistics()) {
+ this.performanceStatistics.stop();
+ }
this.bootNotificationResponse = null;
this.hasStopped = true;
}
public getConfigurationKey(key: string | StandardParametersKey, caseInsensitive = false): ConfigurationKey | undefined {
- const configurationKey: ConfigurationKey | undefined = this.configuration.configurationKey.find((configElement) => {
+ return this.configuration.configurationKey.find((configElement) => {
if (caseInsensitive) {
return configElement.key.toLowerCase() === key.toLowerCase();
}
return configElement.key === key;
});
- return configurationKey;
}
public addConfigurationKey(key: string | StandardParametersKey, value: string, readonly = false, visible = true, reboot = false): void {
}
private getTemplateChargingStationConfiguration(): ChargingStationConfiguration {
- return this.stationInfo.Configuration ? this.stationInfo.Configuration : {} as ChargingStationConfiguration;
+ return this.stationInfo.Configuration ?? {} as ChargingStationConfiguration;
}
private getAuthorizationFile(): string | undefined {
}
// Start the ATG
this.startAutomaticTransactionGenerator();
- if (this.getEnableStatistics()) {
- this.performanceStatistics.start();
- }
}
private startAutomaticTransactionGenerator() {
}
private async reconnect(error: any): Promise<void> {
+ // Stop WebSocket ping
+ this.stopWebSocketPing();
// Stop heartbeat
this.stopHeartbeat();
// Stop the ATG if needed
}
public stop(): void {
- clearInterval(this.displayInterval);
+ if (this.displayInterval) {
+ clearInterval(this.displayInterval);
+ }
performance.clearMarks();
this.performanceObserver.disconnect();
}
import { Worker } from 'worker_threads';
import WorkerAbstract from './WorkerAbstract';
import { WorkerData } from '../types/Worker';
+import { WorkerUtils } from './WorkerUtils';
export default class WorkerDynamicPool<T> extends WorkerAbstract {
private pool: DynamicPool;
public static getInstance(min: number, max: number, workerScript: string, opts?: PoolOptions<Worker>): DynamicPool {
if (!DynamicPool.instance) {
- opts.exitHandler = opts?.exitHandler ?? ((code) => {
- if (code !== 0) {
- console.error(`Worker stopped with exit code ${code}`);
- }
- });
+ opts.exitHandler = opts?.exitHandler ?? WorkerUtils.defaultExitHandler;
DynamicPool.instance = new DynamicPool(min, max, workerScript, opts);
}
return DynamicPool.instance;
import Utils from '../utils/Utils';
import { Worker } from 'worker_threads';
import WorkerAbstract from './WorkerAbstract';
+import { WorkerUtils } from './WorkerUtils';
export default class WorkerSet<T> extends WorkerAbstract {
public maxElementsPerWorker: number;
worker.on('message', () => { });
worker.on('error', () => { });
worker.on('exit', (code) => {
- if (code !== 0) {
- console.error(`Worker stopped with exit code ${code}`);
- }
+ WorkerUtils.defaultExitHandler(code);
this.workerSet.delete(this.getWorkerSetElementByWorker(worker));
});
this.workerSet.add({ worker, numberOfWorkerElements: 0 });
import { Worker } from 'worker_threads';
import WorkerAbstract from './WorkerAbstract';
import { WorkerData } from '../types/Worker';
+import { WorkerUtils } from './WorkerUtils';
export default class WorkerStaticPool<T> extends WorkerAbstract {
private pool: StaticPool;
public static getInstance(numberOfThreads: number, workerScript: string, opts?: PoolOptions<Worker>): StaticPool {
if (!StaticPool.instance) {
- opts.exitHandler = opts?.exitHandler ?? ((code) => {
- if (code !== 0) {
- console.error(`Worker stopped with exit code ${code}`);
- }
- });
+ opts.exitHandler = opts?.exitHandler ?? WorkerUtils.defaultExitHandler;
StaticPool.instance = new StaticPool(numberOfThreads, workerScript, opts);
}
return StaticPool.instance;
--- /dev/null
+export class WorkerUtils {
+ public static defaultExitHandler = (code: number): void => {
+ if (code !== 0) {
+ console.error(`Worker stopped with exit code ${code}`);
+ }
+ };
+}