import java.util.LinkedList;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.DevelopmentKeys;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.impl.DebugPolicy;
import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.procedure.AsyncProcedure;
import org.simantics.db.procedure.Listener;
import org.simantics.db.request.ExternalRead;
import org.simantics.db.request.RequestFlags;
+import org.simantics.utils.Development;
final public class ExternalReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> implements Listener<T> {
final LinkedList<T> items = new LinkedList<T>();
- protected ExternalRead<T> request;
+ protected ExternalRead<T> id;
protected ReadGraphImpl graph;
protected boolean registered = false;
@Override
int makeHash() {
- return request.hashCode();
+ return id.hashCode();
}
@Override
public Object getOriginalRequest() {
- return request;
+ return id;
}
@Override
@Override
public void discard() {
- request.unregistered();
- request = null;
+ id.unregistered();
+ id = null;
graph = null;
super.discard();
}
@Override
- public void setPending() {
+ public void setPending(QuerySupport querySupport) {
//if(result != NO_RESULT) {
//new Exception("result = " + result).printStackTrace();
//}
public ExternalReadEntry(ExternalRead<T> request, ReadGraphImpl graph) {
assert request != null;
- this.request = request;
+ this.id = request;
this.graph = graph;
}
@Override
public void except(Throwable t) {
- if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: excepted " + this);
+ if (Development.DEVELOPMENT) {
+ if(Development.<Boolean>getProperty(DevelopmentKeys.CACHE_ENTRY_STATE, Bindings.BOOLEAN)) {
+ System.err.println("[QUERY STATE]: excepted " + this);
+ }
+ }
+
if(statusOrException != DISCARDED) {
statusOrException = EXCEPTED;
result = t;
}
// Reschedule
if(!items.isEmpty()) {
- graph.processor.updatePrimitive(request);
+ graph.processor.updatePrimitive(id);
}
}
@Override
public String toString() {
- if(request == null) return "DISCARDED ExternalRead";
- else return request.toString();
+ if(id == null) return "DISCARDED ExternalRead";
+ else return id.toString();
}
};
@Override
public String toString() {
- if(request == null) return "DISCARDED ExternalRead " + System.identityHashCode(this);
- else return request.toString() + " " + + System.identityHashCode(this);
+ if(id == null) return "DISCARDED ExternalRead " + System.identityHashCode(this);
+ else return id.toString() + " " + + System.identityHashCode(this);
}
@Override
ReadGraphImpl queryGraph = graph.withParent(this);
if(!registered) {
- request.register(graph, this);
+ id.register(graph, this);
registered = true;
}
- queryGraph.asyncBarrier.waitBarrier(request, graph);
+ queryGraph.asyncBarrier.waitBarrier(id, graph);
} catch (Throwable t) {
synchronized(items) {
items.addLast(result);
- graph.processor.updatePrimitive(request);
+ graph.processor.updatePrimitive(id);
// TODO: implement flags/logic in ExternalRead to state that all but the latest request result can be evaporated
// In some cases where data is produced really fast this might be necessary but currently this queueing will do.
}