From 6da46379296ecec681d6b72d053f82f637ed1c3c Mon Sep 17 00:00:00 2001 From: Jussi Koskela Date: Wed, 31 Oct 2018 16:03:38 +0200 Subject: [PATCH] Update structure and value cache when refreshing variable Previous implementation only updated value cache contents after the previous cached results expired, which could cause unacceptable delays in new NodeManager query results. Also, if there were no listeners for the NodeManager query results, results wouldn't get updated anymore. gitlab #173 Change-Id: I162fbddea7a5b312c7dceb1448d6ef1cc1f07b73 --- .../db/layer0/variable/NodeCache.java | 18 ++++++++++++++++++ .../db/layer0/variable/NodeSupport.java | 14 ++++++++++++++ .../db/StandardVariableNodeManager.java | 12 ++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeCache.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeCache.java index 309efe31e..5ed9678e9 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeCache.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeCache.java @@ -116,6 +116,24 @@ public class NodeCache { scheduleExpiration(node, System.nanoTime() + defaultExpirationTimeInNs); } + public synchronized void remove(Node node) { + if (disposed) + return; + Long expTime = exp.get(node); + if (expTime != null) { + expirationTimes.remove(expTime); + } + map.remove(node); + } + + public synchronized void clear() { + if (disposed) + return; + expirationTimes.clear(); + exp.clear(); + map.clear(); + } + public synchronized void dispose() { disposed = true; expirationTimes.clear(); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeSupport.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeSupport.java index 79bc4eb5e..3ac88ae67 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeSupport.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeSupport.java @@ -5,6 +5,8 @@ import java.util.concurrent.TimeUnit; import org.simantics.databoard.binding.mutable.Variant; import org.simantics.db.layer0.variable.Variables.NodeStructure; import org.simantics.simulator.variable.NodeManager; +import org.simantics.simulator.variable.exceptions.NoValueException; +import org.simantics.simulator.variable.exceptions.NodeManagerException; /** * @author Antti Villberg @@ -55,6 +57,18 @@ public class NodeSupport { && manager.equals(other.manager); } + public void refreshCache(Node node) throws NodeManagerException { + VariableNode variableNode = new VariableNode<>(this, node); + NodeStructure ns = NodeStructureRequest.get(variableNode); + structureCache.put(node, ns); + try { + Variant value = manager.getValue(node); + valueCache.put(node, value); + } catch (NoValueException e) { + valueCache.remove(node); + }; + } + public void dispose() { valueCache.dispose(); structureCache.dispose(); diff --git a/bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableNodeManager.java b/bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableNodeManager.java index a08d733d1..aefa672d4 100644 --- a/bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableNodeManager.java +++ b/bundles/org.simantics.simulator.toolkit.db/src/org/simantics/simulator/toolkit/db/StandardVariableNodeManager.java @@ -16,6 +16,9 @@ import org.simantics.db.layer0.variable.NodeSupport; import org.simantics.simulator.toolkit.StandardNodeManager; import org.simantics.simulator.toolkit.StandardNodeManagerSupport; import org.simantics.simulator.toolkit.StandardRealm; +import org.simantics.simulator.variable.exceptions.NodeManagerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Adds support for Layer0 Variable interface in StandardNodeManager @@ -24,6 +27,7 @@ import org.simantics.simulator.toolkit.StandardRealm; */ public class StandardVariableNodeManager> extends StandardNodeManager { + private static final Logger LOGGER = LoggerFactory.getLogger(StandardVariableNodeManager.class); protected NodeSupport support; public StandardVariableNodeManager(StandardRealm realm, Node root) { @@ -33,9 +37,13 @@ public class StandardVariableNodeManager