From 8ca6a02c6b91707da3589ff90cfb573218ecd6bd Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 26 Mar 2013 07:00:24 +0000 Subject: [PATCH] Fixed deadlock issues when game experiment is active and variable name has been changed: better handling of exceptions in external reads . (fixes #4209) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27206 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/adapter/IndexVariable.java | 6 ++++-- .../sysdyn/adapter/ValueIndexVariable.java | 3 ++- .../adapter/VariableValueSubscription.java | 20 +++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java index f56bc881..7a336dc2 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java @@ -104,8 +104,10 @@ public abstract class IndexVariable extends AbstractPropertyVariable { } @Override public void unregistered() { - unregisterSubscription(subscription); - subscription = null; + if(subscription != null) { + unregisterSubscription(subscription); + subscription = null; + } } @SuppressWarnings("unchecked") diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java index 9ce2169b..9834ff5d 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java @@ -36,7 +36,8 @@ public class ValueIndexVariable extends IndexVariable { for(int i = 0; i < variableNames.size(); i++) { for(SysdynResult r : results) { if(experiment instanceof SysdynGameExperiment) { - result[i] = ((SysdynGameExperiment)experiment).getCurrentValue(variableNames.get(i)); + Double d = ((SysdynGameExperiment)experiment).getCurrentValue(variableNames.get(i)); + result[i] = d != null ? d : 0; } else { SysdynDataSet ds = r.getDataSet(variableNames.get(i)); if(ds != null && ds.values != null && ds.values.length > 0) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableValueSubscription.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableValueSubscription.java index 1f918aa7..716fd588 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableValueSubscription.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableValueSubscription.java @@ -18,6 +18,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.simantics.db.Session; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.Listener; import org.simantics.db.request.ExternalRead; @@ -48,11 +49,14 @@ public class VariableValueSubscription { return request; } - - public void update() { - T value = variable.getValue(); - fireValue(value); - } + public void update() { + try { + T value = variable.getValue(); + fireValue(value); + } catch (Throwable e) { + fireException(e); + } + } void fireValue(T value) { if (listener != null) @@ -62,8 +66,12 @@ public class VariableValueSubscription { void fireException(Throwable t) { if (listener != null && excepted.compareAndSet(false, true)) listener.exception(t); + else + // Can't invoke listener.exception multiple times, but logging + // further exceptions anyway. + Logger.defaultLogError(t); } - + public void setListener(Listener listener) { this.listener = listener; } -- 2.47.1