From c5aea000d0dae6c0ac14c702371e7a5f54d0fdd2 Mon Sep 17 00:00:00 2001 From: Brandon Date: Tue, 30 Jan 2024 09:59:42 -0800 Subject: [PATCH] Address init context inconsistency Twin instance was not added to local instances map prior to calling init Updating version --- Development/build.gradle | 2 +- .../development/TwinExecutionEngine.java | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Development/build.gradle b/Development/build.gradle index f6d33ca..9b4f594 100644 --- a/Development/build.gradle +++ b/Development/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'com.scaleoutsoftware.digitaltwin' -version '3.0.5' +version '3.0.6' sourceCompatibility = JavaVersion.VERSION_12 diff --git a/Development/src/main/java/com/scaleoutsoftware/digitaltwin/development/TwinExecutionEngine.java b/Development/src/main/java/com/scaleoutsoftware/digitaltwin/development/TwinExecutionEngine.java index fc55d30..7cf4952 100644 --- a/Development/src/main/java/com/scaleoutsoftware/digitaltwin/development/TwinExecutionEngine.java +++ b/Development/src/main/java/com/scaleoutsoftware/digitaltwin/development/TwinExecutionEngine.java @@ -52,7 +52,7 @@ void init( ) { _simulationProcessors = new ConcurrentHashMap<>(); _messageProcessorValueTypes = new ConcurrentHashMap<>(); _modelInstances = new ConcurrentHashMap<>(); - _alertProviders = new ConcurrentHashMap<>(); + _alertProviders = new ConcurrentHashMap<>(); _simulationSchedulers = new ConcurrentHashMap<>(); _realTimeTimers = new ConcurrentHashMap<>(); _gson = new Gson(); @@ -76,9 +76,6 @@ void addDigitalTwin(String digitalTwinModelName, MessageProcessor digitalTwinMes void addTimer(String modelName, String id, String timerName, TimerType type, Duration interval, TimerHandler handler) { ConcurrentHashMap modelInstances = _modelInstances.get(modelName); - if(modelInstances == null) { - modelInstances = new ConcurrentHashMap<>(); - } TwinProxy proxy = modelInstances.get(id); SimulationScheduler scheduler = _simulationSchedulers.get(modelName); if (scheduler != null) { @@ -268,18 +265,19 @@ public void recordAlertMessage(String model, String alertProvider, AlertMessage } public void createInstance(String modelName, String id, DigitalTwinBase instance) { + TwinProxy proxy = new TwinProxy(instance); + ConcurrentHashMap modelInstances = _modelInstances.get(modelName); + if(modelInstances == null) { + modelInstances = new ConcurrentHashMap<>(); + } + modelInstances.put(id, proxy); InitContext initContext = new WorkbenchInitContext(this, instance, modelName, id); instance.init(initContext); SimulationScheduler scheduler = _simulationSchedulers.get(modelName); - TwinProxy proxy = new TwinProxy(instance); if(scheduler != null) { proxy.setProxyState(ProxyState.Active); scheduler.addInstance(proxy); } - ConcurrentHashMap modelInstances = _modelInstances.get(modelName); - if(modelInstances == null) { - modelInstances = new ConcurrentHashMap<>(); - } modelInstances.put(id, proxy); _modelInstances.put(modelName, modelInstances); }