X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.structural.synchronization.client%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2Fclient%2FSynchronizer.java;h=b311aed94dbfd48bdcd78d6956113480245bbd3b;hp=cfd5fe69b4ec3eac4129c38a0c526e1b5e8a6441;hb=ad0e5bf4b34705988e23c9ee3f8e4fcbb760c701;hpb=0f2d6b33db9eabe0c1b142f6d0197a5d1446c3b1 diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/client/Synchronizer.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/client/Synchronizer.java index cfd5fe69b..b311aed94 100644 --- a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/client/Synchronizer.java +++ b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/client/Synchronizer.java @@ -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 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 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); } @@ -324,5 +330,4 @@ public class Synchronizer { return graph.getService(ManagementSupport.class).getHeadRevisionId()+1; } - }