X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Futil%2FRuntimeEnvironmentRequest.java;h=9f6b8fe530799439bcad7f3d9fab82319fc2733a;hb=44342cceec520f2e869ff43757ebb1d079f47030;hp=cde4e02396a48515a31ca777e1265870e8903cc8;hpb=8561e498009a25473db94b0e667866aa79de90b1;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RuntimeEnvironmentRequest.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RuntimeEnvironmentRequest.java index cde4e0239..9f6b8fe53 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RuntimeEnvironmentRequest.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RuntimeEnvironmentRequest.java @@ -26,36 +26,36 @@ public class RuntimeEnvironmentRequest extends UnaryRead callback; - - UpdateListenerImpl(EnvironmentSpecification environmentSpecification, Listener callback) { - this.environmentSpecification = environmentSpecification; - this.callback = callback; - } + + final EnvironmentSpecification environmentSpecification; + final Listener callback; + + UpdateListenerImpl(EnvironmentSpecification environmentSpecification, Listener callback) { + this.environmentSpecification = environmentSpecification; + this.callback = callback; + } @Override public void notifyAboutUpdate() { - if(callback.isDisposed()) { - stopListening(); - return; - } - getRuntimeEnvironment(environmentSpecification, callback, this); + if(callback.isDisposed()) { + stopListening(); + return; + } + getRuntimeEnvironment(environmentSpecification, callback, this); } - }; + }; public static void getRuntimeEnvironment(EnvironmentSpecification environmentSpecification, Listener callback, UpdateListenerImpl listener) { try { - + SCLContext context = SCLContext.getCurrent(); - + RuntimeEnvironment env; Object graph = context.get("graph"); if(graph == null) @@ -63,7 +63,7 @@ public class RuntimeEnvironmentRequest extends UnaryRead() { @Override public RuntimeEnvironment perform(ReadGraph graph) throws DatabaseException { - + SCLContext sclContext = SCLContext.getCurrent(); Object oldGraph = sclContext.get("graph"); try { @@ -94,7 +94,7 @@ public class RuntimeEnvironmentRequest extends UnaryRead(mainModuleUri) { - - UpdateListenerImpl sclListener; - - @Override - public void register(ReadGraph graph, Listener procedure) { - - SCLContext context = SCLContext.getCurrent(); - Object oldGraph = context.put("graph", graph); - try { - - if(procedure.isDisposed()) { - getRuntimeEnvironment(environmentSpecification, procedure, null); - } else { - sclListener = new UpdateListenerImpl(environmentSpecification, procedure); - sclListener.notifyAboutUpdate(); - } - - } finally { - context.put("graph", oldGraph); - } - - } - - @Override - public void unregistered() { - if(sclListener != null) - sclListener.stopListening(); + + return graph.syncRequest(new ParametrizedPrimitiveRead(mainModuleUri) { + + UpdateListenerImpl sclListener; + + @Override + public void register(ReadGraph graph, Listener procedure) { + + SCLContext context = SCLContext.getCurrent(); + Object oldGraph = context.put("graph", graph); + try { + + if(procedure.isDisposed()) { + getRuntimeEnvironment(environmentSpecification, procedure, null); + } else { + sclListener = new UpdateListenerImpl(environmentSpecification, procedure); + sclListener.notifyAboutUpdate(); + } + + } finally { + context.put("graph", oldGraph); } - - }); + + } + + @Override + public void unregistered() { + if(sclListener != null) + sclListener.stopListening(); + } + + }); } - + @Override public int hashCode() { return 31*getClass().hashCode() + super.hashCode();