/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2018 Association for Decentralized Information Management
* in Industry THTH ry.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
import java.util.ArrayList;
import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
import org.simantics.db.common.exception.DebugException;
+import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.impl.query.QueryProcessor.AsyncBarrier;
import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.SyncMultiProcedure;
import org.simantics.db.request.MultiRead;
import org.simantics.db.request.RequestFlags;
-import org.simantics.utils.datastructures.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-final public class MultiReadEntry<T> extends CacheEntryBase {
+public final class MultiReadEntry<T> extends CacheEntryBase<SyncMultiProcedure<T>> {
-// public ArrayList<Pair<AsyncMultiProcedure<T>, AsyncBarrier>> procs;
+ private static final Logger LOGGER = LoggerFactory.getLogger(MultiReadEntry.class);
protected MultiRead<T> request;
- public MultiReadEntry(MultiRead<T> request) {
+ MultiReadEntry(MultiRead<T> request) {
this.request = request;
}
setResult(null);
}
- synchronized public void finish(AsyncReadGraph graph) {
+ synchronized public void finish(ReadGraph graph) {
assert(isPending());
- ArrayList<Pair<AsyncMultiProcedure<T>, AsyncBarrier>> p = null;
-
- synchronized(this) {
-
+ synchronized(this) {
setReady();
-
-// p = procs;
-// procs = null;
-
}
-// if(p != null) {
-// ArrayList<T> v = (ArrayList<T>)getResult();
-// if(v != null) {
-// for(Pair<AsyncMultiProcedure<T>, AsyncBarrier> pair : p) {
-// for(T t : v) pair.first.execute(graph, t);
-// }
-// }
-// for(Pair<AsyncMultiProcedure<T>, AsyncBarrier> pair : p) {
-// pair.first.finished(graph);
-// pair.second.dec();
-// }
-// }
-
}
@Override
return new Query() {
@Override
- public void recompute(ReadGraphImpl graph, Object provider, CacheEntry entry) {
+ public void recompute(ReadGraphImpl graph) {
- QueryProcessor qp = (QueryProcessor)provider;
-
- final ReadGraphImpl parentGraph = ReadGraphImpl.forRecompute(entry, qp);
-// parentGraph.state.barrier.inc();
-
try {
- request.perform(parentGraph , new AsyncMultiProcedure<T>() {
+ request.perform(graph , new SyncMultiProcedure<T>() {
@Override
- public void execute(AsyncReadGraph graph, T result) {
+ public void execute(ReadGraph graph, T result) {
addOrSet(result);
-// parentGraph.state.barrier.dec();
}
- public void finished(AsyncReadGraph graph) {
+ public void finished(ReadGraph graph) {
finish(graph);
-// parentGraph.state.barrier.dec();
};
@Override
- public void exception(AsyncReadGraph graph, Throwable t) {
+ public void exception(ReadGraph graph, Throwable t) {
except(t);
-// parentGraph.state.barrier.dec();
}
});
-// parentGraph.waitAsync(request);
-
} catch (Throwable t) {
except(t);
-// parentGraph.state.barrier.dec();
if(DebugException.DEBUG) new DebugException(t).printStackTrace();
}
@Override
public void removeEntry(QueryProcessor processor) {
- processor.multiReadMap.remove(request);
+ processor.cache.remove(MultiReadEntry.this);
}
@Override
try {
proc.exception(graph, (Throwable)getResult());
} catch (Throwable t) {
- t.printStackTrace();
+ LOGGER.error("performFromCache proc.exception failed", t);
}
// parentBarrier.dec();
try {
proc.execute(graph, value);
} catch (Throwable t) {
- t.printStackTrace();
+ LOGGER.error("performFromCache proc.execute failed", t);
}
}
try {
proc.finished(graph);
} catch (Throwable t) {
- t.printStackTrace();
+ LOGGER.error("performFromCache proc.finished failed", t);
}
// parentBarrier.dec();
}
}
-
- @Override
- public void performFromCache(ReadGraphImpl graph, Object provider,
- Object procedure) {
-
- final AsyncMultiProcedure<T> proc = (AsyncMultiProcedure<T>)procedure;
+
+ @Override
+ public Object performFromCache(ReadGraphImpl graph, SyncMultiProcedure<T> proc) {
if(isExcepted()) {
try {
proc.exception(graph, (Throwable)getResult());
} catch (Throwable t) {
- t.printStackTrace();
+ LOGGER.error("performFromCache(Sync) proc.exception failed", t);
}
} else {
try {
proc.execute(graph, value);
} catch (Throwable t) {
- t.printStackTrace();
+ LOGGER.error("performFromCache(Sync) proc.execute failed", t);
}
}
try {
proc.finished(graph);
} catch (Throwable t) {
- t.printStackTrace();
+ LOGGER.error("performFromCache(Sync) proc.finished failed", t);
}
}
-
-
-
+
+ return null;
+
}
-
+
@Override
public String toString() {
if(request == null) return "DISCARDED";
else return request.toString() + statusOrException;
}
+ public Object compute(ReadGraphImpl graph, SyncMultiProcedure<T> procedure) throws DatabaseException {
+ return graph.processor.cache.performQuery(graph, request, this, procedure);
+ }
+
}