X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural.synchronization.client%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2FSynchronizer.java;fp=bundles%2Forg.simantics.structural.synchronization.client%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2FSynchronizer.java;h=653224a284f029b0f66e418e467693c66cf7be73;hb=a8ea477a16e16f53f2909c58fb88a379b36b3f2c;hp=8125a676cce08dea12e7bcf09788867c2a8c2f38;hpb=c10753c13921e63c6bb2cf51335a9c6d402efac5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/Synchronizer.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/Synchronizer.java index 8125a676c..653224a28 100644 --- a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/Synchronizer.java +++ b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/Synchronizer.java @@ -1,8 +1,5 @@ package org.simantics.structural.synchronization; -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; @@ -148,8 +150,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(); @@ -161,9 +163,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); } } @@ -271,8 +273,8 @@ public class Synchronizer { public void partialSynchronization(Variable variable, SynchronizationEventHandler handler, TObjectIntHashMap 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); @@ -286,27 +288,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 modifiedComponents = StructuralChangeFlattener.getModifiedComponents(graph, variable, fromRevision); - /*System.out.println("----------------"); - modifiedComponents.forEachEntry( - new TObjectIntProcedure() { - @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); } @@ -320,5 +326,4 @@ public class Synchronizer { return graph.getService(ManagementSupport.class).getHeadRevisionId()+1; } - }