From 0f3520e48a9387d07b622ab5b0c20ec3bddbf2b1 Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Fri, 22 Feb 2019 13:23:15 +0200 Subject: [PATCH] Disable throttling for now, as it doens't work. Also use setSynchronous() for diagram styles, as there is no visualization for pending results. gitlab #30 Change-Id: I53ce85ba6d81b69f41abe26930941f2bd9d610a1 --- .../network/profile/DNElementColorStyle.java | 27 ++++++++++++------- .../network/profile/EdgeThicknessStyle.java | 26 +++++++++++------- .../network/profile/ThrottledStyleBase.java | 13 ++++----- .../network/profile/VertexSizeStyle.java | 25 ++++++++++------- .../network/profile/VertexSymbolStyle.java | 27 ++++++++++--------- 5 files changed, 72 insertions(+), 46 deletions(-) diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.java b/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.java index b74a6619..f8f6ba5c 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.java @@ -24,18 +24,25 @@ public class DNElementColorStyle extends ThrottledStyleBase { @Override public Color calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException { DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance()); - if (ds.elementColoringFunction.isPresent()) { - if (DEBUG) - System.out.print("elementColoringFunction: " + ds.elementColoringFunction + "(" + groupItem + "): "); - Double t = Simantics.applySCLRead(graph, ds.elementColoringFunction.get(), groupItem); - if (DEBUG) - System.out.print(t); - if (t != null) { - Color result = ds.coloringGradient.get(t); - //System.out.println("color(" + t + "): " + result); - return result; + // Prevent PendingVariableExceptions from coming through + boolean wasSynchronous = graph.setSynchronous(true); + try { + if (ds.elementColoringFunction.isPresent()) { + if (DEBUG) + System.out.print("elementColoringFunction: " + ds.elementColoringFunction + "(" + groupItem + "): "); + Double t = Simantics.applySCLRead(graph, ds.elementColoringFunction.get(), groupItem); + if (DEBUG) + System.out.print(t); + if (t != null) { + Color result = ds.coloringGradient.get(t); + //System.out.println("color(" + t + "): " + result); + return result; + } } } + finally { + graph.setSynchronous(wasSynchronous); + } return null; } diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/EdgeThicknessStyle.java b/org.simantics.district.network/src/org/simantics/district/network/profile/EdgeThicknessStyle.java index 06dcdf3f..b305c391 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/EdgeThicknessStyle.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/EdgeThicknessStyle.java @@ -19,17 +19,25 @@ public class EdgeThicknessStyle extends ThrottledStyleBase { @Override public Double calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException { DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance()); - Double thickness = ONE; - if (ds.edgeThicknessProperty.isPresent()) { - thickness = Simantics.applySCLRead(graph, ds.edgeThicknessProperty.get(), groupItem); -// System.out.println("read thickness: " + thickness + " : " + ds.edgeThicknessProperty); - if (thickness == null) { - thickness = ONE; - } else { - thickness = thickness * ds.edgeThicknessGain + ds.edgeThicknessBias; + // Prevent PendingVariableExceptions from coming through + boolean wasSynchronous = graph.setSynchronous(true); + try { + Double thickness = ONE; + if (ds.edgeThicknessProperty.isPresent()) { + thickness = Simantics.applySCLRead(graph, ds.edgeThicknessProperty.get(), groupItem); + // System.out.println("read thickness: " + thickness + " : " + ds.edgeThicknessProperty); + if (thickness == null) { + thickness = ONE; + } else { + thickness = thickness * ds.edgeThicknessGain + ds.edgeThicknessBias; + } } + + return thickness; + } + finally { + graph.setSynchronous(wasSynchronous); } - return thickness; } @Override diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/ThrottledStyleBase.java b/org.simantics.district.network/src/org/simantics/district/network/profile/ThrottledStyleBase.java index f8b817ae..67ca2595 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/ThrottledStyleBase.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/ThrottledStyleBase.java @@ -74,12 +74,13 @@ public abstract class ThrottledStyleBase extends StyleBase calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException { - long currentTimestamp = System.currentTimeMillis(); - if (lastCalculateTimestamp > (currentTimestamp - interval.get())) { - LOGGER.debug("Throttling result calculation for {} {} {} {}", runtimeDiagram, entry, groupItem, interval.get()); - return Optional.empty(); - } - lastCalculateTimestamp = currentTimestamp; +// Needs fixing - this will result registration of listeners for nothing in the cache +// long currentTimestamp = System.currentTimeMillis(); +// if (lastCalculateTimestamp > (currentTimestamp - interval.get())) { +// LOGGER.debug("Throttling result calculation for {} {} {} {}", runtimeDiagram, entry, groupItem, interval.get()); +// return Optional.empty(); +// } +// lastCalculateTimestamp = currentTimestamp; // let's calculate return Optional.ofNullable(calculateThrottledStyle(graph, runtimeDiagram, entry, groupItem)); } diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSizeStyle.java b/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSizeStyle.java index d536bc04..b59590b6 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSizeStyle.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSizeStyle.java @@ -20,17 +20,24 @@ public class VertexSizeStyle extends ThrottledStyleBase { public Double calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException { DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance()); Double scaling = ONE; - if (ds.vertexScaleProperty.isPresent()) { - scaling = Simantics.applySCLRead(graph, ds.vertexScaleProperty.get(), groupItem); - if (scaling == null) { - scaling = ONE; - } else { -// System.out.println("read vertex scaling: " + scaling + " : " + ds.vertexScaleProperty); - scaling = scaling * ds.vertexScaleGain + ds.vertexScaleBias; -// System.out.println("RESULT: " + scaling); + // Prevent PendingVariableExceptions from coming through + boolean wasSynchronous = graph.setSynchronous(true); + try { + if (ds.vertexScaleProperty.isPresent()) { + scaling = Simantics.applySCLRead(graph, ds.vertexScaleProperty.get(), groupItem); + if (scaling == null) { + scaling = ONE; + } else { + // System.out.println("read vertex scaling: " + scaling + " : " + ds.vertexScaleProperty); + scaling = scaling * ds.vertexScaleGain + ds.vertexScaleBias; + // System.out.println("RESULT: " + scaling); + } } + return scaling; + } + finally { + graph.setSynchronous(wasSynchronous); } - return scaling; } @Override diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSymbolStyle.java b/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSymbolStyle.java index 96ff4392..26a5564d 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSymbolStyle.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/VertexSymbolStyle.java @@ -6,7 +6,6 @@ import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.ResourceRead; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.exception.PendingVariableException; import org.simantics.district.network.ontology.DistrictNetworkResource; import org.simantics.layer0.Layer0; import org.simantics.scenegraph.INode; @@ -26,18 +25,22 @@ public class VertexSymbolStyle extends ThrottledStyleBase { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public String calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException { - - Function symbolFunction = getSymbolFunction(graph, entry); - if (symbolFunction == null) - return null; - + // Prevent PendingVariableExceptions from coming through + boolean wasSynchronous = graph.setSynchronous(true); try { - return (String) Simantics.applySCLRead(graph, symbolFunction, groupItem); - } catch (PendingVariableException e) { - throw e; - } catch (Exception e) { - LOGGER.error("Getting dynamic symbol for " + groupItem + " (" + graph.getPossibleRelatedValue(groupItem, Layer0.getInstance(graph).HasName) + ") failed", e); - return null; + Function symbolFunction = getSymbolFunction(graph, entry); + if (symbolFunction == null) + return null; + + try { + return (String) Simantics.applySCLRead(graph, symbolFunction, groupItem); + } catch (Exception e) { + LOGGER.error("Getting dynamic symbol for " + groupItem + " (" + graph.getPossibleRelatedValue(groupItem, Layer0.getInstance(graph).HasName) + ") failed", e); + return null; + } + } + finally { + graph.setSynchronous(wasSynchronous); } } -- 2.45.2