Switch to poolifier worker threads pool implementation.
[e-mobility-charging-stations-simulator.git] / src / worker / WorkerFactory.ts
index 067188d846401d13c3a76c1bdff6236442de6859..2d923daab084bb95b77a783509053bed4b519a7a 100644 (file)
@@ -1,13 +1,21 @@
 import Configuration from '../utils/Configuration';
-import WorkerPool from './WorkerPool';
+import WorkerDynamicPool from './WorkerDynamicPool';
+import { WorkerProcessType } from '../types/Worker';
 import WorkerSet from './WorkerSet';
+import WorkerStaticPool from './WorkerStaticPool';
 import Wrk from './Wrk';
 
 export default class WorkerFactory {
   public static getWorkerImpl(workerScript: string): Wrk {
-    if (Configuration.useWorkerPool()) {
-      return new WorkerPool(workerScript);
+    switch (Configuration.getWorkerProcess()) {
+      case WorkerProcessType.WORKER_SET:
+        return new WorkerSet(workerScript, Configuration.getChargingStationsPerWorker());
+      case WorkerProcessType.STATIC_POOL:
+        return new WorkerStaticPool(workerScript, Configuration.getWorkerPoolMaxSize());
+      case WorkerProcessType.DYNAMIC_POOL:
+        return new WorkerDynamicPool(workerScript, Configuration.getWorkerPoolMinSize(), Configuration.getWorkerPoolMaxSize());
+      default:
+        return null;
     }
-    return new WorkerSet(workerScript, Configuration.getChargingStationsPerWorker());
   }
 }