1 package org.simantics.db.layer0.genericrelation;
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.Session;
6 import org.simantics.db.common.request.ParametrizedPrimitiveRead;
7 import org.simantics.db.layer0.adapter.GenericRelationIndex;
8 import org.simantics.db.procedure.Listener;
9 import org.simantics.utils.datastructures.Pair;
11 class ExternalRequest extends ParametrizedPrimitiveRead<Pair<GenericRelationIndex,Resource>,Long> implements Runnable {
13 private static long value = 0;
14 private Session session;
15 private Listener<Long> procedure;
17 public ExternalRequest(GenericRelationIndex index, Resource model) {
18 super(Pair.make(index, model));
22 public void register(ReadGraph graph, Listener<Long> procedure) {
23 synchronized(getClass()) {
24 procedure.execute(value++);
26 if(procedure.isDisposed()) return;
27 assert(this.procedure == null);
28 this.session = graph.getSession();
29 this.procedure = procedure;
30 parameter.first.addListener(graph, parameter.second, this);
34 public void unregistered() {
35 parameter.first.removeListener(session, parameter.second, this);
40 synchronized(getClass()) {
41 procedure.execute(value++);