]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/client/Synchronizer.java
Added new field TypeId to dependency index for exact type searching
[simantics/platform.git] / bundles / org.simantics.structural.synchronization.client / src / org / simantics / structural / synchronization / client / Synchronizer.java
index cfd5fe69b4ec3eac4129c38a0c526e1b5e8a6441..b311aed94dbfd48bdcd78d6956113480245bbd3b 100644 (file)
@@ -1,8 +1,5 @@
 package org.simantics.structural.synchronization.client;
 
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -28,10 +25,15 @@ import org.simantics.structural.synchronization.protocol.SerializedVariable;
 import org.simantics.structural.synchronization.protocol.SynchronizationEventHandler;
 import org.simantics.structural.synchronization.protocol.SynchronizationException;
 import org.simantics.structural2.variables.VariableConnectionPointDescriptor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.THashSet;
 
 public class Synchronizer {
     
-    public static boolean TRACE = false;
+    private static final Logger LOGGER = LoggerFactory.getLogger(Synchronizer.class);
     
     ReadGraph graph;
     Layer0 L0;
@@ -152,8 +154,8 @@ public class Synchronizer {
      */
     public void fullSynchronization(Variable variable, SynchronizationEventHandler handler) throws DatabaseException {
         long duration = 0;
-        if(TRACE) {
-            System.out.println("fullSynchronization " + variable.getURI(graph));
+        if(LOGGER.isTraceEnabled()) {
+            LOGGER.trace("fullSynchronization {}", variable.getURI(graph));
             duration -= System.nanoTime();
         }
         SCLContext context = SCLContext.getCurrent();
@@ -165,9 +167,9 @@ public class Synchronizer {
         } finally {
             context.put("graph", oldGraph);
         }
-        if(TRACE) {
+        if(LOGGER.isTraceEnabled()) {
             duration += System.nanoTime();
-            System.out.println("full sync in " + 1e-9*duration + "s.");
+            LOGGER.trace("full sync done in {} s", 1e-9*duration);
         }
     }
     
@@ -275,8 +277,8 @@ public class Synchronizer {
     
     public void partialSynchronization(Variable variable, SynchronizationEventHandler handler, TObjectIntHashMap<Variable> changeFlags) throws DatabaseException {
         long duration = 0;
-        if(TRACE) {
-            System.out.println("partialSynchronization " + variable.getURI(graph));
+        if(LOGGER.isTraceEnabled()) {
+            LOGGER.trace("partialSynchronization {}", variable.getURI(graph));
             duration -= System.nanoTime();
         }
         int changeStatus = changeFlags.get(variable);
@@ -290,27 +292,31 @@ public class Synchronizer {
         } finally {
             context.put("graph", oldGraph);
         } 
-        if(TRACE) {
+        if(LOGGER.isTraceEnabled()) {
             duration += System.nanoTime();
-            System.out.println("partial sync in " + 1e-9*duration + "s.");
+            LOGGER.trace("partial sync in {} s", 1e-9*duration);
         }
     }
     
     public void partialSynchronization(Variable variable, SynchronizationEventHandler handler, long fromRevision) throws DatabaseException {
+        boolean trace = LOGGER.isTraceEnabled();
+        if (trace)
+            LOGGER.trace("Partial synchronization for {} from rev {}", variable.getURI(graph), fromRevision);
+
         TObjectIntHashMap<Variable> modifiedComponents = StructuralChangeFlattener.getModifiedComponents(graph, variable, fromRevision);
-        /*System.out.println("----------------");
-        modifiedComponents.forEachEntry(
-                new TObjectIntProcedure<Variable>() {
-                    @Override
-                    public boolean execute(Variable a, int b) {
-                        try {
-                            System.out.println("Changed: " + a.getURI(graph) + " " + b);
-                        } catch (DatabaseException e) {
-                            e.printStackTrace();
-                        }
-                        return true;
-                    }
-                });*/
+
+        if (trace) {
+            LOGGER.trace("----------------");
+            modifiedComponents.forEachEntry((Variable a, int b) -> {
+                try {
+                    LOGGER.trace("Changed: " + a.getURI(graph) + " " + b);
+                } catch (DatabaseException e) {
+                    LOGGER.error("Variable.getURI failed", e);
+                }
+                return true;
+            });
+        }
+
         partialSynchronization(variable, handler, modifiedComponents);
     }
     
@@ -324,5 +330,4 @@ public class Synchronizer {
         return graph.getService(ManagementSupport.class).getHeadRevisionId()+1;
     }
 
-    
 }