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;
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;
}
return result;
} catch (MissingVariableValueException e) {
- handler.reportProblem("Failed to read " + name + ". " + e.getMessage());
+ handler.reportProblem("Failed to read " + name + ": " + e.getMessage());
Throwable cur = e;
while((cur = cur.getCause()) != null) {
if(!(cur instanceof MissingVariableValueException)) {
- handler.reportProblem(cur.getMessage());
- break;
+ handler.reportProblem(" " + getSafeDescription(cur));
}
}
} catch (Exception e) {
- handler.reportProblem("Failed to serialize " + name + ": " + e.getMessage(), e);
+ handler.reportProblem("Failed to serialize " + name + ": " + getSafeDescription(e), e);
}
return null;
}
+ private String getSafeDescription(Throwable cur) {
+ return cur.getClass().getName() + (cur == null || cur.getMessage() != null ? ": " + cur.getMessage() : "");
+ }
+
Collection<SerializedVariable> mapProperties(SynchronizationEventHandler handler, Variable child) throws DatabaseException {
ArrayList<SerializedVariable> result = new ArrayList<SerializedVariable>();
for(Variable prop : child.getProperties(graph, StructuralResource2.URIs.SynchronizedRelation)) {
*/
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();
} 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);
}
}
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);
} 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);
}
return graph.getService(ManagementSupport.class).getHeadRevisionId()+1;
}
-
}