From: Jérôme Benoit Date: Wed, 19 May 2021 22:16:37 +0000 (+0200) Subject: Constify some hardcoded worker related numbers X-Git-Tag: v1.0.1-2~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1f0052b9fa7d0a13a1e85d8a0f761ba250af7fd5;p=e-mobility-charging-stations-simulator.git Constify some hardcoded worker related numbers Signed-off-by: Jérôme Benoit --- diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 0926115c..a3479696 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -58,12 +58,12 @@ export default class Configuration { } static getWorkerPoolMinSize(): number { - return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerPoolMinSize') ? Configuration.getConfig().workerPoolMinSize : 4; + return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerPoolMinSize') ? Configuration.getConfig().workerPoolMinSize : Constants.DEFAULT_WORKER_POOL_MIN_SIZE; } static getWorkerPoolMaxSize(): number { Configuration.deprecateConfigurationKey('workerPoolSize;', 'Use \'workerPoolMaxSize\' instead'); - return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerPoolMaxSize') ? Configuration.getConfig().workerPoolMaxSize : 16; + return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerPoolMaxSize') ? Configuration.getConfig().workerPoolMaxSize : Constants.DEFAULT_WORKER_POOL_MAX_SIZE; } static getWorkerPoolStrategy(): WorkerChoiceStrategy { @@ -71,7 +71,7 @@ export default class Configuration { } static getChargingStationsPerWorker(): number { - return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'chargingStationsPerWorker') ? Configuration.getConfig().chargingStationsPerWorker : 1; + return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'chargingStationsPerWorker') ? Configuration.getConfig().chargingStationsPerWorker : Constants.DEFAULT_CHARGING_STATIONS_PER_WORKER; } static getLogConsole(): boolean { diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 8b1df1ca..706ef41c 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -33,4 +33,7 @@ export default class Constants { static readonly WORKER_START_DELAY = 500; static readonly WORKER_POOL_MAX_INACTIVE_TIME = 60000; + static readonly DEFAULT_WORKER_POOL_MIN_SIZE = 4; + static readonly DEFAULT_WORKER_POOL_MAX_SIZE = 16; + static readonly DEFAULT_CHARGING_STATIONS_PER_WORKER = 1; } diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index f4307be6..3784e7ab 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -16,14 +16,14 @@ export default class WorkerFactory { options.startDelay = options.startDelay ?? Constants.WORKER_START_DELAY; switch (workerProcessType) { case WorkerProcessType.WORKER_SET: - options.elementsPerWorker = options.elementsPerWorker ?? 1; + options.elementsPerWorker = options.elementsPerWorker ?? Constants.DEFAULT_CHARGING_STATIONS_PER_WORKER; return new WorkerSet(workerScript, options.elementsPerWorker, options.startDelay); case WorkerProcessType.STATIC_POOL: - options.poolMaxSize = options.poolMaxSize ?? 16; + options.poolMaxSize = options.poolMaxSize ?? Constants.DEFAULT_WORKER_POOL_MAX_SIZE; return new WorkerStaticPool(workerScript, options.poolMaxSize, options.startDelay, options.poolOptions); case WorkerProcessType.DYNAMIC_POOL: - options.poolMinSize = options.poolMinSize ?? 4; - options.poolMaxSize = options.poolMaxSize ?? 16; + options.poolMinSize = options.poolMinSize ?? Constants.DEFAULT_WORKER_POOL_MIN_SIZE; + options.poolMaxSize = options.poolMaxSize ?? Constants.DEFAULT_WORKER_POOL_MAX_SIZE; return new WorkerDynamicPool(workerScript, options.poolMinSize, options.poolMaxSize, options.startDelay, options.poolOptions); default: return null;