X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Futil%2FRuntimeEnvironmentRequest.java;h=cde4e02396a48515a31ca777e1265870e8903cc8;hp=6fbe36854ad99bd8934bd843a094be4742496e7e;hb=e19c37f84fd1ce2d946578f7c05f3e45444ba67a;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 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 6fbe36854..cde4e0239 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 @@ -1,8 +1,5 @@ package org.simantics.db.layer0.util; -import java.util.HashMap; -import java.util.Map; - import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ParametrizedPrimitiveRead; @@ -33,7 +30,7 @@ public class RuntimeEnvironmentRequest extends UnaryRead callback; @@ -46,68 +43,64 @@ public class RuntimeEnvironmentRequest extends UnaryRead callback, UpdateListenerImpl listener) { - - try { - - SCLContext context = SCLContext.getCurrent(); - - RuntimeEnvironment env; - Object graph = context.get("graph"); - if(graph == null) - try { - env = SimanticsInternal.getSession().syncRequest(new Read() { - @Override - public RuntimeEnvironment perform(ReadGraph graph) throws DatabaseException { - - SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.get("graph"); - try { - sclContext.put("graph", graph); - return SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment( - environmentSpecification, - callback.getClass().getClassLoader(), listener); - } catch (ImportFailureException e) { - throw new DatabaseException(e); - } catch (Throwable t) { - throw new DatabaseException(t); - } finally { - sclContext.put("graph", oldGraph); - } + 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) + try { + env = SimanticsInternal.getSession().syncRequest(new Read() { + @Override + public RuntimeEnvironment perform(ReadGraph graph) throws DatabaseException { + + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.get("graph"); + try { + sclContext.put("graph", graph); + return SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment( + environmentSpecification, + callback.getClass().getClassLoader(), listener); + } catch (ImportFailureException e) { + throw new DatabaseException(e); + } catch (Throwable t) { + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); } - }); - } catch (DatabaseException e) { - callback.exception(e); - return; - } - else - env = SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment( - environmentSpecification, - callback.getClass().getClassLoader(), listener); - callback.execute(env); - } catch (ImportFailureException e) { - callback.exception(new DatabaseException(e)); - } - - } - - }; + } + }); + } catch (DatabaseException e) { + callback.exception(e); + return; + } + else + env = SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment( + environmentSpecification, + callback.getClass().getClassLoader(), listener); + callback.execute(env); + } catch (ImportFailureException e) { + callback.exception(new DatabaseException(e)); + } - // This is needed to prevent garbage collection from collecting UpdateListenerImpls - // -ModuleRepository only makes a weak reference to the listener - final static Map map = new HashMap(); + } @Override public RuntimeEnvironment perform(ReadGraph graph) throws DatabaseException { final EnvironmentSpecification environmentSpecification = EnvironmentSpecification.of( "Builtin", "", - "Prelude", "", + "StandardLibrary", "", "Simantics/All", ""); fillEnvironmentSpecification(environmentSpecification); Resource mainModule = Layer0Utils.getPossibleChild(graph, parameter, "SCLMain"); @@ -120,7 +113,9 @@ public class RuntimeEnvironmentRequest extends UnaryRead(mainModuleUri) { - + + UpdateListenerImpl sclListener; + @Override public void register(ReadGraph graph, Listener procedure) { @@ -129,12 +124,11 @@ public class RuntimeEnvironmentRequest extends UnaryRead