static async start() {
try {
let numStationsTotal = 0;
- const workerImplementation: Wrk = WorkerFactory.getWorkerImpl('./dist/charging-station/StationWorker.js', Configuration.getWorkerProcess(), {
+ const workerImplementation: Wrk = WorkerFactory.getWorkerImpl<StationWorkerData>('./dist/charging-station/StationWorker.js', Configuration.getWorkerProcess(), {
poolMaxSize: Configuration.getWorkerPoolMaxSize(),
poolMinSize: Configuration.getWorkerPoolMinSize(),
elementsPerWorker: Configuration.getChargingStationsPerWorker()
public constructor(objName: string) {
this.objId = objName;
- this.commandsStatistics = { id: this.objId ? this.objId : ' Object id not specified', commandsStatisticsData: {} };
+ this.commandsStatistics = { id: this.objId ? this.objId : 'Object id not specified', commandsStatisticsData: {} };
}
public addMessage(command: RequestCommand | IncomingRequestCommand, messageType: MessageType): void {
import { WorkerData } from '../types/Worker';
import Wrk from './Wrk';
-export default class WorkerDynamicPool extends Wrk {
+export default class WorkerDynamicPool<T> extends Wrk {
private pool: DynamicPool;
/**
* @return {Promise<void>}
* @public
*/
- public async addElement(elementData: WorkerData): Promise<void> {
+ public async addElement(elementData: T): Promise<void> {
await this.pool.execute(elementData);
// Start worker sequentially to optimize memory at startup
await Utils.sleep(Constants.START_WORKER_DELAY);
import Wrk from './Wrk';
export default class WorkerFactory {
- public static getWorkerImpl(workerScript: string, workerProcessType: WorkerProcessType, options?: WorkerOptions): Wrk {
+ public static getWorkerImpl<T>(workerScript: string, workerProcessType: WorkerProcessType, options?: WorkerOptions): Wrk {
if (Utils.isUndefined(options)) {
options = {} as WorkerOptions;
}
if (Utils.isUndefined(options.elementsPerWorker)) {
options.elementsPerWorker = 1;
}
- return new WorkerSet(workerScript, options.elementsPerWorker);
+ return new WorkerSet<T>(workerScript, options.elementsPerWorker);
case WorkerProcessType.STATIC_POOL:
if (Utils.isUndefined(options.poolMaxSize)) {
options.elementsPerWorker = 16;
}
- return new WorkerStaticPool(workerScript, options.poolMaxSize);
+ return new WorkerStaticPool<T>(workerScript, options.poolMaxSize);
case WorkerProcessType.DYNAMIC_POOL:
if (Utils.isUndefined(options.poolMinSize)) {
options.elementsPerWorker = 4;
if (Utils.isUndefined(options.poolMaxSize)) {
options.elementsPerWorker = 16;
}
- return new WorkerDynamicPool(workerScript, options.poolMinSize, options.poolMaxSize);
+ return new WorkerDynamicPool<T>(workerScript, options.poolMinSize, options.poolMaxSize);
default:
return null;
}
-import { WorkerData, WorkerEvents, WorkerSetElement } from '../types/Worker';
+import { WorkerEvents, WorkerSetElement } from '../types/Worker';
import Constants from '../utils/Constants';
import Utils from '../utils/Utils';
import { Worker } from 'worker_threads';
import Wrk from './Wrk';
-export default class WorkerSet extends Wrk {
+export default class WorkerSet<T> extends Wrk {
public maxElementsPerWorker: number;
private workers: Set<WorkerSetElement>;
* @return {Promise<void>}
* @public
*/
- public async addElement(elementData: WorkerData): Promise<void> {
+ public async addElement(elementData: T): Promise<void> {
if (!this.workers) {
throw Error('Cannot add a WorkerSet element: workers\' set does not exist');
}
import { WorkerData } from '../types/Worker';
import Wrk from './Wrk';
-export default class WorkerStaticPool extends Wrk {
+export default class WorkerStaticPool<T> extends Wrk {
private pool: StaticPool;
/**
* @return {Promise<void>}
* @public
*/
- public async addElement(elementData: WorkerData): Promise<void> {
+ public async addElement(elementData: T): Promise<void> {
await this.pool.execute(elementData);
// Start worker sequentially to optimize memory at startup
await Utils.sleep(Constants.START_WORKER_DELAY);