import org.simantics.db.AsyncReadGraph;
import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.impl.graph.AsyncBarrierImpl;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.procedure.AsyncMultiProcedure;
private static final Object NO_RESULT = new Object();
private final Object key;
- private final ReadGraphImpl graph;
+ private final AsyncBarrierImpl barrier;
+ private final ReadGraphImpl procedureGraph;
private final AsyncMultiProcedure<Result> procedure;
private Object result = NO_RESULT;
private Throwable exception = null;
- public BlockingAsyncMultiProcedure(ReadGraphImpl graph, AsyncMultiProcedure<Result> procedure, Object key) {
+ public BlockingAsyncMultiProcedure(AsyncBarrierImpl barrier, ReadGraphImpl procedureGraph, AsyncMultiProcedure<Result> procedure, Object key) {
this.procedure = procedure;
this.key = key;
- this.graph = graph;
- this.graph.asyncBarrier.inc();
+ this.barrier = barrier;
+ this.barrier.inc();
+ this.procedureGraph = procedureGraph;
}
@Override
public void execute(AsyncReadGraph graph, Result result) {
this.result = result;
try {
- if(procedure != null) procedure.execute(graph, result);
+ if(procedure != null) procedure.execute(procedureGraph, result);
} catch (Throwable throwable) {
Logger.defaultLogError("AsyncProcedure.execute threw for " + procedure, throwable);
}
@Override
public void finished(AsyncReadGraph graph) {
- this.graph.asyncBarrier.dec();
try {
- if(procedure != null) procedure.finished(graph);
+ if(procedure != null) procedure.finished(procedureGraph);
} catch (Throwable throwable) {
Logger.defaultLogError("AsyncProcedure.finish threw for " + procedure, throwable);
+ } finally {
+ barrier.dec();
}
}
public void exception(AsyncReadGraph graph, Throwable t) {
this.exception = t;
try {
- if (procedure != null) procedure.exception(graph, t);
+ if (procedure != null) procedure.exception(procedureGraph, t);
} catch (Throwable throwable) {
Logger.defaultLogError("AsyncProcedure.exception threw for " + procedure, throwable);
} finally {
- this.graph.asyncBarrier.dec();
+ barrier.dec();
}
}
@SuppressWarnings("unchecked")
public Result get() throws DatabaseException {
- graph.asyncBarrier.waitBarrier(key, graph);
+
+ barrier.waitBarrier(key, procedureGraph);
+
if (exception != null) {
if (exception instanceof DatabaseException) throw (DatabaseException) exception;
throw new DatabaseException(exception);
} else {
return (Result) result;
}
+
}
@SuppressWarnings("unchecked")
*******************************************************************************/
package org.simantics.db.impl.graph;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.simantics.db.common.utils.Logger;
private static final long serialVersionUID = 4724463372850048672L;
- static final HashMap<AsyncBarrierImpl, Collection<AsyncBarrierImpl>> reverseLookup = new HashMap<>();
- public static final HashMap<AsyncBarrierImpl, Debugger> debuggerMap = new HashMap<>();
- static final HashMap<AsyncBarrierImpl, CacheEntry<?>> entryMap = new HashMap<>();
- static final HashMap<AsyncBarrierImpl, Boolean> restartMap = new HashMap<>();
-
static final int WAIT_TIME = 600;
- public static final boolean BOOKKEEPING = false;
public static final boolean PRINT = false;
- static final boolean RESTART_GUARD = true;
final public AsyncBarrierImpl caller;
- //private final Semaphore sema = new Semaphore(0);
-
public AsyncBarrierImpl(AsyncBarrierImpl caller, CacheEntry<?> entry) {
super(0);
- if (BOOKKEEPING) {
- synchronized (entryMap) {
- entryMap.put(this, entry);
- }
- synchronized (debuggerMap) {
- debuggerMap.put(this, new Debugger());
- }
- synchronized (reverseLookup) {
- Collection<AsyncBarrierImpl> barriers = reverseLookup
- .get(caller);
- if (barriers == null) {
- barriers = new ArrayList<AsyncBarrierImpl>();
- reverseLookup.put(caller, barriers);
- }
- barriers.add(this);
- }
- }
this.caller = caller;
+ if (BarrierTracing.BOOKKEEPING) {
+ BarrierTracing.trace(this, entry);
+ }
}
- public class Debugger {
-
- public Map<AsyncBarrierImpl, String> infos = new HashMap<>();
-
- public synchronized void inc(AsyncBarrierImpl id, String info) {
- if (id == null)
- return;
- String exist = infos.get(id);
- if (exist != null)
- throw new IllegalStateException("Already existing info " + id + " " + info);
- infos.put(id, exist);
- }
-
- public synchronized void dec(AsyncBarrierImpl id) {
- if (id == null)
- return;
- String exist = infos.get(id);
- if (exist == null) {
- System.err.println("No data for " + id);
- } else {
- infos.remove(id);
- }
- }
-
- @Override
- public synchronized String toString() {
- StringBuilder b = new StringBuilder();
- for (String s : infos.values()) {
- b.append("info " + s + "\r\n");
- }
- return b.toString();
- }
-
- public boolean isEmpty() {
- return infos.isEmpty();
- }
-
- }
public void inc() {
- if (BOOKKEEPING)
- inc(this, new Exception().getStackTrace()[2].toString());
- else
- inc(null, null);
-
- if (RESTART_GUARD)
- if(restartMap.containsKey(this))
- throw new IllegalStateException("Unplanned restart");
-
+ if(BarrierTracing.BOOKKEEPING) {
+ BarrierTracing.inc(this);
+ } else {
+ inc(null, null);
+ }
+
}
- private void inc(Object id, String info) {
-
- // if (PRINT) {
- // if (get() < 5)
- // new Exception("inc " + get() + " " + this).printStackTrace();
- // }
-
- if (BOOKKEEPING) {
-// Debugger debugger = debuggerMap.get(this);
-// if (debugger != null)
-// debugger.inc(id, info);
- }
+ void inc(Object id, String info) {
if(PRINT) {
-
System.err.println("inc barrier[" + get() + "] " + this);
StackTraceElement[] elems = new Exception().getStackTrace();
for(int i=0;i<4;i++) System.err.println(elems[i]);
-
}
if (incrementAndGet() == 1) {
if (caller != null) {
- if (BOOKKEEPING)
- caller.inc(this, "Child");
- else
- caller.inc(null, null);
+ if(BarrierTracing.BOOKKEEPING) {
+ caller.inc(this, "Child");
+ } else {
+ caller.inc(null, null);
+ }
}
}
int count = decrementAndGet();
if (count < 1) {
+ if(BarrierTracing.BOOKKEEPING) {
+ BarrierTracing.dec(this, count);
+ }
if (count == 0) {
- if (caller != null)
- caller.dec(this);
- // sema.release();
+ if (caller != null) {
+ caller.dec();
+ }
}
if (count < 0) {
Logger.defaultLogError(
}
- public void dec(Object id) {
-
- if (PRINT) {
- if (get() < 5)
- new Exception("dec" + get() + " " + this).printStackTrace();
- }
-
- if (BOOKKEEPING) {
-// Debugger debugger = debuggerMap.get(this);
-// if (debugger != null) {
-// debugger.dec(id);
-// if(debugger.isEmpty())
-// debuggerMap.remove(this);
-// }
- }
-
- int count = decrementAndGet();
- if (count < 1) {
- if (count == 0) {
- debuggerMap.remove(this);
- if (caller != null)
- caller.dec(this);
- if (RESTART_GUARD)
- restartMap.put(this, true);
- }
- if (count < 0) {
- Logger.defaultLogError(
- "Database request processing error. The application code has performed illegal actions (probably called multiple times the execute or exception method of a single result request.",
- new Exception());
- System.exit(-1);
- }
- assert (count >= 0);
- }
- }
-
public static String report(AsyncBarrierImpl barrier) {
- CacheEntry<?> e = entryMap.get(barrier);
+ CacheEntry<?> e = BarrierTracing.entryMap.get(barrier);
if(e != null) return e.toString();
else return "Barrier@" + System.identityHashCode(barrier);
}
// debugger.toErr(indent + 2);
// }
- Collection<AsyncBarrierImpl> children = reverseLookup.get(barrier);
+ Collection<AsyncBarrierImpl> children = BarrierTracing.reverseLookup.get(barrier);
if (children != null) {
for (AsyncBarrierImpl child : children)
printReverse(child, indent + 2);
+ ") is taking long to execute, so far "
+ (waitCount / 1000) + " s.");
- if (BOOKKEEPING) {
-
- synchronized (reverseLookup) {
+ if (BarrierTracing.BOOKKEEPING) {
+ synchronized (BarrierTracing.reverseLookup) {
printReverse(this, 0);
}
-
}
// if(Development.DEVELOPMENT) {
public void restart() {
assertReady();
- // log.clear();
- // sema.drainPermits();
- if (RESTART_GUARD)
- restartMap.remove(this);
- if (BOOKKEEPING)
- debuggerMap.put(this, new Debugger());
+ if(BarrierTracing.BOOKKEEPING) {
+ BarrierTracing.restart(this);
+ }
}
public void assertReady() {
--- /dev/null
+package org.simantics.db.impl.graph;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.simantics.db.impl.query.CacheEntry;
+import org.simantics.db.impl.query.QueryProcessor.SessionTask;
+
+public class BarrierTracing {
+
+ public static final boolean BOOKKEEPING = false;
+ static final boolean RESTART_GUARD = BOOKKEEPING && false;
+
+ public static Map<SessionTask,Exception> tasks = new HashMap<>();
+ public static final HashMap<AsyncBarrierImpl, Collection<AsyncBarrierImpl>> reverseLookup = new HashMap<>();
+ public static final HashMap<AsyncBarrierImpl, Debugger> debuggerMap = new HashMap<>();
+ public static final HashMap<AsyncBarrierImpl, CacheEntry<?>> entryMap = new HashMap<>();
+ public static final HashMap<AsyncBarrierImpl, Throwable> restartMap = new HashMap<>();
+ public static final HashMap<AsyncBarrierImpl, Throwable> startMap = new HashMap<>();
+
+ public static void trace(AsyncBarrierImpl barrier, CacheEntry<?> entry) {
+
+ if (RESTART_GUARD) {
+ synchronized (startMap) {
+ startMap.put(barrier, new Exception());
+ }
+ }
+ synchronized (entryMap) {
+ entryMap.put(barrier, entry);
+ }
+ synchronized (debuggerMap) {
+ debuggerMap.put(barrier, new Debugger());
+ }
+ synchronized (reverseLookup) {
+ Collection<AsyncBarrierImpl> barriers = reverseLookup
+ .get(barrier.caller);
+ if (barriers == null) {
+ barriers = new ArrayList<AsyncBarrierImpl>();
+ reverseLookup.put(barrier.caller, barriers);
+ }
+ barriers.add(barrier);
+ }
+
+ }
+
+ public static void inc(AsyncBarrierImpl barrier) {
+
+ barrier.inc(barrier, new Exception().getStackTrace()[2].toString());
+
+ if (RESTART_GUARD)
+ if(restartMap.containsKey(barrier)) {
+ startMap.get(barrier).printStackTrace();
+ restartMap.get(barrier).printStackTrace();
+ new Exception().printStackTrace();
+ throw new IllegalStateException("Unplanned restart");
+ }
+
+
+ }
+
+ public static void restart(AsyncBarrierImpl barrier) {
+ if (RESTART_GUARD)
+ BarrierTracing.restartMap.remove(barrier);
+ if (BOOKKEEPING)
+ BarrierTracing.debuggerMap.put(barrier, new Debugger());
+ }
+
+ public static void dec(AsyncBarrierImpl barrier, int count) {
+ if (count == 0) {
+ if (RESTART_GUARD) {
+ restartMap.put(barrier, new Exception());
+ }
+ debuggerMap.remove(barrier);
+ }
+ else if (count < 0) {
+ BarrierTracing.startMap.get(barrier).printStackTrace();
+ BarrierTracing.restartMap.get(barrier).printStackTrace();
+ new Exception().printStackTrace();
+ }
+ }
+
+ public static class Debugger {
+
+ public Map<AsyncBarrierImpl, String> infos = new HashMap<>();
+
+ public synchronized void inc(AsyncBarrierImpl id, String info) {
+ if (id == null)
+ return;
+ String exist = infos.get(id);
+ if (exist != null)
+ throw new IllegalStateException("Already existing info " + id + " " + info);
+ infos.put(id, exist);
+ }
+
+ public synchronized void dec(AsyncBarrierImpl id) {
+ if (id == null)
+ return;
+ String exist = infos.get(id);
+ if (exist == null) {
+ System.err.println("No data for " + id);
+ } else {
+ infos.remove(id);
+ }
+ }
+
+ @Override
+ public synchronized String toString() {
+ StringBuilder b = new StringBuilder();
+ for (String s : infos.values()) {
+ b.append("info " + s + "\r\n");
+ }
+ return b.toString();
+ }
+
+ public boolean isEmpty() {
+ return infos.isEmpty();
+ }
+
+ }
+
+}
processor.schedule(new SessionTask(this) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
try {
final ListenerBase listener = getListenerBase(procedure);
QueryCache.runnerReadEntry(ReadGraphImpl.this, request, parent, listener, procedure, false);
processor.schedule(new SessionTask(this) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
try {
final ListenerBase listener = getListenerBase(procedure);
QueryCache.runnerAsyncReadEntry(ReadGraphImpl.this, request, parent, listener, procedure, false);
try {
- BlockingAsyncMultiProcedure<T> proc = new BlockingAsyncMultiProcedure<>(graph, new AsyncMultiProcedure<T>() {
+ BlockingAsyncMultiProcedure<T> proc = new BlockingAsyncMultiProcedure<>(graph.asyncBarrier, graph, new AsyncMultiProcedure<T>() {
@Override
public void execute(AsyncReadGraph graph, T result) {
import org.simantics.db.impl.BlockingAsyncProcedure;
import org.simantics.db.impl.DebugPolicy;
import org.simantics.db.impl.graph.AsyncBarrierImpl;
+import org.simantics.db.impl.graph.BarrierTracing;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.query.QueryProcessor.SessionTask;
import org.simantics.db.procedure.AsyncProcedure;
AsyncProcedure<T> procedure = entry != null ? entry : procedure_;
ReadGraphImpl queryGraph = graph.withParent(entry);
+ queryGraph.asyncBarrier.inc();
BlockingAsyncProcedure<T> proc = new BlockingAsyncProcedure<>(queryGraph.asyncBarrier, graph, null, request);
class AsyncTask extends SessionTask {
- int counter = 0;
+ int counter = 0;
T result;
DatabaseException exception;
}
@Override
- public void run(int thread) {
+ public void run0(int thread) {
if(needsToBlock) proc.waitBarrier();
if(proc.isDone()) {
+ ReadGraphImpl executeGraph = graph.withParent(graph.parent);
+ executeGraph.asyncBarrier.inc();
try {
result = (T)proc.get();
- if(procedure != null) procedure.execute(graph, result);
+ if(procedure != null) {
+ procedure.execute(executeGraph, result);
+ }
} catch (DatabaseException e) {
- if(procedure != null) procedure.exception(graph, e);
+ if(procedure != null) procedure.exception(executeGraph, e);
exception = e;
} catch (Throwable t) {
DatabaseException dbe = new DatabaseException(t);
- if(procedure != null) procedure.exception(graph, dbe);
+ if(procedure != null) procedure.exception(executeGraph, dbe);
exception = dbe;
} finally {
- if (entry != null)
- entry.performFromCache(graph, procedure_);
+ if (entry != null) {
+ // This does not throw
+ entry.performFromCache(executeGraph, procedure_);
+ }
+ executeGraph.asyncBarrier.dec();
+ executeGraph.asyncBarrier.waitBarrier(procedure, executeGraph);
}
} else {
- if(counter++ > 10000) {
- AsyncBarrierImpl.printReverse(queryGraph.asyncBarrier, 2);
- AsyncBarrierImpl caller = queryGraph.asyncBarrier.caller;
- while(caller != null) {
- System.err.println("called by " + AsyncBarrierImpl.report(caller));
- caller = caller.caller;
- }
- for(AsyncBarrierImpl ab : AsyncBarrierImpl.debuggerMap.keySet()) {
- AsyncBarrierImpl.printReverse(ab, 2);
- }
- throw new IllegalStateException("Eternal loop in queries.");
- }
- graph.processor.schedule(this);
+ if(counter++ > 10000) {
+ if(BarrierTracing.BOOKKEEPING) {
+ AsyncBarrierImpl.printReverse(queryGraph.asyncBarrier, 2);
+ AsyncBarrierImpl caller = queryGraph.asyncBarrier.caller;
+ while(caller != null) {
+ System.err.println("called by " + AsyncBarrierImpl.report(caller));
+ caller = caller.caller;
+ }
+ for(AsyncBarrierImpl ab : BarrierTracing.debuggerMap.keySet()) {
+ AsyncBarrierImpl.printReverse(ab, 2);
+ }
+ }
+ throw new IllegalStateException("Eternal loop in queries.");
+ }
+ graph.processor.schedule(new AsyncTask(graph));
}
}
}
-
- request.perform(queryGraph, proc);
-
+
+ try {
+ request.perform(queryGraph, proc);
+ } finally {
+ queryGraph.asyncBarrier.dec();
+ }
+
AsyncTask task = new AsyncTask(graph);
if(needsToBlock) task.run(0);
graph.processor.schedule(task);
return null;
}
-
+
if(task.exception != null) throw task.exception;
else return task.result;
if(entry == null) {
graph.processor.schedule(new SessionTask(graph) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
try {
runnerReadEntry(graph, r, parent, listener, procedure, needsToBlock);
} catch (DatabaseException e) {
if(entry == null) {
graph.processor.schedule(new SessionTask(graph) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
try {
runnerAsyncReadEntry(graph, r, parent, listener, procedure, needsToBlock);
} catch (DatabaseException e) {
import org.simantics.db.exception.ResourceNotFoundException;
import org.simantics.db.impl.DebugPolicy;
import org.simantics.db.impl.ResourceImpl;
+import org.simantics.db.impl.graph.BarrierTracing;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.graph.ReadGraphSupport;
import org.simantics.db.impl.graph.WriteGraphImpl;
public void close() {
}
- SessionTask getOwnTask(ReadGraphImpl impl) {
+ public SessionTask getOwnTask(ReadGraphImpl impl) {
Set<ReadGraphImpl> ancestors = impl.ancestorSet();
synchronized(querySupportLock) {
int index = 0;
return null;
}
+ public SessionTask getSubTask(ReadGraphImpl impl) {
+ Set<ReadGraphImpl> onlyThis = Collections.singleton(impl);
+ synchronized(querySupportLock) {
+ int index = 0;
+ while(index < freeScheduling.size()) {
+ SessionTask task = freeScheduling.get(index);
+ if(task.hasCommonParent(onlyThis)) {
+ return freeScheduling.remove(index);
+ }
+ index++;
+ }
+ }
+ return null;
+ }
+
public boolean performPending(ReadGraphImpl graph) {
SessionTask task = getOwnTask(graph);
if(task != null) {
// }
final public void schedule(SessionTask request) {
-
+
//int performer = request.thread;
// if(DebugPolicy.SCHEDULE)
// if(performer == THREADS) {
synchronized(querySupportLock) {
-
- //new Exception().printStackTrace();
-
+
+ if(BarrierTracing.BOOKKEEPING) {
+ Exception current = new Exception();
+ Exception previous = BarrierTracing.tasks.put(request, current);
+ if(previous != null) {
+ previous.printStackTrace();
+ current.printStackTrace();
+ }
+ }
+
freeScheduling.add(request);
querySupportLock.notifyAll();
- //System.err.println("schedule free task " + request + " => " + freeScheduling.size());
-
-// for(int i=0;i<THREADS;i++) {
-// ReentrantLock queueLock = threadLocks[i];
-// queueLock.lock();
-// //queues[performer].add(request);
-// //if(ThreadState.SLEEP == threadStates[i]) sleepers.decrementAndGet();
-// threadConditions[i].signalAll();
-// queueLock.unlock();
-// }
-
}
return;
public final ReadGraphImpl graph;
private Set<ReadGraphImpl> ancestors;
+ private int counter = 0;
+ private Exception trace;
public SessionTask(ReadGraphImpl graph) {
this.graph = graph;
+ if(graph != null) graph.asyncBarrier.inc();
}
public boolean hasCommonParent(Set<ReadGraphImpl> otherAncestors) {
return !Collections.disjoint(ancestors, otherAncestors);
}
- public abstract void run(int thread);
+ public abstract void run0(int thread);
+
+ public final void run(int thread) {
+ if(counter++ > 0) {
+ if(BarrierTracing.BOOKKEEPING) {
+ trace.printStackTrace();
+ new Exception().printStackTrace();
+ }
+ throw new IllegalStateException("Multiple invocations of SessionTask!");
+ }
+ if(BarrierTracing.BOOKKEEPING) {
+ trace = new Exception();
+ }
+ run0(thread);
+ if(graph != null) graph.asyncBarrier.dec();
+ }
@Override
public String toString() {
AsyncProcedure<T> procedure = entry != null ? entry : procedure_;
ReadGraphImpl queryGraph = graph.withParent(entry);
+ queryGraph.asyncBarrier.inc();
+ ReadGraphImpl executeGraph = graph.withParent(graph.parent);
+ executeGraph.asyncBarrier.inc();
+
try {
+ // This throws
T result = request.perform(queryGraph);
- if(procedure != null) procedure.execute(graph, result);
+
+ if(procedure != null) procedure.execute(executeGraph, result);
return (T)result;
} catch (DatabaseException e) {
- if(procedure != null) procedure.exception(graph, e);
+ if(procedure != null) procedure.exception(executeGraph, e);
throw e;
} catch (Throwable t) {
DatabaseException dbe = new DatabaseException(t);
- if(procedure != null) procedure.exception(graph, dbe);
+ if(procedure != null) procedure.exception(executeGraph, dbe);
throw dbe;
} finally {
- if (entry != null)
- entry.performFromCache(queryGraph, procedure_);
+ queryGraph.asyncBarrier.dec();
+
+ try {
+
+ if (entry != null) {
+ // This also throws so must dec barrier finally
+ entry.performFromCache(executeGraph, procedure_);
+ }
+
+ } finally {
+
+ executeGraph.asyncBarrier.dec();
+ executeGraph.asyncBarrier.waitBarrier(procedure, executeGraph);
+ }
+
+
}
}
requestManager.scheduleWrite(new SessionTask(null) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
if(Development.DEVELOPMENT) {
try {
requestManager.scheduleWrite(new SessionTask(null) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
ITask task = ThreadLogger.getInstance().begin("WriteRequest " + request);
requestManager.scheduleWrite(new SessionTask(null) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
fireSessionVariableChange(SessionVariables.QUEUED_READS);
Procedure<Object> stateProcedure = new Procedure<Object>() {
requestManager.scheduleWrite(new SessionTask(null) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
ITask task = ThreadLogger.getInstance().begin("WriteRequest " + request);
requestManager.scheduleWrite(new SessionTask(null) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
ITask task = ThreadLogger.getInstance().begin("WriteRequest " + request);
requestManager.scheduleRead(new SessionRead(throwable, notify) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
fireSessionVariableChange(SessionVariables.QUEUED_READS);
final ReadGraphImpl newGraph = ReadGraphImpl.create(getQueryProvider2());
+ // This is never synced but increase to prevent it from visiting 0
+ newGraph.asyncBarrier.inc();
+
try {
if (listener != null) {
requestManager.scheduleRead(new SessionRead(null, notify) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
fireSessionVariableChange(SessionVariables.QUEUED_READS);
requestManager.scheduleRead(new SessionRead(null, notify) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
fireSessionVariableChange(SessionVariables.QUEUED_READS);
requestManager.scheduleRead(new SessionRead(null, notify) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
fireSessionVariableChange(SessionVariables.QUEUED_READS);
requestManager.scheduleRead(new SessionRead(throwable, notify) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
fireSessionVariableChange(SessionVariables.QUEUED_READS);
session.queryProvider2.schedule(new SessionTask(null) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
try {
transactionState.startReadTransaction(thread);
task.run(thread);
session.queryProvider2.schedule(new SessionTask(null) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
session.fireFinishReadTransaction();
session.queryProvider2.schedule(new SessionTask(null) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
try {
transactionState.startWriteTransaction(thread);
session.queryProvider2.schedule(new SessionTask(null) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
// Support for DelayedWriteRequest cancels during the
// read-only part of the request.
session.queryProvider2.schedule(new SessionTask(null) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
read.run(thread);
if(read.notify != null) read.notify.release();
}
session.queryProvider2.schedule(new SessionTask(null) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
try {
task.run(thread);
} finally {
final TaskHelper th = new TaskHelper("Undo");
session.requestManager.scheduleWrite(new SessionTask(null) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
session.flushCounter = 0;
session.clusterStream.reallyFlush();
ClientChangesImpl cs = new ClientChangesImpl(session);
import org.simantics.db.common.procedure.adapter.CacheListener;
import org.simantics.db.common.procedure.adapter.ListenerSupport;
import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
+import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.common.request.AsyncReadRequest;
import org.simantics.db.common.request.ReadRequest;
import org.simantics.db.common.session.SessionEventListenerAdapter;
task4.finish();
// ITask task5 = ThreadLogger.getInstance().begin("DiagramContentRequest2");
ITask task42 = ThreadLogger.getInstance().begin("DiagramContentRequest2");
- DiagramContents contents = g.syncRequest(query);
+ DiagramContents contents = g.syncRequest(query, TransientCacheAsyncListener.instance());
//System.err.println("contents: " + contents);
task42.finish();
// task5.finish();
}
public void clear() {
- // Prevent DiagramContents leakage through DisposableListeners.
- lastContent = null;
- content = null;
- changes = null;
-
+ // Prevent DiagramContents leakage through DisposableListeners.
+ lastContent = null;
+ content = null;
+ changes = null;
+
this.addedElements.clear();
this.removedElements.clear();
this.addedConnectionSegments.clear();
// TODO: Connection loading has no listening, changes :Connection will not be noticed by this code!
Listener<IElement> loadListener = new DisposableListener<IElement>(canvasListenerSupport) {
- @Override
- public String toString() {
- return "Connection load listener for " + element;
- }
+
+ boolean firstTime = true;
+
+ @Override
+ public String toString() {
+ return "Connection load listener for " + element;
+ }
@Override
public void execute(IElement loaded) {
// Invoked when the element has been loaded.
return;
}
+ if (firstTime) {
+
+ mapElement(element, loaded);
+ synchronized (GraphToDiagramUpdater.this) {
+ addedElements.add(loaded);
+ addedElementMap.put(element, loaded);
+ addedConnectionMap.put(element, loaded);
+ }
+
+ firstTime = false;
+
+ }
+
Object data = loaded.getHint(ElementHints.KEY_OBJECT);
// Logic for disposing listener
graph.syncRequest(new ConnectionRequest(canvas, diagram, element, errorHandler, loadListener), new AsyncProcedure<IElement>() {
@Override
public void execute(AsyncReadGraph graph, final IElement e) {
- if (e == null)
- return;
-
- //System.out.println("ConnectionRequestProcedure " + e);
- mapElement(element, e);
- synchronized (GraphToDiagramUpdater.this) {
- addedElements.add(e);
- addedElementMap.put(element, e);
- addedConnectionMap.put(element, e);
- }
// Read connection type
graph.forSingleType(element, br.DIA.Connection, new Procedure<Resource>() {
}
}
});
+
}
@Override
} else if (content.nodeSet.contains(element)) {
Listener<IElement> loadListener = new DisposableListener<IElement>(canvasListenerSupport) {
- @Override
- public String toString() {
- return "Node load listener for " + element;
- }
+
+ boolean firstTime = true;
+
+ @Override
+ public String toString() {
+ return "Node load listener for " + element;
+ }
@Override
public void execute(IElement loaded) {
// Invoked when the element has been loaded.
return;
}
+ if (firstTime) {
+
+ // This is invoked before the element is actually loaded.
+ //System.out.println("NodeRequestProcedure " + e);
+ if (DebugPolicy.DEBUG_NODE_LOAD)
+ System.out.println("MAPPING ADDED NODE: " + element + " -> " + loaded);
+ mapElement(element, loaded);
+ synchronized (GraphToDiagramUpdater.this) {
+ addedElements.add(loaded);
+ addedElementMap.put(element, loaded);
+ }
+
+ firstTime = false;
+
+ }
+
Object data = loaded.getHint(ElementHints.KEY_OBJECT);
// Logic for disposing listener
graph.syncRequest(new NodeRequest(canvas, diagram, element, loadListener), new AsyncProcedure<IElement>() {
@Override
public void execute(AsyncReadGraph graph, IElement e) {
- if (e == null)
- return;
-
- // This is invoked before the element is actually loaded.
- //System.out.println("NodeRequestProcedure " + e);
- if (DebugPolicy.DEBUG_NODE_LOAD)
- System.out.println("MAPPING ADDED NODE: " + element + " -> " + e);
- mapElement(element, e);
- synchronized (GraphToDiagramUpdater.this) {
- addedElements.add(e);
- addedElementMap.put(element, e);
- }
}
@Override
continue;
Listener<IElement> loadListener = new DisposableListener<IElement>(canvasListenerSupport) {
- @Override
- public String toString() {
- return "processRouteGraphConnections " + connection;
- }
+
+ boolean firstTime = true;
+
+ @Override
+ public String toString() {
+ return "processRouteGraphConnections " + connection;
+ }
@Override
public void execute(IElement loaded) {
// Invoked when the element has been loaded.
return;
}
+ if(firstTime) {
+ if (DebugPolicy.DEBUG_NODE_LOAD)
+ System.out.println("MAPPING ADDED ROUTE GRAPH CONNECTION: " + connection + " -> " + loaded);
+ mapElement(connection, loaded);
+ synchronized (GraphToDiagramUpdater.this) {
+ addedElements.add(loaded);
+ addedElementMap.put(connection, loaded);
+ addedRouteGraphConnectionMap.put(connection, loaded);
+ }
+ firstTime = false;
+ }
+
Object data = loaded.getHint(ElementHints.KEY_OBJECT);
// Logic for disposing listener
graph.syncRequest(new ConnectionRequest(canvas, diagram, connection, errorHandler, loadListener), new Procedure<IElement>() {
@Override
public void execute(final IElement e) {
- if (e == null)
- return;
-
- //System.out.println("ConnectionRequestProcedure " + e);
- if (DebugPolicy.DEBUG_NODE_LOAD)
- System.out.println("MAPPING ADDED ROUTE GRAPH CONNECTION: " + connection + " -> " + e);
- mapElement(connection, e);
- synchronized (GraphToDiagramUpdater.this) {
- addedElements.add(e);
- addedElementMap.put(connection, e);
- addedRouteGraphConnectionMap.put(connection, e);
- }
}
@Override
public void exception(Throwable throwable) {
});
Listener<IElement> loadListener = new DisposableListener<IElement>(canvasListenerSupport) {
- @Override
- public String toString() {
- return "processBranchPoints for " + element;
- }
+
+ boolean firstTime = true;
+
+ @Override
+ public String toString() {
+ return "processBranchPoints for " + element;
+ }
@Override
public void execute(IElement loaded) {
// Invoked when the element has been loaded.
return;
}
+ if (firstTime) {
+
+ mapElement(element, loaded);
+ synchronized (GraphToDiagramUpdater.this) {
+ addedBranchPoints.add(loaded);
+ addedElementMap.put(element, loaded);
+ ConnectionEntityImpl ce = getConnectionEntity(element);
+ loaded.setHint(ElementHints.KEY_CONNECTION_ENTITY, ce);
+ loaded.setHint(ElementHints.KEY_PARENT_ELEMENT, ce.getConnectionElement());
+ }
+
+ firstTime = false;
+
+ }
+
Object data = loaded.getHint(ElementHints.KEY_OBJECT);
if (addedElementMap.containsKey(data)) {
// This element was just loaded, in
graph.syncRequest(new NodeRequest(canvas, diagram, element, loadListener), new AsyncProcedure<IElement>() {
@Override
public void execute(AsyncReadGraph graph, IElement e) {
- if (e != null) {
- mapElement(element, e);
- synchronized (GraphToDiagramUpdater.this) {
- addedBranchPoints.add(e);
- addedElementMap.put(element, e);
- ConnectionEntityImpl ce = getConnectionEntity(element);
- e.setHint(ElementHints.KEY_CONNECTION_ENTITY, ce);
- e.setHint(ElementHints.KEY_PARENT_ELEMENT, ce.getConnectionElement());
- }
- }
}
@Override
return "defaultConnectionSegmentAdapter";
}
}, new DisposableListener<IElement>(listenerSupport) {
-
- @Override
- public String toString() {
- return "DefaultConnectionSegmentAdapter listener for " + edge;
- }
-
+
+ @Override
+ public String toString() {
+ return "DefaultConnectionSegmentAdapter listener for " + edge;
+ }
+
@Override
public void execute(IElement loaded) {
// Invoked when the element has been loaded.
GraphToDiagramUpdater updater = new GraphToDiagramUpdater(lastContent, content, changes);
GraphToDiagramSynchronizer.this.currentUpdater = updater;
try {
- updater.process(graph);
+ updater.process(graph);
} finally {
- GraphToDiagramSynchronizer.this.currentUpdater = null;
+ GraphToDiagramSynchronizer.this.currentUpdater = null;
}
Timing.END(task);