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
scheduleExpiration(node, System.nanoTime() + defaultExpirationTimeInNs);
}
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();
public synchronized void dispose() {
disposed = true;
expirationTimes.clear();
import org.simantics.databoard.binding.mutable.Variant;
import org.simantics.db.layer0.variable.Variables.NodeStructure;
import org.simantics.simulator.variable.NodeManager;
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
/**
* @author Antti Villberg
&& manager.equals(other.manager);
}
&& manager.equals(other.manager);
}
+ public void refreshCache(Node node) throws NodeManagerException {
+ VariableNode<Node> 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();
public void dispose() {
valueCache.dispose();
structureCache.dispose();
import org.simantics.simulator.toolkit.StandardNodeManager;
import org.simantics.simulator.toolkit.StandardNodeManagerSupport;
import org.simantics.simulator.toolkit.StandardRealm;
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
/**
* Adds support for Layer0 Variable interface in StandardNodeManager
*/
public class StandardVariableNodeManager<Node, Engine extends StandardNodeManagerSupport<Node>> extends StandardNodeManager<Node,Engine> {
*/
public class StandardVariableNodeManager<Node, Engine extends StandardNodeManagerSupport<Node>> extends StandardNodeManager<Node,Engine> {
+ private static final Logger LOGGER = LoggerFactory.getLogger(StandardVariableNodeManager.class);
protected NodeSupport<Node> support;
public StandardVariableNodeManager(StandardRealm<Node, Engine> realm, Node root) {
protected NodeSupport<Node> support;
public StandardVariableNodeManager(StandardRealm<Node, Engine> realm, Node root) {
@Override
public void refreshVariable(Node node) {
@Override
public void refreshVariable(Node node) {
+ try {
+ support.refreshCache(node);
+ } catch (NodeManagerException e) {
+ LOGGER.error("Failed to refresh variable", e);
+ throw new RuntimeException(e);
+ }
super.refreshVariable(node);
super.refreshVariable(node);
- support.valueCache.clearExpired();
- support.structureCache.clearExpired();
}
}
\ No newline at end of file
}
}
\ No newline at end of file