]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Fixed deadlock issues when game experiment is active and variable name has been chang...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 26 Mar 2013 07:00:24 +0000 (07:00 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 26 Mar 2013 07:00:24 +0000 (07:00 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27206 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableValueSubscription.java

index f56bc881722f626f50caf90ab20571d991e64057..7a336dc239b2560ca5a35b8d358fff3a16c9e067 100644 (file)
@@ -104,8 +104,10 @@ public abstract class IndexVariable<T> extends AbstractPropertyVariable {
         }\r
         @Override\r
         public void unregistered() {\r
-            unregisterSubscription(subscription);\r
-            subscription = null;\r
+            if(subscription != null) {\r
+                unregisterSubscription(subscription);\r
+                subscription = null;\r
+            }\r
         }\r
 \r
         @SuppressWarnings("unchecked")\r
index 9ce2169bd735ba0445cd7f36b2f7d5babee95c14..9834ff5db5c7bc42f04efe38cab661769a777eca 100644 (file)
@@ -36,7 +36,8 @@ public class ValueIndexVariable extends IndexVariable<double[]> {
                for(int i = 0; i < variableNames.size(); i++) {\r
                    for(SysdynResult r : results) {            \r
                        if(experiment instanceof SysdynGameExperiment) {\r
-                           result[i] = ((SysdynGameExperiment)experiment).getCurrentValue(variableNames.get(i));\r
+                           Double d = ((SysdynGameExperiment)experiment).getCurrentValue(variableNames.get(i)); \r
+                           result[i] = d != null ? d : 0;\r
                        } else {\r
                            SysdynDataSet ds = r.getDataSet(variableNames.get(i));\r
                            if(ds != null && ds.values != null && ds.values.length > 0) {\r
index 1f918aa7eeb99ecd96faca1939a89d9c82419d24..716fd5887f1ae657925d95c2e61c4ca050a3f118 100644 (file)
@@ -18,6 +18,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import org.simantics.db.Session;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.Logger;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.procedure.Listener;\r
 import org.simantics.db.request.ExternalRead;\r
@@ -48,11 +49,14 @@ public class VariableValueSubscription<T> {
                return request;\r
        }\r
 \r
-\r
-       public void update() {\r
-               T value = variable.getValue();\r
-               fireValue(value);\r
-       }\r
+    public void update() {\r
+        try {\r
+            T value = variable.getValue();\r
+            fireValue(value);\r
+        } catch (Throwable e) {\r
+            fireException(e);\r
+        }\r
+    }\r
 \r
        void fireValue(T value) {\r
                if (listener != null)\r
@@ -62,8 +66,12 @@ public class VariableValueSubscription<T> {
        void fireException(Throwable t) {\r
                if (listener != null && excepted.compareAndSet(false, true))\r
                        listener.exception(t);\r
+        else\r
+            // Can't invoke listener.exception multiple times, but logging\r
+            // further exceptions anyway.\r
+            Logger.defaultLogError(t);\r
        }\r
-\r
+       \r
        public void setListener(Listener<T> listener) {\r
                this.listener = listener;\r
        }\r