]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Disable throttling for now, as it doens't work. 71/2671/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Fri, 22 Feb 2019 11:23:15 +0000 (13:23 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Fri, 22 Feb 2019 11:23:15 +0000 (13:23 +0200)
Also use setSynchronous() for diagram styles, as there is no
visualization for pending results.

gitlab #30

Change-Id: I53ce85ba6d81b69f41abe26930941f2bd9d610a1

org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.java
org.simantics.district.network/src/org/simantics/district/network/profile/EdgeThicknessStyle.java
org.simantics.district.network/src/org/simantics/district/network/profile/ThrottledStyleBase.java
org.simantics.district.network/src/org/simantics/district/network/profile/VertexSizeStyle.java
org.simantics.district.network/src/org/simantics/district/network/profile/VertexSymbolStyle.java

index b74a66198366ccff9b2b24f79c8909c549eb017c..f8f6ba5c5760d8ddd2c1e118382dc3b35269dfa4 100644 (file)
@@ -24,18 +24,25 @@ public class DNElementColorStyle extends ThrottledStyleBase<Color> {
        @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;
        }
 
index 06dcdf3f05e8fc3d0ff6327e75ff7486ee3b893a..b305c39148bd284bfea3b96ee1cbf6221226e198 100644 (file)
@@ -19,17 +19,25 @@ public class EdgeThicknessStyle extends ThrottledStyleBase<Double> {
        @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
index f8b817ae2811143b2f1c92c34d214fc5ea777e58..67ca25952522f41caa0b7a59a163131fa2a7b878 100644 (file)
@@ -74,12 +74,13 @@ public abstract class ThrottledStyleBase<Result> extends StyleBase<Optional<Resu
     @Override
     public final Optional<Result> 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));
     }
index d536bc0438b6b78b42a84c390a14cc24df13c002..b59590b6e301a5e122f6c3c9175eb04a125f49e9 100644 (file)
@@ -20,17 +20,24 @@ public class VertexSizeStyle extends ThrottledStyleBase<Double> {
        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
index 96ff439235971ec19438150e36ff8f2cb019b68b..26a5564d5fade5e47180b437fd12b5c56f66032f 100644 (file)
@@ -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<String> {
        @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);
                }
        }