ge.getCache().decRef(context);
}
+ public void execFromQuery(Runnable runnable) {
+ ge.execFromQuery(runnable);
+ }
+
}
int getActivityInt();
void scheduleQueryUpdate(Runnable r);
+ void execFromQuery(Runnable r);
}
protected Boolean hasChildren = Viewpoint.PENDING_HAS_CHILDREN;
final public void setChildren(PrimitiveQueryUpdater updater, NodeContext[] children) {
+
if (children == null)
throw new NullPointerException(this + ": null children produced by " + getClass().getName());
- for(NodeContext c : children) updater.incRef(c);
- for(NodeContext c : this.children) updater.decRef(c);
+
+ final NodeContext[] currentChildren = this.children;
+
+ updater.execFromQuery(new Runnable() {
+
+ @Override
+ public void run() {
+ for(NodeContext c : children) updater.incRef(c);
+ for(NodeContext c : currentChildren) updater.decRef(c);
+ }
+
+ });
this.children = children;
}
}
}
+ @Override
+ public void execFromQuery(java.lang.Runnable r) {
+ ge.queryUpdateScheduler.execute(r);
+ }
+
Runnable QUERY_UPDATE_SCHEDULER = new Runnable() {
@Override
public void run() {
queryUpdateScheduler.execute(QUERY_UPDATE_SCHEDULER);
}
}
+
+ @Override
+ public void execFromQuery(java.lang.Runnable r) {
+ queryUpdateScheduler.execute(r);
+ }
Runnable QUERY_UPDATE_SCHEDULER = new Runnable() {
@Override
}
}
+ @Override
+ public void execFromQuery(java.lang.Runnable r) {
+ ge.queryUpdateScheduler.execute(r);
+ }
+
Runnable QUERY_UPDATE_SCHEDULER = new Runnable() {
@Override
public void run() {
void incRef(NodeContext context);
void decRef(NodeContext context);
+
+ void execFromQuery(Runnable runnable);
}
\ No newline at end of file
org.simantics.db.common.internal.config;x-friends:="org.simantics.db.procore",
org.simantics.db.common.issue,
org.simantics.db.common.primitiverequest,
+ org.simantics.db.common.procedure,
org.simantics.db.common.procedure.adapter,
org.simantics.db.common.procedure.guarded,
org.simantics.db.common.procedure.single,
*******************************************************************************/
package org.simantics.db.common.primitiverequest;
-import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
-import org.simantics.db.procedure.AsyncProcedure;
-import org.simantics.db.request.AsyncRead;
+import org.simantics.db.adaption.AdaptionService;
+import org.simantics.db.common.request.BinaryRead;
+import org.simantics.db.exception.DatabaseException;
-final public class PossibleAdapter<T> implements AsyncRead<T> {
+final public class PossibleAdapter<T> extends BinaryRead<Resource,Class<T>, T> {
- final private Resource resource;
- final private Class<T> clazz;
-
- @Override
- public int hashCode() {
- return resource.hashCode() + 31 * clazz.hashCode();
- }
-
- @Override
- public boolean equals(Object object) {
- if (this == object)
- return true;
- else if (object == null)
- return false;
- else if (getClass() != object.getClass())
- return false;
- PossibleAdapter<?> r = (PossibleAdapter<?>)object;
- return resource.equals(r.resource) && clazz.equals(r.clazz);
- }
-
- @Override
- public int threadHash() {
- return hashCode();
- }
-
- @Override
- public int getFlags() {
- return 0;
- }
-
public PossibleAdapter(Resource resource, Class<T> clazz) {
- this.resource = resource;
- this.clazz = clazz;
+ super(resource, clazz);
}
@Override
- public void perform(AsyncReadGraph graph, AsyncProcedure<T> procedure) {
-
- graph.forPossibleAdapted(resource, clazz, procedure);
-
+ public T perform(ReadGraph graph) throws DatabaseException {
+
+ final AdaptionService service = graph.peekService(AdaptionService.class);
+ return service.adapt(graph, parameter, parameter, Resource.class, parameter2, true);
+
}
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common.procedure;
+
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.AsyncProcedure;
+
+public class BlockingAsyncProcedure<Result> implements AsyncProcedure<Result> {
+
+ final private Object key;
+ private Result result = null;
+ private Throwable exception = null;
+ final private AsyncProcedure<Result> procedure;
+ final private Semaphore semaphore = new Semaphore(0);
+// final private AtomicBoolean latch;
+
+ public BlockingAsyncProcedure(AsyncProcedure<Result> procedure, Object key) {
+// assert(procedure != null);
+ this.key = key;
+ this.procedure = procedure;
+ if(key == null)
+ System.err.println("asd");
+ //System.err.println("BlockingAsyncProcedure " + key);
+// latch = new AtomicBoolean(false);
+ }
+
+ @Override
+ public void execute(AsyncReadGraph graph, Result result) {
+ this.result = result;
+ semaphore.release();
+// if(latch.compareAndSet(false, true)) {
+ try {
+ if(procedure != null) procedure.execute(graph, result);
+ } catch (Throwable throwable) {
+ Logger.defaultLogError("AsyncProcedure.execute threw for " + procedure, throwable);
+ }
+// } finally {
+//// System.err.println("ResultCallWrappedSingleQueryProcedure4 dec " + key);
+// }
+// } else {
+// Logger.defaultLogError("Procedure was called many times (this time is execute)");
+// }
+ }
+
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable t) {
+ this.exception = t;
+ semaphore.release();
+// if(latch.compareAndSet(false, true)) {
+ try {
+ if(procedure != null) procedure.exception(graph, t);
+ } catch (Throwable throwable) {
+ Logger.defaultLogError("AsyncProcedure.exception threw for " + procedure, throwable);
+ } finally {
+ }
+// } else {
+// Logger.defaultLogError("Procedure was called many times (this time is exception)");
+// }
+
+ }
+
+ public Result get() throws DatabaseException {
+
+ try {
+ boolean success = semaphore.tryAcquire(10, TimeUnit.SECONDS);
+ if(!success) throw new DatabaseException("Timeout while waiting for async request to complete: " + key);
+ } catch (InterruptedException e) {
+ throw new DatabaseException(e);
+ }
+
+ if(exception != null) {
+ if(exception instanceof DatabaseException) throw (DatabaseException)exception;
+ throw new DatabaseException(exception);
+ } else {
+ return result;
+ }
+
+ }
+
+ public Result getResult() {
+ return result;
+ }
+
+ public Throwable getException() {
+ return exception;
+ }
+
+ @Override
+ public String toString() {
+ return "." + procedure;
+ }
+
+}
if(Development.DEVELOPMENT) {
impl.processor.threadLocks[0].lock();
- System.err.println("-queues=" + impl.processor.queues[0].size());
+// System.err.println("-queues=" + impl.processor.queues[0].size());
impl.processor.threadLocks[0].unlock();
- System.err.println("-own=" + impl.processor.ownTasks[0].size());
- System.err.println("-ownSync=" + impl.processor.ownSyncTasks[0].size());
- for(SessionTask task : impl.processor.ownSyncTasks[0]) {
- System.err.println("--" + task);
- }
+// System.err.println("-own=" + impl.processor.ownTasks[0].size());
+// System.err.println("-ownSync=" + impl.processor.ownSyncTasks[0].size());
+// for(SessionTask task : impl.processor.ownSyncTasks[0]) {
+// System.err.println("--" + task);
+// }
}
import org.simantics.db.common.primitiverequest.Value;
import org.simantics.db.common.primitiverequest.ValueImplied;
import org.simantics.db.common.primitiverequest.VariantValueImplied;
+import org.simantics.db.common.procedure.BlockingAsyncProcedure;
import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter;
import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.impl.internal.RandomAccessValueSupport;
import org.simantics.db.impl.internal.ResourceData;
import org.simantics.db.impl.procedure.CallWrappedSingleQueryProcedure4;
+import org.simantics.db.impl.procedure.InternalProcedure;
import org.simantics.db.impl.procedure.ResultCallWrappedQueryProcedure4;
import org.simantics.db.impl.procedure.ResultCallWrappedSingleQueryProcedure4;
import org.simantics.db.impl.query.CacheEntry;
import org.simantics.db.impl.query.QueryProcessor;
import org.simantics.db.impl.query.QuerySupport;
import org.simantics.db.impl.query.TripleIntProcedure;
+import org.simantics.db.impl.query.QueryProcessor.SessionTask;
import org.simantics.db.impl.support.ResourceSupport;
import org.simantics.db.procedure.AsyncListener;
import org.simantics.db.procedure.AsyncMultiListener;
try {
- return syncRequest(new org.simantics.db.common.primitiverequest.Resource(
- id));
+// assert (id != null);
+// assert (procedure != null);
+//
+// processor.forResource(this, id, procedure);
+//
+//// return syncRequest(new org.simantics.db.common.primitiverequest.Resource(
+//// id));
+
+ Integer rid = QueryCache.resultURIToResource(this, id, parent, null);
+ if(rid == 0) throw new ResourceNotFoundException(id);
+ return processor.querySupport.getResource(rid);
} catch (ResourceNotFoundException e) {
try {
- return syncRequest(new org.simantics.db.common.primitiverequest.Resource(
- id));
+ return getResource(id);
+
+// return syncRequest(new org.simantics.db.common.primitiverequest.Resource(
+// id));
} catch (ResourceNotFoundException e) {
throws DatabaseException {
assert (request != null);
- AsyncReadProcedure<T> procedure = new AsyncReadProcedure<T>();
- syncRequest(request, procedure);
- procedure.checkAndThrow();
- return procedure.result;
+// AsyncReadProcedure<T> procedure = new AsyncReadProcedure<T>();
+ BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(null, request);
+ syncRequest(request, ap);
+ return ap.get();
+// procedure.checkAndThrow();
+// return procedure.result;
// return syncRequest(request, new AsyncProcedureAdapter<T>());
ListenerBase listener = getListenerBase(procedure);
- final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
- procedure, request);
+ BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(procedure, request);
+
+// final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
+// procedure, request);
- QueryCache.runnerAsyncReadEntry(this, request, parent, listener, wrapper);
+ QueryCache.runnerAsyncReadEntry(this, request, parent, listener, ap, true);
//processor.query(this, request, parent, wrapper, listener);
- return wrapper.getResult();
+ return ap.get();
+
+// return wrapper.getResult();
// if (parent != null || listener != null || ((request.getFlags() & RequestFlags.SCHEDULE) > 0)) {
//
ListenerBase listener = getListenerBase(procedure);
assert(listener == null);
+ BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(procedure, request);
+
// final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
// procedure, request);
- QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure);
+ QueryCache.runnerAsyncReadEntry(this, request, parent, listener, ap, true);
+
+ ap.get();
}
assert (request != null);
assert (procedure != null);
+
+ processor.schedule(Integer.MIN_VALUE, new SessionTask(request, processor.THREAD_MASK+1, -1) {
- final ListenerBase listener = getListenerBase(procedure);
-
- if (parent != null || listener != null) {
-
- try {
- QueryCache.runnerReadEntry(this, request, parent, listener, procedure);
- //processor.query(this, request, parent, procedure,listener);
- } catch (DatabaseException e) {
- Logger.defaultLogError(e);
- // This throwable has already been transferred to procedure at this point - do nothing about it
- //
- }
-
- } else {
-
-// final ReadGraphImpl newGraph = newSync();
-
- try {
-
- T result = request.perform(this);
-
- try {
- procedure.execute(this, result);
- } catch (Throwable t) {
- Logger.defaultLogError(t);
- }
-
- } catch (Throwable t) {
-
+ @Override
+ public void run(int thread) {
try {
- procedure.exception(this, t);
- } catch (Throwable t2) {
- Logger.defaultLogError(t2);
+ final ListenerBase listener = getListenerBase(procedure);
+ QueryCache.runnerReadEntry(ReadGraphImpl.this, request, parent, listener, procedure, false);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
}
-
- } finally {
-
}
+
+ });
- }
+
+// quer
+//
+// final ListenerBase listener = getListenerBase(procedure);
+//
+// if (parent != null || listener != null) {
+//
+// try {
+// QueryCache.runnerReadEntry(this, request, parent, listener, procedure);
+// //processor.query(this, request, parent, procedure,listener);
+// } catch (DatabaseException e) {
+// Logger.defaultLogError(e);
+// // This throwable has already been transferred to procedure at this point - do nothing about it
+// //
+// }
+//
+// } else {
+//
+//// final ReadGraphImpl newGraph = newSync();
+//
+// try {
+//
+// T result = request.perform(this);
+//
+// try {
+// procedure.execute(this, result);
+// } catch (Throwable t) {
+// Logger.defaultLogError(t);
+// }
+//
+// } catch (Throwable t) {
+//
+// try {
+// procedure.exception(this, t);
+// } catch (Throwable t2) {
+// Logger.defaultLogError(t2);
+// }
+//
+// } finally {
+//
+// }
+//
+// }
}
assert (request != null);
assert (procedure != null);
- final ListenerBase listener = getListenerBase(procedure);
+ //final ListenerBase listener = getListenerBase(procedure);
- if (parent != null || listener != null) {
+ processor.schedule(Integer.MIN_VALUE, new SessionTask(request, processor.THREAD_MASK+1, -1) {
- try {
- QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure);
- //processor.query(this, request, parent, procedure, listener);
- } catch (DatabaseException e) {
- Logger.defaultLogError(e);
+ @Override
+ public void run(int thread) {
+ try {
+ final ListenerBase listener = getListenerBase(procedure);
+ QueryCache.runnerAsyncReadEntry(ReadGraphImpl.this, request, parent, listener, procedure, false);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ }
}
+
+ });
- } else {
-
- try {
-
- request.perform(this, new CallWrappedSingleQueryProcedure4<T>(procedure, request));
-
- } catch (Throwable t) {
-
- if (t instanceof DatabaseException)
- procedure.exception(this, t);
- else
- procedure
- .exception(
- this,
- new DatabaseException(
- "Unexpected exception in ReadGraph.asyncRequest(SingleAsyncRead, SingleProcedure)",
- t));
+
- }
- }
+// if (parent != null || listener != null) {
+//
+// try {
+// QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure);
+// //processor.query(this, request, parent, procedure, listener);
+// } catch (DatabaseException e) {
+// Logger.defaultLogError(e);
+// }
+//
+// } else {
+//
+// try {
+//
+// request.perform(this, new CallWrappedSingleQueryProcedure4<T>(procedure, request));
+//
+// } catch (Throwable t) {
+//
+// if (t instanceof DatabaseException)
+// procedure.exception(this, t);
+// else
+// procedure
+// .exception(
+// this,
+// new DatabaseException(
+// "Unexpected exception in ReadGraph.asyncRequest(SingleAsyncRead, SingleProcedure)",
+// t));
+//
+// }
+//
+// }
}
Layer0 b = getBuiltins();
initBuiltinValues(b);
+ if(resource.toString().equals("[id=$319492]") && predicate.toString().equals("[id=$235477]"))
+ System.err.println("foobar2");
+
+
Statement literalStatement = getPossibleStatement(resource, predicate);
if(literalStatement != null && resource.equals(literalStatement.getSubject())) {
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, final IntProcedure proc) throws DatabaseException {
QueryProcessor processor = graph.processor;
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, final TripleIntProcedure procedure) throws DatabaseException {
computeForEach(graph, r1(), r2(), this, procedure);
return getResult();
else return request.toString() + statusOrException;
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, AsyncMultiProcedure<T> procedure) throws DatabaseException {
return graph.processor.cache.performQuery(graph, request, this, procedure);
}
final public void addOrSet(AsyncReadGraph graph, Object item) {
+// System.err.println("addOrSet " + request + " " + Thread.currentThread() + " " + item);
+
assert(isPending());
synchronized(this) {
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
ReadGraphImpl queryGraph = graph.withParent(this);
throw new Error("Not possible!");
}
- @Override
- public Object compute(ReadGraphImpl graph, Procedure procedure) throws DatabaseException {
- throw new Error("Not possible!");
- }
-
@Override
Object performFromCache(ReadGraphImpl graph, Procedure procedure) throws DatabaseException {
throw new Error("Not possible!");
public CacheEntryBase() {
}
- abstract public Object compute(ReadGraphImpl graph, Procedure procedure) throws DatabaseException;
+ //abstract public Object compute(ReadGraphImpl graph, Procedure procedure) throws DatabaseException;
}
provider.cache.remove(this);
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, final InternalProcedure<ObjectResourceIdMap<String>> procedure) throws DatabaseException {
computeForEach(graph, id, this, procedure);
return getResult();
content.append("\n");
}
- public void generateQuery(StringBuilder content, String clazz, String[] signature, boolean runnerShortcut) {
- generateGetOrCreate(content, clazz, signature);
+ public void generateQuery(StringBuilder content, String clazz, String[] signature, boolean runnerShortcut, boolean genAsync) {
+ generateGetOrCreate(content, clazz, signature, genAsync);
generateRemove(content, clazz, signature);
- generateRunner(content, clazz, signature, runnerShortcut);
+ generateRunner(content, clazz, signature, runnerShortcut, genAsync);
}
- public void generateRunner(StringBuilder content, String clazz, String[] signature, boolean shortcut) {
+ public void generateRunner(StringBuilder content, String clazz, String[] signature, boolean shortcut, boolean genAsync) {
- line(content, "public static void runner" + clazz + "(ReadGraphImpl graph, " + signature[0] + ", CacheEntry parent, ListenerBase listener, " + signature[4] + " procedure) throws DatabaseException {");
+ line(content, "public static void runner" + clazz + "(ReadGraphImpl graph, " + signature[0] + ", CacheEntry parent, ListenerBase listener, final " + signature[4] + " procedure" + (genAsync ? ", boolean isSync" : "") + ") throws DatabaseException {");
line(content, " QueryCache cache = graph.processor.cache;");
if(shortcut) {
line(content, " if(parent == null && listener == null && !cache.shouldCache(graph.processor, " + signature[1] + ")) {");
line(content, " return;");
line(content, " }");
}
- line(content, " if(procedure == null) procedure = emptyProcedure" + clazz + ";");
- line(content, " " + clazz + " entry = (" + clazz + ")cache.getOrCreate" + clazz + "(" + signature[1] + ");");
- line(content, " ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);");
- line(content, " if(entry.isReady()) entry.performFromCache(graph, procedure);");
+ line(content, " " + clazz + " entry = (" + clazz + ")cache.getOrCreate" + clazz + "(" + signature[1] + (genAsync ? ", isSync" : "") + ");");
+ if(genAsync) {
+ line(content, " if(entry == null) {");
+ line(content, " graph.processor.schedule(Integer.MIN_VALUE, new SessionTask(r, graph.processor.THREAD_MASK+1, -1) {");
+ line(content, " @Override");
+ line(content, " public void run(int thread) {");
+ line(content, " try {");
+ line(content, " assert(!isSync);");
+ line(content, " runner" + clazz + "(graph, r, parent, listener, procedure, isSync);");
+ line(content, " } catch (DatabaseException e) {");
+ line(content, " Logger.defaultLogError(e);");
+ line(content, " }");
+ line(content, " }");
+ line(content, " });");
+ line(content, " return;");
+ line(content, " }");
+ }
+ line(content, " " + signature[4] + " procedure_ = procedure != null ? procedure : emptyProcedure" + clazz + ";");
+ line(content, " ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);");
+ line(content, " if(entry.isReady()) entry.performFromCache(graph, procedure_);");
line(content, " else {");
- if(shortcut) line(content, " " + clazz + ".computeForEach(graph, " + signature[1] + ", entry, procedure);");
- else line(content, " entry.compute(graph, procedure);");
+ line(content, " assert(entry.isPending());");
+ if(shortcut) line(content, " " + clazz + ".computeForEach(graph, " + signature[1] + ", entry, procedure_);");
+ else line(content, " entry.compute(graph, procedure_);");
line(content, " if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());");
line(content, " }");
line(content, "}");
}
- public void generateGetOrCreate(StringBuilder content, String clazz, String[] signature) {
+ public void generateGetOrCreate(StringBuilder content, String clazz, String[] signature, boolean genAsync) {
String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
- line(content, "" + clazz + " getOrCreate" + clazz + "(" + signature[0] + ") throws DatabaseException {");
+ line(content, "" + clazz + " getOrCreate" + clazz + "(" + signature[0] + (genAsync ? ", boolean isSync" : "") + ") throws DatabaseException {");
line(content, " " + clazz + " existing = null;");
line(content, " synchronized(" + lower + "Map) {");
line(content, " existing = (" + clazz + ")" + lower + "Map.get(" + signature[1] + ");");
line(content, " return existing;");
line(content, " }");
line(content, " }");
- line(content, " if(existing.isPending()) waitPending(existing);");
+ if(genAsync) {
+ line(content, " if(existing.isPending()) {");
+ line(content, " if(isSync) waitPending(existing);");
+ line(content, " else return null;");
+ line(content, " }");
+ } else {
+ line(content, " if(existing.isPending()) waitPending(existing);");
+ }
line(content, " return existing;");
line(content, "}");
line(content, "");
content.append("import org.simantics.db.ObjectResourceIdMap;\n");
content.append("import org.simantics.db.RelationInfo;\n");
+ content.append("import org.simantics.db.common.utils.Logger;\n");
content.append("import org.simantics.db.exception.DatabaseException;\n");
content.append("import org.simantics.db.impl.graph.ReadGraphImpl;\n");
content.append("import org.simantics.db.impl.procedure.InternalProcedure;\n");
+ content.append("import org.simantics.db.impl.query.QueryProcessor.SessionTask;\n");
content.append("import org.simantics.db.procedure.AsyncMultiProcedure;\n");
content.append("import org.simantics.db.procedure.AsyncProcedure;\n");
content.append("import org.simantics.db.procedure.ListenerBase;\n");
line(content,"}");
content.append("\n");
- generateQuery(content, "Objects", signatureR2IP, true);
- generateQuery(content, "Statements", signatureR2TIP, true);
- generateQuery(content, "DirectObjects", signatureR2IP, true);
- generateQuery(content, "RelationInfoQuery", signatureR1RelationInfo, true);
- generateQuery(content, "URIToResource", signatureID1, true);
- generateQuery(content, "ValueQuery", signatureR1Bytes, true);
- generateQuery(content, "OrderedSet", signatureR1IP, true);
- generateQuery(content, "PrincipalTypes", signatureR1IP, true);
- generateQuery(content, "DirectPredicates", signatureR1IntSet, true);
- generateQuery(content, "Predicates", signatureR1IntSet, true);
- generateQuery(content, "ReadEntry", signatureRead, true);
- generateQuery(content, "AsyncReadEntry", signatureAsyncRead, true);
- generateQuery(content, "Types", signatureR1IntSet, true);
+ generateQuery(content, "Objects", signatureR2IP, true, false);
+ generateQuery(content, "Statements", signatureR2TIP, true, false);
+ generateQuery(content, "DirectObjects", signatureR2IP, true, false);
+ generateQuery(content, "RelationInfoQuery", signatureR1RelationInfo, true, false);
+ generateQuery(content, "URIToResource", signatureID1, true, false);
+ generateQuery(content, "ValueQuery", signatureR1Bytes, true, false);
+ generateQuery(content, "OrderedSet", signatureR1IP, true, false);
+ generateQuery(content, "PrincipalTypes", signatureR1IP, true, false);
+ generateQuery(content, "DirectPredicates", signatureR1IntSet, true, false);
+ generateQuery(content, "Predicates", signatureR1IntSet, true, false);
+ generateQuery(content, "ReadEntry", signatureRead, true, true);
+ generateQuery(content, "AsyncReadEntry", signatureAsyncRead, true, true);
+ generateQuery(content, "Types", signatureR1IntSet, true, false);
//generateQuery(content, "NamespaceIndex", signatureID2, true);
- generateQuery(content, "ChildMap", signatureChildMap, true);
+ generateQuery(content, "ChildMap", signatureChildMap, true, false);
- generateQuery(content, "AssertedStatements", signatureR2TIP, false);
- generateQuery(content, "AssertedPredicates", signatureR1IP, false);
- generateQuery(content, "DirectSuperRelations", signatureR1IP, false);
- generateQuery(content, "SuperTypes", signatureR1IntSet, false);
- generateQuery(content, "TypeHierarchy", signatureR1IntSet, false);
- generateQuery(content, "SuperRelations", signatureR1IntSet, false);
- generateQuery(content, "MultiReadEntry", signatureMultiRead, false);
- generateQuery(content, "AsyncMultiReadEntry", signatureAsyncMultiRead, false);
- generateQuery(content, "ExternalReadEntry", signatureExternalRead, false);
+ generateQuery(content, "AssertedStatements", signatureR2TIP, false, false);
+ generateQuery(content, "AssertedPredicates", signatureR1IP, false, false);
+ generateQuery(content, "DirectSuperRelations", signatureR1IP, false, false);
+ generateQuery(content, "SuperTypes", signatureR1IntSet, false, false);
+ generateQuery(content, "TypeHierarchy", signatureR1IntSet, false, false);
+ generateQuery(content, "SuperRelations", signatureR1IntSet, false, false);
+ generateQuery(content, "MultiReadEntry", signatureMultiRead, false, false);
+ generateQuery(content, "AsyncMultiReadEntry", signatureAsyncMultiRead, false, false);
+ generateQuery(content, "ExternalReadEntry", signatureExternalRead, false, false);
content.append("}\n");
FileUtils.writeFile(source, content.toString().getBytes());
} catch (MalformedURLException e) {
provider.cache.remove(this);
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
computeForEach(graph, r1(), r2(), this, procedure);
return getResult();
provider.cache.remove(this);
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
return computeForEach(graph, id, this, procedure);
}
}
- @Override
+ //@Override
public Object compute(final ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
QueryProcessor processor = graph.processor;
// Do nothing - the state is already set and cannot be recomputed on demand
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
return graph.processor.cache.performQuery(graph, request, this, procedure);
}
else return request.toString() + statusOrException;
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, AsyncMultiProcedure<T> procedure) throws DatabaseException {
return graph.processor.cache.performQuery(graph, request, this, procedure);
}
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
computeForEach(graph, r1(), r2(), this, procedure);
return getResult();
setResult(new IntArray());
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
computeForEach(graph, id, this, procedure);
return getResult();
}
- @Override
+ //@Override
public Object compute(final ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
QueryProcessor processor = graph.processor;
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
computeForEach(graph, id, this, procedure);
return getResult();
}
- @Override
+ //@Override
public Object compute(final ReadGraphImpl graph, final IntProcedure proc) throws DatabaseException {
return computeForEach(graph, id, this, proc);
}
import org.simantics.db.ObjectResourceIdMap;
import org.simantics.db.RelationInfo;
+import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.InternalProcedure;
+import org.simantics.db.impl.query.QueryProcessor.SessionTask;
import org.simantics.db.procedure.AsyncMultiProcedure;
import org.simantics.db.procedure.AsyncProcedure;
import org.simantics.db.procedure.ListenerBase;
}
}
- public static void runnerObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+ public static void runnerObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r1,r2)) {
Objects.computeForEach(graph, r1,r2, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedureObjects;
Objects entry = (Objects)cache.getOrCreateObjects(r1,r2);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureObjects;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- Objects.computeForEach(graph, r1,r2, entry, procedure);
+ assert(entry.isPending());
+ Objects.computeForEach(graph, r1,r2, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException {
+ public static void runnerStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r1,r2)) {
Statements.computeForEach(graph, r1,r2, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedureStatements;
Statements entry = (Statements)cache.getOrCreateStatements(r1,r2);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureStatements;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- Statements.computeForEach(graph, r1,r2, entry, procedure);
+ assert(entry.isPending());
+ Statements.computeForEach(graph, r1,r2, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerDirectObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+ public static void runnerDirectObjects(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r1,r2)) {
DirectObjects.computeForEach(graph, r1,r2, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedureDirectObjects;
DirectObjects entry = (DirectObjects)cache.getOrCreateDirectObjects(r1,r2);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectObjects;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- DirectObjects.computeForEach(graph, r1,r2, entry, procedure);
+ assert(entry.isPending());
+ DirectObjects.computeForEach(graph, r1,r2, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerRelationInfoQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<RelationInfo> procedure) throws DatabaseException {
+ public static void runnerRelationInfoQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<RelationInfo> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
RelationInfoQuery.computeForEach(graph, r, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedureRelationInfoQuery;
RelationInfoQuery entry = (RelationInfoQuery)cache.getOrCreateRelationInfoQuery(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ InternalProcedure<RelationInfo> procedure_ = procedure != null ? procedure : emptyProcedureRelationInfoQuery;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- RelationInfoQuery.computeForEach(graph, r, entry, procedure);
+ assert(entry.isPending());
+ RelationInfoQuery.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerURIToResource(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, InternalProcedure<Integer> procedure) throws DatabaseException {
+ public static void runnerURIToResource(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener, final InternalProcedure<Integer> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, id)) {
URIToResource.computeForEach(graph, id, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedureURIToResource;
URIToResource entry = (URIToResource)cache.getOrCreateURIToResource(id);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ InternalProcedure<Integer> procedure_ = procedure != null ? procedure : emptyProcedureURIToResource;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- URIToResource.computeForEach(graph, id, entry, procedure);
+ assert(entry.isPending());
+ URIToResource.computeForEach(graph, id, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<byte[]> procedure) throws DatabaseException {
+ public static void runnerValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<byte[]> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
ValueQuery.computeForEach(graph, r, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedureValueQuery;
ValueQuery entry = (ValueQuery)cache.getOrCreateValueQuery(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ InternalProcedure<byte[]> procedure_ = procedure != null ? procedure : emptyProcedureValueQuery;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- ValueQuery.computeForEach(graph, r, entry, procedure);
+ assert(entry.isPending());
+ ValueQuery.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerOrderedSet(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+ public static void runnerOrderedSet(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
OrderedSet.computeForEach(graph, r, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedureOrderedSet;
OrderedSet entry = (OrderedSet)cache.getOrCreateOrderedSet(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureOrderedSet;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- OrderedSet.computeForEach(graph, r, entry, procedure);
+ assert(entry.isPending());
+ OrderedSet.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerPrincipalTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+ public static void runnerPrincipalTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
PrincipalTypes.computeForEach(graph, r, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedurePrincipalTypes;
PrincipalTypes entry = (PrincipalTypes)cache.getOrCreatePrincipalTypes(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ IntProcedure procedure_ = procedure != null ? procedure : emptyProcedurePrincipalTypes;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- PrincipalTypes.computeForEach(graph, r, entry, procedure);
+ assert(entry.isPending());
+ PrincipalTypes.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerDirectPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerDirectPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
DirectPredicates.computeForEach(graph, r, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedureDirectPredicates;
DirectPredicates entry = (DirectPredicates)cache.getOrCreateDirectPredicates(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureDirectPredicates;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- DirectPredicates.computeForEach(graph, r, entry, procedure);
+ assert(entry.isPending());
+ DirectPredicates.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
Predicates.computeForEach(graph, r, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedurePredicates;
Predicates entry = (Predicates)cache.getOrCreatePredicates(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedurePredicates;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- Predicates.computeForEach(graph, r, entry, procedure);
+ assert(entry.isPending());
+ Predicates.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
- ReadEntry getOrCreateReadEntry(Read<?> r) throws DatabaseException {
+ ReadEntry getOrCreateReadEntry(Read<?> r, boolean isSync) throws DatabaseException {
ReadEntry existing = null;
synchronized(readEntryMap) {
existing = (ReadEntry)readEntryMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) {
+ if(isSync) waitPending(existing);
+ else return null;
+ }
return existing;
}
}
}
- public static void runnerReadEntry(ReadGraphImpl graph, Read<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
+ public static void runnerReadEntry(ReadGraphImpl graph, Read<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, boolean isSync) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
ReadEntry.computeForEach(graph, r, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedureReadEntry;
- ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(r, isSync);
+ if(entry == null) {
+ graph.processor.schedule(Integer.MIN_VALUE, new SessionTask(r, graph.processor.THREAD_MASK+1, -1) {
+ @Override
+ public void run(int thread) {
+ try {
+ assert(!isSync);
+ runnerReadEntry(graph, r, parent, listener, procedure, isSync);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ }
+ }
+ });
+ return;
+ }
+ AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureReadEntry;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- ReadEntry.computeForEach(graph, r, entry, procedure);
+ assert(entry.isPending());
+ ReadEntry.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
- AsyncReadEntry getOrCreateAsyncReadEntry(AsyncRead<?> r) throws DatabaseException {
+ AsyncReadEntry getOrCreateAsyncReadEntry(AsyncRead<?> r, boolean isSync) throws DatabaseException {
AsyncReadEntry existing = null;
synchronized(asyncReadEntryMap) {
existing = (AsyncReadEntry)asyncReadEntryMap.get(r);
return existing;
}
}
- if(existing.isPending()) waitPending(existing);
+ if(existing.isPending()) {
+ if(isSync) waitPending(existing);
+ else return null;
+ }
return existing;
}
}
}
- public static void runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
+ public static void runnerAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, boolean isSync) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
AsyncReadEntry.computeForEach(graph, r, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedureAsyncReadEntry;
- AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(r, isSync);
+ if(entry == null) {
+ graph.processor.schedule(Integer.MIN_VALUE, new SessionTask(r, graph.processor.THREAD_MASK+1, -1) {
+ @Override
+ public void run(int thread) {
+ try {
+ assert(!isSync);
+ runnerAsyncReadEntry(graph, r, parent, listener, procedure, isSync);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ }
+ }
+ });
+ return;
+ }
+ AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureAsyncReadEntry;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- AsyncReadEntry.computeForEach(graph, r, entry, procedure);
+ assert(entry.isPending());
+ AsyncReadEntry.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
Types.computeForEach(graph, r, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedureTypes;
Types entry = (Types)cache.getOrCreateTypes(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureTypes;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- Types.computeForEach(graph, r, entry, procedure);
+ assert(entry.isPending());
+ Types.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerChildMap(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<ObjectResourceIdMap<String>> procedure) throws DatabaseException {
+ public static void runnerChildMap(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<ObjectResourceIdMap<String>> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) {
ChildMap.computeForEach(graph, r, null, procedure);
return;
}
- if(procedure == null) procedure = emptyProcedureChildMap;
ChildMap entry = (ChildMap)cache.getOrCreateChildMap(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ InternalProcedure<ObjectResourceIdMap<String>> procedure_ = procedure != null ? procedure : emptyProcedureChildMap;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- ChildMap.computeForEach(graph, r, entry, procedure);
+ assert(entry.isPending());
+ ChildMap.computeForEach(graph, r, entry, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException {
+ public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- if(procedure == null) procedure = emptyProcedureAssertedStatements;
AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(r1,r2);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedStatements;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- entry.compute(graph, procedure);
+ assert(entry.isPending());
+ entry.compute(graph, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+ public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- if(procedure == null) procedure = emptyProcedureAssertedPredicates;
AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedPredicates;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- entry.compute(graph, procedure);
+ assert(entry.isPending());
+ entry.compute(graph, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, IntProcedure procedure) throws DatabaseException {
+ public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- if(procedure == null) procedure = emptyProcedureDirectSuperRelations;
DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectSuperRelations;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- entry.compute(graph, procedure);
+ assert(entry.isPending());
+ entry.compute(graph, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- if(procedure == null) procedure = emptyProcedureSuperTypes;
SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureSuperTypes;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- entry.compute(graph, procedure);
+ assert(entry.isPending());
+ entry.compute(graph, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- if(procedure == null) procedure = emptyProcedureTypeHierarchy;
TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureTypeHierarchy;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- entry.compute(graph, procedure);
+ assert(entry.isPending());
+ entry.compute(graph, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure<IntSet> procedure) throws DatabaseException {
+ public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- if(procedure == null) procedure = emptyProcedureSuperRelations;
SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureSuperRelations;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- entry.compute(graph, procedure);
+ assert(entry.isPending());
+ entry.compute(graph, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException {
+ public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncMultiProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- if(procedure == null) procedure = emptyProcedureMultiReadEntry;
MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ AsyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureMultiReadEntry;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- entry.compute(graph, procedure);
+ assert(entry.isPending());
+ entry.compute(graph, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead<?> r, CacheEntry parent, ListenerBase listener, AsyncMultiProcedure procedure) throws DatabaseException {
+ public static void runnerAsyncMultiReadEntry(ReadGraphImpl graph, AsyncMultiRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncMultiProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- if(procedure == null) procedure = emptyProcedureAsyncMultiReadEntry;
AsyncMultiReadEntry entry = (AsyncMultiReadEntry)cache.getOrCreateAsyncMultiReadEntry(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ AsyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureAsyncMultiReadEntry;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- entry.compute(graph, procedure);
+ assert(entry.isPending());
+ entry.compute(graph, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
}
}
- public static void runnerExternalReadEntry(ReadGraphImpl graph, ExternalRead<?> r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException {
+ public static void runnerExternalReadEntry(ReadGraphImpl graph, ExternalRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure) throws DatabaseException {
QueryCache cache = graph.processor.cache;
- if(procedure == null) procedure = emptyProcedureExternalReadEntry;
ExternalReadEntry entry = (ExternalReadEntry)cache.getOrCreateExternalReadEntry(r);
- ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure, false);
- if(entry.isReady()) entry.performFromCache(graph, procedure);
+ AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureExternalReadEntry;
+ ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
+ if(entry.isReady()) entry.performFromCache(graph, procedure_);
else {
- entry.compute(graph, procedure);
+ assert(entry.isPending());
+ entry.compute(graph, procedure_);
if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
}
}
import java.util.ArrayList;
import java.util.Collection;
+import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicBoolean;
import org.simantics.db.AsyncReadGraph;
try {
Thread.sleep(1);
counter++;
- if(counter > 1000) {
+ if(counter > 5000) {
CacheEntryBase base = ((CacheEntryBase)entry);
// if(base.created != null) {
// System.err.println("created:");
private AsyncProcedure<T> procedure;
private T result = null;
private Throwable throwable = null;
+ private Semaphore s = new Semaphore(0);
AsyncProcedureWrapper(AsyncProcedure<T> procedure) {
this.procedure = procedure;
public void execute(AsyncReadGraph graph, T result) {
if(procedure != null) procedure.execute(graph, result);
this.result = result;
+ s.release();
}
@Override
public void exception(AsyncReadGraph graph, Throwable throwable) {
if(procedure != null) procedure.exception(graph, throwable);
this.throwable = throwable;
+ s.release();
}
public T get() throws DatabaseException {
+ try {
+ s.acquire();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
if(throwable != null) {
if(throwable instanceof DatabaseException) throw (DatabaseException)throwable;
else throw new DatabaseException(throwable);
public static <T> T resultReadEntry(ReadGraphImpl graph, Read r, CacheEntry parent, ListenerBase listener, AsyncProcedure<T> procedure) throws DatabaseException {
AsyncProcedureWrapper<T> wrap = new AsyncProcedureWrapper<>(procedure);
- QueryCache.runnerReadEntry(graph, r, parent, listener, wrap);
+ QueryCache.runnerReadEntry(graph, r, parent, listener, wrap, true);
+ return wrap.get();
+ }
+
+ public static <T> T resultAsyncReadEntry(ReadGraphImpl graph, AsyncRead r, CacheEntry parent, ListenerBase listener, AsyncProcedure<T> procedure) throws DatabaseException {
+ AsyncProcedureWrapper<T> wrap = new AsyncProcedureWrapper<>(procedure);
+ QueryCache.runnerAsyncReadEntry(graph, r, parent, listener, wrap, true);
return wrap.get();
}
QueryThread[] executors;
- public ArrayList<SessionTask>[] queues;
+// public ArrayList<SessionTask>[] queues;
+
+ public LinkedList<SessionTask> freeScheduling = new LinkedList<SessionTask>();
enum ThreadState {
public ReentrantLock[] threadLocks;
public Condition[] threadConditions;
- public ArrayList<SessionTask>[] ownTasks;
+ //public ArrayList<SessionTask>[] ownTasks;
- public ArrayList<SessionTask>[] ownSyncTasks;
+ //public ArrayList<SessionTask>[] ownSyncTasks;
- ArrayList<SessionTask>[] delayQueues;
+ //ArrayList<SessionTask>[] delayQueues;
final Object querySupportLock;
public void close() {
}
- final public void scheduleOwn(int caller, SessionTask request) {
- ownTasks[caller].add(request);
- }
+// final public void scheduleOwn(int caller, SessionTask request) {
+// ownTasks[caller].add(request);
+// }
final public void scheduleAlways(int caller, SessionTask request) {
- int performer = request.thread;
- if(caller == performer) {
- ownTasks[caller].add(request);
- } else {
- schedule(caller, request);
- }
+// int performer = request.thread;
+// if(caller == performer) {
+// ownTasks[caller].add(request);
+// } else {
+// schedule(caller, request);
+// }
+ schedule(caller, request);
+
}
final public void schedule(int caller, SessionTask request) {
assert(request != null);
- if(caller == performer) {
- request.run(caller);
- } else {
- ReentrantLock queueLock = threadLocks[performer];
- queueLock.lock();
- queues[performer].add(request);
- // This thread could have been sleeping
- if(queues[performer].size() == 1) {
- if(ThreadState.SLEEP == threadStates[performer]) sleepers.decrementAndGet();
- threadConditions[performer].signalAll();
- }
- queueLock.unlock();
- }
+// if(caller == performer) {
+// request.run(caller);
+// } else {
+
+// if(performer == THREADS) {
+
+ synchronized(querySupportLock) {
+
+ freeScheduling.add(request);
+
+ //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;
+
+// }
+//
+// ReentrantLock queueLock = threadLocks[performer];
+// queueLock.lock();
+// queues[performer].add(request);
+// // This thread could have been sleeping
+// if(queues[performer].size() == 1) {
+// //if(ThreadState.SLEEP == threadStates[performer]) sleepers.decrementAndGet();
+// threadConditions[performer].signalAll();
+// }
+// queueLock.unlock();
+// }
}
querySupportLock = core.getLock();
executors = new QueryThread[THREADS];
- queues = new ArrayList[THREADS];
+// queues = new ArrayList[THREADS];
threadLocks = new ReentrantLock[THREADS];
threadConditions = new Condition[THREADS];
threadStates = new ThreadState[THREADS];
- ownTasks = new ArrayList[THREADS];
- ownSyncTasks = new ArrayList[THREADS];
- delayQueues = new ArrayList[THREADS * THREADS];
+// ownTasks = new ArrayList[THREADS];
+// ownSyncTasks = new ArrayList[THREADS];
+// delayQueues = new ArrayList[THREADS * THREADS];
// freeSchedule = new AtomicInteger(0);
- for (int i = 0; i < THREADS * THREADS; i++) {
- delayQueues[i] = new ArrayList<SessionTask>();
- }
+// for (int i = 0; i < THREADS * THREADS; i++) {
+// delayQueues[i] = new ArrayList<SessionTask>();
+// }
for (int i = 0; i < THREADS; i++) {
// tasks[i] = new ArrayList<Runnable>();
- ownTasks[i] = new ArrayList<SessionTask>();
- ownSyncTasks[i] = new ArrayList<SessionTask>();
- queues[i] = new ArrayList<SessionTask>();
+// ownTasks[i] = new ArrayList<SessionTask>();
+// ownSyncTasks[i] = new ArrayList<SessionTask>();
+// queues[i] = new ArrayList<SessionTask>();
threadLocks[i] = new ReentrantLock();
threadConditions[i] = threadLocks[i].newCondition();
// limits[i] = false;
private Session session;
private QuerySupport querySupport;
+ final private QueryProcessor processor;
final private ArrayList<SessionTask> tasks = new ArrayList<SessionTask>();
- final private ArrayList<SessionTask> own;
- final private ArrayList<SessionTask> ownSync;
- final private ArrayList<SessionTask> queue;
+// final private ArrayList<SessionTask> own;
+// final private ArrayList<SessionTask> ownSync;
+// final private ArrayList<SessionTask> queue;
final private ReentrantLock lock;
final private Condition condition;
final private Object querySupportLock;
final private int THREADS;
final private AtomicInteger sleepers;
final private ThreadState[] threadStates;
- final private ArrayList<SessionTask>[] delayQueues;
+// final private ArrayList<SessionTask>[] delayQueues;
final private QueryThread[] executors;
final private ReentrantLock[] threadLocks;
- final private ArrayList<SessionTask>[] queues;
- final private ArrayList<SessionTask>[] ownSyncTasks;
+// final private ArrayList<SessionTask>[] queues;
+// final private ArrayList<SessionTask>[] ownSyncTasks;
public QueryThread(Session session, QueryProcessor processor, int index, String name) {
super(QueryProcessor.QueryThreadGroup, null, name);
this.session = session;
+ this.processor = processor;
this.index = index;
- own = processor.ownTasks[index];
- ownSync = processor.ownSyncTasks[index];
- queue = processor.queues[index];
+// own = processor.ownTasks[index];
+// ownSync = processor.ownSyncTasks[index];
+// queue = processor.queues[index];
lock = processor.threadLocks[index];
condition = processor.threadConditions[index];
querySupportLock = processor.querySupportLock;
sleepers = processor.sleepers;
querySupport = processor.querySupport;
threadStates = processor.threadStates;
- delayQueues = processor.delayQueues;
+// delayQueues = processor.delayQueues;
executors = processor.executors;
threadLocks = processor.threadLocks;
- queues = processor.queues;
- ownSyncTasks = processor.ownSyncTasks;
+// queues = processor.queues;
+// ownSyncTasks = processor.ownSyncTasks;
}
synchronized void dispose() {
while(true) {
// Perform own tasks first
- if(tasks.addAll(own)) {
- own.clear();
- } else if (doWait && !ownSync.isEmpty()) {
- tasks.add(ownSync.remove(ownSync.size()-1));
- }
+// if(tasks.addAll(own)) {
+// own.clear();
+// } else if (doWait && !ownSync.isEmpty()) {
+// tasks.add(ownSync.remove(ownSync.size()-1));
+// }
// Try some queued tasks
- lock.lock();
- if(tasks.addAll(queue)) {
- queue.clear();
- lock.unlock();
- return tasks;
- } else {
- lock.unlock();
- }
+// lock.lock();
+// if(tasks.addAll(queue)) {
+// queue.clear();
+// lock.unlock();
+// return tasks;
+// } else {
+// lock.unlock();
+// }
// Return tasks if some were found
if(!tasks.isEmpty()) return tasks;
+
if(!doWait) return null;
synchronized (querySupportLock) {
- lock.lock();
+// System.err.println("check free tasks for QT " + index + " (" + processor.freeScheduling + ")");
- // Just maybe someone inserted tasks and notified just before synchronized block
- if(tasks.addAll(queue)) {
- queue.clear();
- lock.unlock();
+ if(!processor.freeScheduling.isEmpty()) {
+ tasks.add(processor.freeScheduling.removeFirst());
return tasks;
}
+ lock.lock();
+
+ // Just maybe someone inserted tasks and notified just before synchronized block
+// if(tasks.addAll(queue)) {
+// queue.clear();
+// lock.unlock();
+// return tasks;
+// }
+
+// System.err.println("QT " + index + ", sleepers = " + sleepers);
+
// We are the last one awake
if(sleepers.incrementAndGet() == THREADS) {
if(querySupport == null) System.err.println("null qs");
querySupport.ceased(index);
- if(tasks.addAll(own)) {
- own.clear();
- }
+// if(tasks.addAll(own)) {
+// own.clear();
+// }
// System.err.println("tasks after ceased: " + tasks.size());
if(!tasks.isEmpty()) {
lock.unlock();
threadStates[index] = ThreadState.SLEEP;
condition.await();
+ sleepers.decrementAndGet();
+
// We are done
if(isDisposed()) {
threadStates[index] = ThreadState.DISPOSED;
boolean didExecute = false;
- for(int performer=0;performer<THREADS;performer++) {
- if(!delayQueues[index * THREADS + performer].isEmpty()) {
- synchronized(executors[performer]) {
- threadLocks[performer].lock();
- queues[performer].addAll(delayQueues[index * THREADS + performer]);
- delayQueues[index * THREADS + performer].clear();
- executors[performer].notify();
- threadLocks[performer].unlock();
- }
- }
- }
+// for(int performer=0;performer<THREADS;performer++) {
+// if(!delayQueues[index * THREADS + performer].isEmpty()) {
+// synchronized(executors[performer]) {
+// threadLocks[performer].lock();
+// queues[performer].addAll(delayQueues[index * THREADS + performer]);
+// delayQueues[index * THREADS + performer].clear();
+// executors[performer].notify();
+// threadLocks[performer].unlock();
+// }
+// }
+// }
if(tasks.isEmpty()) {
ArrayList<SessionTask> finished = newTasks(false, tasks);
SessionTask task = tasks.remove(tasks.size() - 1);
- if(task.syncCaller == index) {
- ownSyncTasks[index].add(task);
- } else {
+// if(task.syncCaller == index) {
+// ownSyncTasks[index].add(task);
+// } else {
task.run(index);
+// System.err.println("QT(s) " + index + " runs " + task);
didExecute = true;
- }
+// }
}
while(!tasks.isEmpty()) {
SessionTask task = tasks.remove(tasks.size()-1);
+// System.err.println("QT " + index + " runs " + task);
task.run(index);
}
- for(int performer=0;performer<THREADS;performer++) {
- if(!delayQueues[index * THREADS + performer].isEmpty()) {
- synchronized(executors[performer]) {
- threadLocks[performer].lock();
- queues[performer].addAll(delayQueues[index * THREADS + performer]);
- delayQueues[index * THREADS + performer].clear();
- executors[performer].notify();
- threadLocks[performer].unlock();
- }
- }
- }
+// for(int performer=0;performer<THREADS;performer++) {
+// if(!delayQueues[index * THREADS + performer].isEmpty()) {
+// synchronized(executors[performer]) {
+// threadLocks[performer].lock();
+// queues[performer].addAll(delayQueues[index * THREADS + performer]);
+// delayQueues[index * THREADS + performer].clear();
+// executors[performer].notify();
+// threadLocks[performer].unlock();
+// }
+// }
+// }
}
}
final public Object addOrSet(AsyncReadGraph graph, Object result) {
+
+// System.err.println("addOrSet " + request + " " + Thread.currentThread() + " " + result);
assert(assertPending());
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, AsyncProcedure<T> procedure) throws DatabaseException {
ReadGraphImpl queryGraph = graph.withParent(this);
@Override
public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
+ if(done) return;
done = true;
RelationInfo result = new RelationInfo(r, isFunctional, isFinal, true);
if(entry != null) entry.setResult(result);
@Override
public void finished(ReadGraphImpl graph) throws DatabaseException {
- if(!done) {
- done = true;
- RelationInfo result = new RelationInfo(r, isFunctional, isFinal, false);
- if(entry != null) entry.setResult(result);
- proc.execute(graph, result);
- }
+ if(done) return;
+ done = true;
+ RelationInfo result = new RelationInfo(r, isFunctional, isFinal, false);
+ if(entry != null) entry.setResult(result);
+ proc.execute(graph, result);
}
@Override
public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
- if(!done) {
- done = true;
- DatabaseException e = new DatabaseException("Internal error in RelationInfoQuery");
- if(entry != null) entry.except(e);
- proc.exception(graph, e);
- }
+ if(done) return;
+ done = true;
+ DatabaseException e = new DatabaseException("Internal error in RelationInfoQuery");
+ if(entry != null) entry.except(e);
+ proc.exception(graph, e);
}
});
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, final InternalProcedure<RelationInfo> procedure) throws DatabaseException {
computeForEach(graph, id, this, procedure);
return getResult();
final static private void forSingleAssertion(ReadGraphImpl graph, final int r1, final int r2, final Statements entry, final TripleIntProcedure procedure) throws DatabaseException {
+ if(entry != null) {
+ assert(entry.isPending());
+ }
+
IntArray map = getAssertionMap(graph, r1, r2, entry);
if(map == null) {
if(entry != null) entry.finish(graph, procedure);
}
}
-
- @Override
- public Object compute(ReadGraphImpl graph, final TripleIntProcedure procedure) throws DatabaseException {
- computeForEach(graph, r1(), r2(), this, procedure);
- return getResult();
- }
public static void computeForEach(ReadGraphImpl graph, final int r1, final int r2, final Statements entry, final TripleIntProcedure procedure) throws DatabaseException {
+ if(entry != null) {
+ assert(entry.isPending());
+ }
+
QueryCache.runnerRelationInfoQuery(graph, r2, entry, null, new InternalProcedure<RelationInfo>() {
@Override
synchronized(this) {
setReady();
+ //new Exception(toString() + " is READY").printStackTrace();
}
IntArray v = (IntArray)getResult();
@Override
public void recompute(ReadGraphImpl graph) throws DatabaseException {
- compute(graph, new TripleIntProcedureAdapter() {
+ computeForEach(graph, r1(), r2(), this, new TripleIntProcedureAdapter() {
@Override
public void finished(ReadGraphImpl graph) {
}
- @Override
+ //@Override
public Object compute(final ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryProcessor processor = graph.processor;
provider.cache.remove(this);
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
return computeForEach(graph, id, this, procedure);
}
provider.cache.remove(this);
}
- @Override
+ //@Override
public IntSet compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
QueryProcessor processor = graph.processor;
provider.cache.remove(this);
}
- @Override
+ //@Override
public Object compute(final ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
computeForEach(graph, id, this, procedure);
return getResult();
provider.cache.remove(this);
}
- @Override
+ //@Override
public Object compute(ReadGraphImpl graph, final InternalProcedure<Integer> procedure) throws DatabaseException {
computeForEach(graph, id, this, procedure);
return getResult();
throw new Error("Not possible.");
}
- @Override
- public Object compute(ReadGraphImpl graph, Procedure procedure) throws DatabaseException {
- throw new Error("Not possible.");
- }
-
@Override
Object performFromCache(ReadGraphImpl graph, Procedure procedure) throws DatabaseException {
throw new Error("Not possible.");
}
- public static byte[] computeForEach(ReadGraphImpl graph, final int r) {
-
- graph.ensureLoaded(r);
-
- return graph.getValue(r);
-
- }
-
- @Override
- public Object compute(ReadGraphImpl graph, final InternalProcedure<byte[]> procedure) throws DatabaseException {
- return computeForEach(graph, id, this, procedure);
- }
+// public Object compute(ReadGraphImpl graph, final InternalProcedure<byte[]> procedure) throws DatabaseException {
+// return computeForEach(graph, id, this, procedure);
+// }
@Override
public String toString() {
@Override
public Object performFromCache(ReadGraphImpl graph, InternalProcedure<byte[]> procedure) throws DatabaseException {
- return compute(graph, procedure);
+ return computeForEach(graph, id, this, procedure);
}
@Override
public void recompute(ReadGraphImpl graph) throws DatabaseException {
- compute(graph, new InternalProcedure<byte[]>() {
+ computeForEach(graph, id, this, new InternalProcedure<byte[]>() {
@Override
public void execute(ReadGraphImpl graph, byte[] result) {
fillEnvironmentSpecification(environmentSpecification);
Layer0 L0 = Layer0.getInstance(graph);
- Collection<Resource> sclModules = graph.syncRequest(new ObjectsWithType(parameter, L0.ConsistsOf, L0.SCLModule));
- for (Resource sclModule : sclModules)
- environmentSpecification.importModule(graph.getURI(sclModule), "");
+ if(parameter != null) {
+ Collection<Resource> sclModules = graph.syncRequest(new ObjectsWithType(parameter, L0.ConsistsOf, L0.SCLModule));
+ for (Resource sclModule : sclModules)
+ environmentSpecification.importModule(graph.getURI(sclModule), "");
+ }
Resource mainModule = Layer0Utils.getPossibleChild(graph, parameter2, "SCLMain");
if(mainModule != null)
public void register(ReadGraph graph, final Listener<Variant> procedure) {
VariableNode node = parameter.first;
-
+
if(procedure.isDisposed()) {
// We are not listening
try {
Variant newValue = get(parameter);
if (wasRun && ObjectUtils.objectEquals(value, newValue)) {
- //System.out.println("CACHE VALUE MATCH (" + newValue + ") for " + node.node);
+ try {
+ //System.err.println("CACHE VALUE MATCH (" + newValue + ") for " + node.node);
+ } catch (Throwable t) {
+
+ }
return;
}
value = newValue;
}
@SuppressWarnings("unchecked")
- public final <T extends ClusterI> T getClusterByResourceKey(final int resourceKey) {
+ public synchronized final <T extends ClusterI> T getClusterByResourceKey(final int resourceKey) {
int clusterKey = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(resourceKey);
if (ClusterTraitsBase.isVirtualClusterKey(clusterKey))
throw new RuntimeException("Tried to get a persistent cluster for a virtual resource.");
import org.simantics.db.authentication.UserAuthenticator;
import org.simantics.db.common.Indexing;
import org.simantics.db.common.TransactionPolicyRelease;
+import org.simantics.db.common.procedure.BlockingAsyncProcedure;
import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter;
import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
import org.simantics.db.common.procedure.wrapper.NoneToAsyncListener;
assert (request != null);
assert (procedure != null);
- int thread = request.hashCode() & queryProvider2.THREAD_MASK;
+ //int thread = request.hashCode() & queryProvider2.THREAD_MASK;
- requestManager.scheduleRead(new SessionRead(request, throwable, notify, thread, thread) {
+ requestManager.scheduleRead(new SessionRead(request, throwable, notify, queryProvider2.THREAD_MASK + 1, -1) {
@Override
public void run(int thread) {
};
- QueryCache.runnerReadEntry(newGraph, request, null, listener, ap);
+ QueryCache.runnerReadEntry(newGraph, request, null, listener, ap, true);
} catch (Throwable t) {
// This is handled by the AsyncProcedure
if (listener != null) {
try {
- QueryCache.runnerAsyncReadEntry(newGraph, request, null, listener, procedure);
+ QueryCacheBase.resultAsyncReadEntry(newGraph, request, null, listener, procedure);
+ //QueryCache.runnerAsyncReadEntry(newGraph, request, null, listener, procedure, true);
//newGraph.processor.query(newGraph, request, null, procedure, listener);
} catch (DatabaseException e) {
Logger.defaultLogError(e);
} else {
- final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
- procedure, "request");
-
- try {
+// final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
+// procedure, "request");
-// newGraph.state.barrier.inc();
+ BlockingAsyncProcedure<T> wrap = new BlockingAsyncProcedure<T>(procedure, request);
- request.perform(newGraph, wrapper);
+ try {
-// newGraph.waitAsync(request);
+ request.perform(newGraph, wrap);
+ wrap.get();
} catch (Throwable t) {
- wrapper.exception(newGraph, t);
+ wrap.exception(newGraph, t);
+
+// wrapper.exception(newGraph, t);
// newGraph.waitAsync(request);
public int getAmountOfQueryThreads() {
// This must be a power of two
- return 4;
+ return 16;
// return Integer.highestOneBit(Runtime.getRuntime().availableProcessors());
}
if(!session.state.isAlive()) return;
WriteState<?> writeState = session.writeState;
+
+ assert(writeState != null);
+
WriteGraphImpl graph = writeState.getGraph();
if(writeState.isExcepted()) {
} else {
- throw new IllegalStateException("State in ceased should be WRITE or READ or INIT (was " + state + ")");
+ // Spurious wakeup
+
+ //throw new IllegalStateException("State in ceased should be WRITE or READ or INIT (was " + state + ")");
}
boolean inUpdate = state == State.WRITE_UPDATE;
+ //System.err.println("schedule write " + task);
+
assert(State.INIT != state);
//task.combine = combine != null ? combine : inUpdate;
if(State.IDLE == state) {
import org.simantics.db.Resource;
import org.simantics.db.adaption.Adapter;
import org.simantics.db.adaption.AdaptionService;
+import org.simantics.db.common.procedure.BlockingAsyncProcedure;
import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.common.procedure.single.SyncReadProcedure;
import org.simantics.db.common.request.BinaryRead;
public <T, C> T adapt(ReadGraph g, Resource r, C context, Class<C> contextClass, Class<T> targetClass, boolean possible) throws DatabaseException {
Adapter<T,C> adapter = getAdapter(g, r, context, contextClass, targetClass, possible);
+ if(adapter == null) return null;
- SyncReadProcedure<T> procedure = new SyncReadProcedure<T>();
- adapter.adapt(g, r, context, procedure);
- procedure.checkAndThrow();
- return procedure.result;
+ BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<T>(null, adapter);
+
+// SyncReadProcedure<T> procedure = new SyncReadProcedure<T>();
+ adapter.adapt(g, r, context, ap);
+ return ap.get();
+// procedure.checkAndThrow();
+// return procedure.result;
}
<product
application="org.simantics.workbench.application"
description="Simantics Desktop Environment"
- name="Simantics Desktop">
+ name="TestingStation Server">
<property
name="appName"
- value="Simantics Desktop"/>
+ value="TestingStation Server"/>
<property
name="aboutImage"
value="platform:/plugin/org.simantics.desktop.ui/icons/simantics256.png">
import gnu.trove.set.hash.THashSet;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Set;
+import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
import org.simantics.db.AsyncReadGraph;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
+import org.simantics.db.common.primitiverequest.OrderedSet;
import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
+import org.simantics.db.common.utils.OrderedSetUtils;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.procedure.AsyncMultiProcedure;
import org.simantics.db.procedure.AsyncProcedure;
// These help loading result.elements in the correct order.
final AtomicInteger index = new AtomicInteger();
final TIntArrayList unrecognizedElementIndices = new TIntArrayList();
-
- g.forOrderedSet(data, new AsyncMultiProcedure<Resource>() {
-
- @Override
- public void execute(AsyncReadGraph graph, final Resource component) {
-
- // Must add the elements to the result set here in order to
- // keep their order the same as in the ordered set.
- final int elementIndex = index.getAndIncrement();
- result.elements.add(component);
-
- graph.forTypes(component, new AsyncProcedure<Set<Resource>>() {
-
- @Override
- public void exception(AsyncReadGraph graph, Throwable t) {
- if (errorHandler != null)
- errorHandler.error(t.getMessage(), t);
- }
-
- @Override
- public void execute(AsyncReadGraph graph, Set<Resource> types) {
- if (types.contains(DIA.Connection)) {
- if (types.contains(DIA.RouteGraphConnection)) {
- graph.asyncRequest(new RouteGraphConnectionPartRequest(errorHandler, DIA, component),
- new ProcedureAdapter<RouteGraphConnectionPartData>() {
- @Override
- public void execute(RouteGraphConnectionPartData partData) {
- synchronized (result) {
- for (EdgeResource link : partData.links) {
- result.routeLinks.add(link);
- result.partToConnection.put(link, component);
- result.connectionToParts.add(component, link);
- }
- for (Resource line : partData.routeLines) {
- result.routeLines.add(line);
- result.connectionToParts.add(component, line);
- result.partToConnection.put(line, component);
- }
- for (Resource point : partData.routePoints) {
- result.routePoints.add(point);
- result.connectionToParts.add(component, point);
- result.partToConnection.put(point, component);
- }
- }
- }
- });
-
- synchronized (result.routeGraphConnectionSet) {
- result.routeGraphConnectionSet.add(component);
- }
- } else {
- graph.asyncRequest(new ConnectionPartRequest(errorHandler, DIA, component),
- new ProcedureAdapter<ConnectionPartData>() {
- @Override
- public void execute(ConnectionPartData partData) {
- synchronized (result) {
- for (EdgeResource er : partData.edges) {
- result.connectionSegments.add(er);
- result.partToConnection.put(er, component);
- result.connectionToParts.add(component, er);
- }
- for (Resource bp : partData.branchPoints) {
- result.branchPoints.add(bp);
- result.connectionToParts.add(component, bp);
- result.partToConnection.put(bp, component);
- }
- }
- }
- });
-
- synchronized (result.connectionSet) {
- result.connectionSet.add(component);
- }
- }
- }
- else if (types.contains(DIA.Element)) {
- synchronized (result.nodeSet) {
- result.nodeSet.add(component);
- }
- }
- else {
- synchronized (unrecognizedElementIndices) {
- // Unrecognized element, mark it to be
- // removed after everything is processed.
- unrecognizedElementIndices.add(elementIndex);
- }
- }
- }
-
- });
-
- }
-
+
+ Collection<Resource> components = OrderedSetUtils.toList(g, data);
+
+ Semaphore s = new Semaphore(0);
+
+ for(Resource component : components) {
+
+ // Must add the elements to the result set here in order to
+ // keep their order the same as in the ordered set.
+ final int elementIndex = index.getAndIncrement();
+ result.elements.add(component);
+
+ Set<Resource> types = g.getTypes(component);
+
+ if (types.contains(DIA.Connection)) {
+ if (types.contains(DIA.RouteGraphConnection)) {
+ g.asyncRequest(new RouteGraphConnectionPartRequest(errorHandler, DIA, component),
+ new ProcedureAdapter<RouteGraphConnectionPartData>() {
+ @Override
+ public void execute(RouteGraphConnectionPartData partData) {
+ synchronized (result) {
+ for (EdgeResource link : partData.links) {
+ result.routeLinks.add(link);
+ result.partToConnection.put(link, component);
+ result.connectionToParts.add(component, link);
+ }
+ for (Resource line : partData.routeLines) {
+ result.routeLines.add(line);
+ result.connectionToParts.add(component, line);
+ result.partToConnection.put(line, component);
+ }
+ for (Resource point : partData.routePoints) {
+ result.routePoints.add(point);
+ result.connectionToParts.add(component, point);
+ result.partToConnection.put(point, component);
+ }
+ }
+ s.release();
+ }
+ });
+
+ synchronized (result.routeGraphConnectionSet) {
+ result.routeGraphConnectionSet.add(component);
+ }
+ } else {
+ g.asyncRequest(new ConnectionPartRequest(errorHandler, DIA, component),
+ new ProcedureAdapter<ConnectionPartData>() {
+ @Override
+ public void execute(ConnectionPartData partData) {
+ synchronized (result) {
+ for (EdgeResource er : partData.edges) {
+ result.connectionSegments.add(er);
+ result.partToConnection.put(er, component);
+ result.connectionToParts.add(component, er);
+ }
+ for (Resource bp : partData.branchPoints) {
+ result.branchPoints.add(bp);
+ result.connectionToParts.add(component, bp);
+ result.partToConnection.put(bp, component);
+ }
+ }
+ s.release();
+ }
+ });
+
+ synchronized (result.connectionSet) {
+ result.connectionSet.add(component);
+ }
+ }
+ }
+ else if (types.contains(DIA.Element)) {
+ synchronized (result.nodeSet) {
+ result.nodeSet.add(component);
+ }
+ s.release();
+
+ }
+ else {
+ synchronized (unrecognizedElementIndices) {
+ // Unrecognized element, mark it to be
+ // removed after everything is processed.
+ unrecognizedElementIndices.add(elementIndex);
+ }
+ s.release();
+ }
+
+ }
+
+ try {
+ s.acquire(components.size());
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ // Remove elements that were not recognized in descending order.
+ unrecognizedElementIndices.sort();
+ unrecognizedElementIndices.forEachDescending(new TIntProcedure() {
@Override
- public void finished(AsyncReadGraph graph) {
- // Remove elements that were not recognized in descending order.
- unrecognizedElementIndices.sort();
- unrecognizedElementIndices.forEachDescending(new TIntProcedure() {
- @Override
- public boolean execute(int index) {
- result.elements.remove(index);
- return true;
- }
- });
-
- // Help successive request executions by remembering the previous
- // element count. This will relieve some ArrayList reallocation
- // strain down the road.
- previousElementCount = result.elements.size();
- }
-
- @Override
- public void exception(AsyncReadGraph graph, Throwable t) {
- if (errorHandler != null)
- errorHandler.error(t.getMessage(), t);
+ public boolean execute(int index) {
+ result.elements.remove(index);
+ return true;
}
});
+ // Help successive request executions by remembering the previous
+ // element count. This will relieve some ArrayList reallocation
+ // strain down the road.
+ previousElementCount = result.elements.size();
+
+
+// g.forOrderedSet(data, new AsyncMultiProcedure<Resource>() {
+//
+// @Override
+// public void execute(AsyncReadGraph graph, final Resource component) {
+//
+// graph.forTypes(component, new AsyncProcedure<Set<Resource>>() {
+//
+// @Override
+// public void exception(AsyncReadGraph graph, Throwable t) {
+// if (errorHandler != null)
+// errorHandler.error(t.getMessage(), t);
+// }
+//
+// @Override
+// public void execute(AsyncReadGraph graph, Set<Resource> types) {
+//
+// }
+//
+// });
+//
+// }
+//
+// @Override
+// public void finished(AsyncReadGraph graph) {
+// }
+//
+// @Override
+// public void exception(AsyncReadGraph graph, Throwable t) {
+// if (errorHandler != null)
+// errorHandler.error(t.getMessage(), t);
+// }
+// });
+
return result;
}
}
\ No newline at end of file
// ITask task5 = ThreadLogger.getInstance().begin("DiagramContentRequest2");
ITask task42 = ThreadLogger.getInstance().begin("DiagramContentRequest2");
DiagramContents contents = g.syncRequest(query);
+ System.err.println("contents: " + contents);
task42.finish();
// task5.finish();
monitor.worked(10);
this.removedRouteGraphConnections.clear();
}
- void processNodes(AsyncReadGraph graph) {
+ void processNodes(ReadGraph graph) throws DatabaseException {
for (Map.Entry<Resource, Change> entry : changes.elements.entrySet()) {
IElement mappedElement = getMappedElement(element);
if (mappedElement == null) {
if (DebugPolicy.DEBUG_NODE_LOAD)
- graph.asyncRequest(new ReadRequest() {
+ graph.syncRequest(new ReadRequest() {
@Override
public void run(ReadGraph graph) throws DatabaseException {
System.out.println(" EXTERNALLY ADDED ELEMENT: "
}
};
- graph.asyncRequest(new ConnectionRequest(canvas, diagram, element, errorHandler, loadListener), new AsyncProcedure<IElement>() {
+ graph.syncRequest(new ConnectionRequest(canvas, diagram, element, errorHandler, loadListener), new AsyncProcedure<IElement>() {
@Override
public void execute(AsyncReadGraph graph, final IElement e) {
if (e == null)
};
//System.out.println("NODE REQUEST: " + element);
- graph.asyncRequest(new NodeRequest(canvas, diagram, element, loadListener), new AsyncProcedure<IElement>() {
+ graph.syncRequest(new NodeRequest(canvas, diagram, element, loadListener), new AsyncProcedure<IElement>() {
@Override
public void execute(AsyncReadGraph graph, IElement e) {
if (e == null)
case REMOVED: {
IElement e = getMappedElement(element);
if (DebugPolicy.DEBUG_NODE_LOAD)
- graph.asyncRequest(new ReadRequest() {
+ graph.syncRequest(new ReadRequest() {
@Override
public void run(ReadGraph graph) throws DatabaseException {
System.out.println(" EXTERNALLY REMOVED ELEMENT: "
}
}
- void processRouteGraphConnections(AsyncReadGraph graph) {
+ void processRouteGraphConnections(ReadGraph graph) throws DatabaseException {
for (Map.Entry<Resource, Change> entry : changes.routeGraphConnections.entrySet()) {
final Resource connection = entry.getKey();
}
};
- graph.asyncRequest(new ConnectionRequest(canvas, diagram, connection, errorHandler, loadListener), new Procedure<IElement>() {
+ graph.syncRequest(new ConnectionRequest(canvas, diagram, connection, errorHandler, loadListener), new Procedure<IElement>() {
@Override
public void execute(final IElement e) {
if (e == null)
return assertMappedConnection(connection);
}
- void processBranchPoints(AsyncReadGraph graph) {
+ void processBranchPoints(ReadGraph graph) throws DatabaseException {
for (Map.Entry<Resource, Change> entry : changes.branchPoints.entrySet()) {
final Resource element = entry.getKey();
IElement mappedElement = getMappedElement(element);
if (mappedElement == null) {
if (DebugPolicy.DEBUG_NODE_LOAD)
- graph.asyncRequest(new ReadRequest() {
+ graph.syncRequest(new ReadRequest() {
@Override
public void run(ReadGraph graph) throws DatabaseException {
System.out.println(" EXTERNALLY ADDED BRANCH POINT: "
}
};
- graph.asyncRequest(new NodeRequest(canvas, diagram, element, loadListener), new AsyncProcedure<IElement>() {
+ graph.syncRequest(new NodeRequest(canvas, diagram, element, loadListener), new AsyncProcedure<IElement>() {
@Override
public void execute(AsyncReadGraph graph, IElement e) {
if (e != null) {
case REMOVED: {
IElement e = getMappedElement(element);
if (DebugPolicy.DEBUG_NODE_LOAD)
- graph.asyncRequest(new ReadRequest() {
+ graph.syncRequest(new ReadRequest() {
@Override
public void run(ReadGraph graph) throws DatabaseException {
System.out.println(" EXTERNALLY REMOVED BRANCH POINT: "
}
}
- void processConnectionSegments(AsyncReadGraph graph) {
+ void processConnectionSegments(ReadGraph graph) throws DatabaseException {
ConnectionSegmentAdapter adapter = connectionSegmentAdapter;
for (Map.Entry<EdgeResource, Change> entry : changes.connectionSegments.entrySet()) {
IElement mappedElement = getMappedElement(seg);
if (mappedElement == null) {
if (DebugPolicy.DEBUG_EDGE_LOAD)
- graph.asyncRequest(new ReadRequest() {
+ graph.syncRequest(new ReadRequest() {
@Override
public void run(ReadGraph graph) throws DatabaseException {
System.out.println(" EXTERNALLY ADDED CONNECTION SEGMENT: " + seg.toString()
}
});
- graph.asyncRequest(new EdgeRequest(canvas, errorHandler, canvasListenerSupport, diagram, adapter, seg), new AsyncProcedure<IElement>() {
+ graph.syncRequest(new EdgeRequest(canvas, errorHandler, canvasListenerSupport, diagram, adapter, seg), new AsyncProcedure<IElement>() {
@Override
public void execute(AsyncReadGraph graph, IElement e) {
if (DebugPolicy.DEBUG_EDGE_LOAD)
case REMOVED: {
final IElement e = getMappedElement(seg);
if (DebugPolicy.DEBUG_EDGE_LOAD)
- graph.asyncRequest(new ReadRequest() {
+ graph.syncRequest(new ReadRequest() {
@Override
public void run(ReadGraph graph) throws DatabaseException {
System.out.println(" EXTERNALLY REMOVED CONNECTION SEGMENT: " + seg.toString() + " - "
Object task = Timing.BEGIN("processNodesConnections");
//System.out.println("---- PROCESS NODES & CONNECTIONS BEGIN");
if (!changes.elements.isEmpty()) {
- graph.syncRequest(new AsyncReadRequest() {
+ graph.syncRequest(new ReadRequest() {
@Override
- public void run(AsyncReadGraph graph) {
+ public void run(ReadGraph graph) throws DatabaseException {
processNodes(graph);
}
@Override
//System.out.println("---- PROCESS BRANCH POINTS BEGIN");
if (!changes.branchPoints.isEmpty()) {
- graph.syncRequest(new AsyncReadRequest() {
+ graph.syncRequest(new ReadRequest() {
@Override
- public void run(AsyncReadGraph graph) {
+ public void run(ReadGraph graph) throws DatabaseException {
processBranchPoints(graph);
}
@Override
//System.out.println("---- PROCESS CONNECTION SEGMENTS BEGIN");
if (!changes.connectionSegments.isEmpty()) {
- graph.syncRequest(new AsyncReadRequest() {
+ graph.syncRequest(new ReadRequest() {
@Override
- public void run(AsyncReadGraph graph) {
+ public void run(ReadGraph graph) throws DatabaseException {
processConnectionSegments(graph);
}
@Override
task = Timing.BEGIN("processRouteGraphConnections");
if (!changes.routeGraphConnections.isEmpty()) {
- graph.syncRequest(new AsyncReadRequest() {
+ graph.syncRequest(new ReadRequest() {
@Override
- public void run(AsyncReadGraph graph) {
+ public void run(ReadGraph graph) throws DatabaseException {
processRouteGraphConnections(graph);
}
@Override
*/
public final class DebugPolicy {
- public static boolean DEBUG = false;
+ public static boolean DEBUG = true;
public static boolean DEBUG_GRAPH_WRITEBACK = false;
public static boolean DEBUG_GRAPH_WRITEBACK_MODIFICATION = false;
public static boolean DEBUG_TERMINAL_SEARCH = false;
- public static boolean DEBUG_LOAD = false;
- public static boolean DEBUG_NODE_LOAD = false;
- public static boolean DEBUG_CONNECTION_LOAD = false;
- public static boolean DEBUG_EDGE_LOAD = false;
- public static boolean DEBUG_CONNECTION_VISUALS_LOAD = false;
- public static boolean DEBUG_TRANSFORM_LOAD = false;
+ public static boolean DEBUG_LOAD = true;
+ public static boolean DEBUG_NODE_LOAD = true;
+ public static boolean DEBUG_CONNECTION_LOAD = true;
+ public static boolean DEBUG_EDGE_LOAD = true;
+ public static boolean DEBUG_CONNECTION_VISUALS_LOAD = true;
+ public static boolean DEBUG_TRANSFORM_LOAD = true;
public static double DETERMINANT_LIMIT_HIGH = 1e24;
public static double DETERMINANT_LIMIT_LOW = 1e-24;
public static double TRANSLATION_LIMIT_HIGH = 1e32;
- public static boolean DEBUG_EDGE_LISTENER = false;
-
- public static boolean DEBUG_GENERAL_ELEMENT_UPDATE = false;
- public static boolean DEBUG_GENERAL_ELEMENT_UPDATE_DETAIL = false;
- public static boolean DEBUG_GRAPH_UPDATE = false;
- public static boolean DEBUG_DIAGRAM_UPDATE = false;
- public static boolean DEBUG_DIAGRAM_UPDATE_DETAIL = false;
- public static boolean DEBUG_NODE_UPDATE = false;
- public static boolean DEBUG_CONNECTION_UPDATE = false;
- public static boolean DEBUG_EDGE_UPDATE = false;
-
- public static boolean DEBUG_LISTENER_BASE = false;
- public static boolean DEBUG_DIAGRAM_LISTENER = false;
- public static boolean DEBUG_NODE_LISTENER = false;
- public static boolean DEBUG_CONNECTION_LISTENER = false;
+ public static boolean DEBUG_EDGE_LISTENER = true;
+
+ public static boolean DEBUG_GENERAL_ELEMENT_UPDATE = true;
+ public static boolean DEBUG_GENERAL_ELEMENT_UPDATE_DETAIL = true;
+ public static boolean DEBUG_GRAPH_UPDATE = true;
+ public static boolean DEBUG_DIAGRAM_UPDATE = true;
+ public static boolean DEBUG_DIAGRAM_UPDATE_DETAIL = true;
+ public static boolean DEBUG_NODE_UPDATE = true;
+ public static boolean DEBUG_CONNECTION_UPDATE = true;
+ public static boolean DEBUG_EDGE_UPDATE = true;
+
+ public static boolean DEBUG_LISTENER_BASE = true;
+ public static boolean DEBUG_DIAGRAM_LISTENER = true;
+ public static boolean DEBUG_NODE_LISTENER = true;
+ public static boolean DEBUG_CONNECTION_LISTENER = true;
/**
* Enables tracing of
org.simantics.modeling;bundle-version="1.1.1",
org.simantics.document.server.io;visibility:=reexport,
org.simantics.scl.db;bundle-version="0.1.3",
- org.slf4j.api
+ org.slf4j.api,
+ org.simantics.threadlog
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.simantics.document.server.Activator
Export-Package: org.simantics.document.server,
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
import org.simantics.db.ReadGraph;
import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.request.VariableRead;
import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.procedure.Listener;
import org.simantics.document.server.JSONObject;
+import org.simantics.threadlog.Task;
+import org.simantics.threadlog.ThreadLog;
public class DocumentRequest extends VariableRead<List<JSONObject>> {
- public static boolean PROFILE = false;
+ public static boolean PROFILE = true;
// Thresholds in microseconds
public static int PROFILE_THRESHOLD_NODEREQUEST = 2000;
public static int PROFILE_THRESHOLD_VALUEREQUEST = 500;
super(var);
}
+ static class NodeRequestE extends NodeRequest {
+
+ static int count1 = 0;
+ static int count = 0;
+
+ public NodeRequestE(Variable node) {
+ super(node);
+ count1++;
+ System.err.println("create NodeRequest count = " + count1);
+ if(count1 == 600)
+ System.err.println("asd");
+ }
+
+ @Override
+ public JSONObject perform(ReadGraph graph) throws DatabaseException {
+ count++;
+ System.err.println("perform NodeRequest count = " + count);
+
+ return super.perform(graph);
+ }
+
+ }
+
@Override
public List<JSONObject> perform(ReadGraph graph) throws DatabaseException {
+
+ Task task = ThreadLog.BEGIN("DocumentRequest " + variable.getURI(graph));
- long s = System.nanoTime();
+ try {
- Set<Variable> nodes = graph.syncRequest(new NodesRequest(variable), TransientCacheAsyncListener.<Set<Variable>>instance());
- HashSet<JSONObject> rs = new HashSet<JSONObject>(); // result
- if(nodes.isEmpty()) {
- return Collections.emptyList();
- }
-
-
- /*TreeMap<String, Variable> nodeMap = new TreeMap<String, Variable>();
-
- for (Variable node : nodes) {
- nodeMap.put(node.getURI(graph), node);
- }
- System.out.println("*************************************************************************");
- for (Variable node : nodeMap.values()) {
- System.out.println(" " + node.getURI(graph));
- }*/
-
- for(Variable node : nodes) {
- rs.add(graph.syncRequest(new NodeRequest(node), TransientCacheAsyncListener.<JSONObject>instance()));
- }
+ long s = System.nanoTime();
+
+ Set<Variable> nodes = graph.syncRequest(new NodesRequest(variable), TransientCacheAsyncListener.<Set<Variable>>instance());
+ HashSet<JSONObject> rs = new HashSet<JSONObject>(); // result
+ if(nodes.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+
+ /*TreeMap<String, Variable> nodeMap = new TreeMap<String, Variable>();
+
+ for (Variable node : nodes) {
+ nodeMap.put(node.getURI(graph), node);
+ }
+ System.out.println("*************************************************************************");
+ for (Variable node : nodeMap.values()) {
+ System.out.println(" " + node.getURI(graph));
+ }*/
+
+ Semaphore done = new Semaphore(0);
+
+ for(Variable node : nodes) {
+
+ graph.asyncRequest(new NodeRequestE(node), new Listener<JSONObject>() {
- ArrayList<JSONObject> result = new ArrayList<JSONObject>(rs);
- Collections.sort(result, new Comparator<JSONObject>() {
+ @Override
+ public void execute(JSONObject result) {
+ synchronized(rs) {
+ rs.add(result);
+ }
+ done.release();
+ }
- @Override
- public int compare(JSONObject o1, JSONObject o2) {
- return o1.id.compareTo(o2.id);
+ @Override
+ public void exception(Throwable t) {
+ t.printStackTrace();
+ done.release();
+ }
+
+ @Override
+ public boolean isDisposed() {
+ return true;
+ }
+
+ });
+
+// rs.add(graph.syncRequest(new NodeRequest(node), TransientCacheAsyncListener.<JSONObject>instance()));
+
+ }
+
+ try {
+ boolean success = done.tryAcquire(nodes.size(), 10, TimeUnit.MILLISECONDS);
+ while(!success) {
+ success = done.tryAcquire(nodes.size(), 10, TimeUnit.MILLISECONDS);
+ System.err.println("still trying to acquire semaphore, avail = " + done.availablePermits() );
+ }
+
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
+
+ ArrayList<JSONObject> result = new ArrayList<JSONObject>(rs);
+ Collections.sort(result, new Comparator<JSONObject>() {
+
+ @Override
+ public int compare(JSONObject o1, JSONObject o2) {
+ return o1.id.compareTo(o2.id);
+ }
+
+ });
+
+ if(PROFILE) {
+ long dura = System.nanoTime()-s;
+ System.err.println("DocumentRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
+ }
+
+ return result;
+
+ } finally {
- });
-
- if(PROFILE) {
- long dura = System.nanoTime()-s;
- System.err.println("DocumentRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
- }
+ task.end();
- return result;
+ }
}
}
\ No newline at end of file
package org.simantics.document.server.request;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
import org.simantics.db.ReadGraph;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.request.VariableRead;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.document.server.DocumentServerUtils.AttributesRequest;
import org.simantics.document.server.JSONObject;
-import org.simantics.utils.datastructures.Pair;
+import org.simantics.threadlog.Task;
+import org.simantics.threadlog.ThreadLog;
public class NodeRequest extends VariableRead<JSONObject> {
long s = System.nanoTime();
- JSONObject staticContent = graph.syncRequest(new AttributesRequest(variable));
+ Task task = ThreadLog.BEGIN("NodeRequest " + variable.getURI(graph));
+
+ try {
- if(DocumentRequest.PROFILE) {
- long dura = System.nanoTime()-s;
- if(dura > DocumentRequest.PROFILE_THRESHOLD_NODEREQUEST * 1e3) {
- System.err.println("NodeRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
- }
- }
+ JSONObject staticContent = graph.syncRequest(new AttributesRequest(variable));
+
+ if(DocumentRequest.PROFILE) {
+ long dura = System.nanoTime()-s;
+ if(dura > DocumentRequest.PROFILE_THRESHOLD_NODEREQUEST * 1e3) {
+ System.err.println("NodeRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
+ }
+ }
- return staticContent;
+
+ return staticContent;
+
+ } finally {
+
+ task.end();
+
+ }
}
public class NodesRequest extends VariableRead<Set<Variable>> {
+ public static boolean PROFILE = false;
+
public NodesRequest(Variable var) {
super(var);
}
nodes.addAll(childNodes);
}
- if(DocumentRequest.PROFILE) {
+ if(PROFILE) {
long dura = System.nanoTime()-s;
System.err.println("NodesRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
}
DocumentationResource DOC = DocumentationResource.getInstance(graph);
+ System.err.println("NodesRequest " + variable.getURI(graph));
+
Resource type = variable.getPossibleType(graph);
if(type == null) return Collections.emptySet();
package org.simantics.document.server.request;
+import java.util.Collections;
import java.util.Map;
import org.simantics.databoard.Bindings;
return Pair.make(type, root);
} else {
Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document));
- Resource componentType = graph.getSingleType(doc);
- Resource root = graph.syncRequest(new IndexRoot(doc));
- // System.err.println("getComponentTypeAndRoot4 " + graph.getPossibleURI(component) + " => " + graph.getPossibleURI(componentType) + " " + graph.getPossibleURI(root));
- return Pair.make(componentType, root);
+ if(doc != null) {
+ Resource componentType = graph.getSingleType(doc);
+ Resource root = graph.syncRequest(new IndexRoot(doc));
+ return Pair.make(componentType, root);
+ } else {
+ System.err.println("component = " + component);
+ Resource root = graph.syncRequest(new IndexRoot(component));
+// Resource componentType = graph.getSingleType(doc);
+ return Pair.make(null, root);
+ }
}
}
throw new IllegalStateException();
public CompilationContext perform(ReadGraph graph)
throws DatabaseException {
RuntimeEnvironment runtimeEnvironment = graph.syncRequest(getRuntimeEnvironmentRequest(parameter.first, parameter.second));
- Map<String, ComponentTypeProperty> propertyMap =
- graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()),
- TransientCacheListener.<Map<String, ComponentTypeProperty>>instance());
- return new CompilationContext(runtimeEnvironment, propertyMap);
+ if(parameter.first != null) {
+ Map<String, ComponentTypeProperty> propertyMap =
+ graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()),
+ TransientCacheListener.<Map<String, ComponentTypeProperty>>instance());
+ return new CompilationContext(runtimeEnvironment, propertyMap);
+ } else {
+ return new CompilationContext(runtimeEnvironment, Collections.emptyMap());
+ }
}
});
}
final AffineTransform transform, final Rectangle2D bounds, final Color color);
}
- private static final boolean DEBUG = false;
+ private static final boolean DEBUG = true;
public static final int ELEMENT_PAINT_PRIORITY = 10;
org.simantics.image.ui;bundle-version="1.0.0",
org.simantics.export.core;bundle-version="1.0.0",
org.slf4j.api,
- org.simantics.graphfile.ontology
+ org.simantics.graphfile.ontology,
+ org.simantics.threadlog
Export-Package: org.simantics.modeling.ui,
org.simantics.modeling.ui.actions,
org.simantics.modeling.ui.chart.property,
import org.simantics.g2d.diagram.DiagramHints;
import org.simantics.g2d.diagram.IDiagram;
import org.simantics.modeling.ui.Activator;
+import org.simantics.threadlog.Task;
+import org.simantics.threadlog.ThreadLog;
import org.simantics.utils.DataContainer;
import org.simantics.utils.threads.ThreadUtils;
try {
Object task = BEGIN("DV.loadDiagram");
+ System.err.println("foo1");
final IDiagram diagram = viewer.loadDiagram(mon.newChild(100), viewer.diagramResource);
if (diagram == null)
return Status.CANCEL_STATUS;
END(task);
+ System.err.println("foo2");
// Start an activation for the input resource.
// This will activate mapping if necessary.
protected static Object BEGIN(String name) {
if (PROFILE) {
- //return ThreadLog.BEGIN(name);
+ return ThreadLog.BEGIN(name);
}
return null;
}
protected static void END(Object task) {
if (PROFILE) {
- //((Task) task).end();
+ ((Task) task).end();
}
}
}
</type>
</target>
+ <target interface="org.simantics.db.ExternalValue">
+ <resource uri="http://www.simantics.org/Modeling-0.0/Functions/sclValue"
+ class="org.simantics.modeling.SCLExternalValue">
+ </resource>
+ </target>
+
</adapters>
\ No newline at end of file
import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource;
import org.simantics.db.layer0.variable.ValueAccessor;
import org.simantics.db.layer0.variable.Variable;
+import org.simantics.diagram.Logger;
import org.simantics.layer0.Layer0;
import org.simantics.scl.runtime.SCLContext;
import org.simantics.scl.runtime.function.Function1;
ExternalValue ev = graph.adapt(converter, ExternalValue.class);
if(ev instanceof ConverterExternalValue) {
- ConverterExternalValue cev = (ConverterExternalValue)ev;
- Function1 fn = cev.getFunction(graph, resource, value, pi.predicate);
- return new ImmutableComponentPropertyContent(pi, value, null, fn);
+ ConverterExternalValue cev = (ConverterExternalValue)ev;
+ try {
+ Function1 fn = cev.getFunction(graph, resource, value, pi.predicate);
+ return new ImmutableComponentPropertyContent(pi, value, null, fn);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ }
} else {
System.err.println("Undefined converter " + graph.getURI(converter));
}
import org.simantics.db.layer0.variable.AbstractChildVariable;
import org.simantics.db.layer0.variable.StandardGraphChildVariable;
import org.simantics.db.layer0.variable.Variable;
+import org.simantics.structural.stubs.StructuralResource2;
public class ImmutableComponentVariable extends AbstractChildVariable {
@Override
public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {
+
+ if(content.procedural) {
+ return new StandardGraphChildVariable(parent, null, content.resource).getPossibleChild(graph, name);
+ }
+
if(content.children == null) return null;
ImmutableComponentVariableContent c = content.children.get(name);
if(c == null) return null;
@Override
public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {
+
+ if(content.procedural) {
+ return new StandardGraphChildVariable(parent, null, content.resource).getChildren(graph);
+ }
+
if(content.children == null) return Collections.emptyList();
ArrayList<Variable> result = new ArrayList<Variable>(content.children.size());
for(ImmutableComponentVariableContent c : content.children.values()) {
result.add(new ImmutableComponentVariable(this, c));
}
return result;
+
}
@Override
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.procedure.adapter.TransientCacheListener;
+import org.simantics.db.common.request.PossibleIndexRoot;
import org.simantics.db.common.utils.NameUtils;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.variable.StandardGraphChildVariable;
@Override
public Variable buildChild(ReadGraph graph, Variable parent, VariableNode<Node> node, Resource child) throws DatabaseException {
- if(graph.isImmutable(child)) {
+ boolean isImmutable = graph.isImmutable(child);
+ Resource possibleIndexRoot = graph.syncRequest(new PossibleIndexRoot(child));
+ if(possibleIndexRoot != null) {
+// String puri = graph.getURI(possibleIndexRoot);
+// if(puri.contains("ModelBroker"))
+// isImmutable = true;
+// if(NameUtils.getSafeName(graph, child).equals("Project"))
+// isImmutable = false;
+ }
+ if(isImmutable) {
+// System.err.println("ImmutableComponentVariableContentRequest " + parent.getURI(graph) + " " + NameUtils.getSafeName(graph, child));
ImmutableComponentVariableContent content = graph.syncRequest(new ImmutableComponentVariableContentRequest(child), TransientCacheListener.instance());
return new ImmutableComponentVariable(parent, content);
} else {
final public Resource resource;
final public String name;
+ boolean procedural = false;
public Map<String,ImmutableComponentVariableContent> children;
public Map<String,ImmutableComponentPropertyContent> properties;
import org.simantics.db.layer0.request.PropertyInfo;
import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource;
import org.simantics.layer0.Layer0;
+import org.simantics.structural.stubs.StructuralResource2;
import org.simantics.structural2.ConnectionImpl;
import org.simantics.structural2.Functions.StructuralChildMapOfResource;
import org.simantics.structural2.queries.ConnectionPointMapOfResource;
Layer0 L0 = Layer0.getInstance(graph);
String name = graph.getRelatedValue(resource, L0.HasName, Bindings.STRING);
ImmutableComponentVariableContent result = new ImmutableComponentVariableContent(resource, name);
+
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ Resource componentType = graph.getPossibleType(resource, STR.Component);
+ if(componentType != null)
+ result.procedural = graph.isInstanceOf(componentType, STR.ProceduralComponentType);
Map<String,PropertyInfo> pis = graph.syncRequest(new UnescapedPropertyMapOfResource(resource));
--- /dev/null
+package org.simantics.modeling;
+
+import org.simantics.db.ConverterExternalValue;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.scl.reflection.ReflectionUtils;
+import org.simantics.scl.reflection.ValueNotFoundException;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.structural2.scl.CompileStructuralValueRequest;
+
+public class SCLExternalValue implements ConverterExternalValue {
+
+ @Override
+ public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException {
+ try {
+ return (T)ReflectionUtils.getValue(ModelingResources.URIs.Functions_sclValue).getValue();
+ } catch (ValueNotFoundException e) {
+ throw new DatabaseException(e);
+ }
+ }
+
+ @Override
+ public Function1 getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return CompileStructuralValueRequest.compile(graph, s, o, p);
+ }
+
+}
SCLContext context = SCLContext.getCurrent();
Object oldGraph = context.put("graph", graph);
try {
- listener.notifyAboutUpdate();
+ synchronized(GraphModuleSourceRepository.class) {
+ listener.notifyAboutUpdate();
+ }
} finally {
listener = null;
context.put("graph", oldGraph);
import org.simantics.scl.runtime.SCLContext;
import org.simantics.scl.runtime.function.Function;
import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.reporting.SCLReportingHandler;
import org.simantics.scl.runtime.tuple.Tuple;
import org.simantics.scl.runtime.tuple.Tuple0;
import org.simantics.utils.DataContainer;
if (graph != null) {
return (T)f.apply(Tuple0.INSTANCE);
} else {
+ final SCLReportingHandler printer = (SCLReportingHandler)SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
return Simantics.getSession().syncRequest(new WriteResultRequest<T>() {
@Override
public T perform(WriteGraph graph) throws DatabaseException {
SCLContext.push(context);
+ SCLReportingHandler oldPrinter = (SCLReportingHandler)context.put(SCLReportingHandler.REPORTING_HANDLER, printer);
ReadGraph oldGraph = (ReadGraph)context.put(GRAPH, graph);
try {
return (T)f.apply(Tuple0.INSTANCE);
} finally {
context.put(GRAPH, oldGraph);
+ context.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
SCLContext.pop();
}
}
}
}
+ public static Function1<Variable, Object> compile(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
+ return graph.syncRequest(new CompileStructuralValueRequest(s, o, p), TransientCacheListener.<Function1<Variable,Object>>instance());
+ }
+
@Override
protected String getExpressionText(ReadGraph graph)
throws DatabaseException {
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
- .
+ .,\
+ scl/
--- /dev/null
+
+importJava "org.simantics.threadlog.ui.ThreadLogController" where
+ @JavaName "start"
+ showThreadLog :: <Proc> ()
super.start(context);
plugin = this;
- ThreadLogController.start();
+ //ThreadLogController.start();
}
/*
version="0.0.0"
unpack="false"/>
+ <plugin
+ id="org.simantics.threadlog"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
</feature>