diff --git a/main/apiplugins/io.sarl.core/src/io/sarl/core/bootstrap.sarl b/main/apiplugins/io.sarl.core/src/io/sarl/core/bootstrap.sarl index d915353283..4400e0b46a 100644 --- a/main/apiplugins/io.sarl.core/src/io/sarl/core/bootstrap.sarl +++ b/main/apiplugins/io.sarl.core/src/io/sarl/core/bootstrap.sarl @@ -24,6 +24,7 @@ import java.lang.ref.SoftReference import java.util.ServiceLoader import java.util.UUID import io.sarl.lang.core.Agent +import io.sarl.lang.core.AgentContext /** * Represents an access point to the SARL run-time environment (SRE). @@ -39,6 +40,15 @@ import io.sarl.lang.core.Agent */ interface SREBootstrap { + /** + * Start the SRE without an agent. + This function prepare the default context. + * + * @return the context that is created by the bootstrap. If {@code null} there is no context created. + * @since 0.7 + */ + def startWithoutAgent : AgentContext + /** * Launch the SRE and the first agent in the kernel. * @@ -185,6 +195,10 @@ final class SRE { package new { } + override startWithoutAgent : AgentContext { + null + } + override startAgent(agentCls : Class, params : Object*) : UUID { throw new UnsupportedOperationException } diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Boot.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Boot.java index 395deb7d38..d090d9850e 100644 --- a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Boot.java +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Boot.java @@ -909,13 +909,7 @@ public static Kernel startJanusWithModule(Module startupModule, Class startupModule = JanusConfig.getSystemPropertyAsClass(Module.class, + JanusConfig.INJECTION_MODULE_NAME, + JanusConfig.INJECTION_MODULE_NAME_VALUE); + assert startupModule != null : "No platform injection module"; //$NON-NLS-1$ + try { + return startWithoutAgent(startupModule.newInstance()); + } catch (Exception exception) { + throw new IllegalStateException(exception); + } + } + /** * Replies the tool for exiting the application. * diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Bootstrap.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Bootstrap.java index 0dae9bb8c8..b0458c158c 100644 --- a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Bootstrap.java +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Bootstrap.java @@ -29,6 +29,7 @@ import io.sarl.core.SREBootstrap; import io.sarl.lang.core.Agent; +import io.sarl.lang.core.AgentContext; /** * Represents an access point to the SARL run-time environment (SRE). @@ -86,4 +87,16 @@ public UUID getBootAgentIdentifier() { return Boot.getBootAgentIdentifier(); } + @Override + public AgentContext startWithoutAgent() { + Kernel kern = this.kernel; + if (kern == null) { + synchronized (this) { + this.kernel = Boot.startWithoutAgent(); + kern = this.kernel; + } + } + return kern.getJanusContext(); + } + } diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/kernel/Kernel.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/kernel/Kernel.java index 07189a378c..f4c48d74da 100644 --- a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/kernel/Kernel.java +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/kernel/Kernel.java @@ -221,6 +221,18 @@ void setJanusContext(@io.janusproject.kernel.annotations.Kernel AgentContext jan this.janusContext = janusContext; } + /** + * Replies the Janus context of the kernel. + * + * @return the Janus root context. It must be never null. + * @since 2.0.7.0 + */ + @Inject + public AgentContext getJanusContext() { + assert this.janusContext != null; + return this.janusContext; + } + /** * Listener on platform events. * diff --git a/tests/io.sarl.core.tests/src/test/java/io/sarl/core/tests/SREBootstrapMock.java b/tests/io.sarl.core.tests/src/test/java/io/sarl/core/tests/SREBootstrapMock.java index 04ee542bad..88badcdf42 100644 --- a/tests/io.sarl.core.tests/src/test/java/io/sarl/core/tests/SREBootstrapMock.java +++ b/tests/io.sarl.core.tests/src/test/java/io/sarl/core/tests/SREBootstrapMock.java @@ -24,6 +24,7 @@ import io.sarl.core.SREBootstrap; import io.sarl.lang.core.Agent; +import io.sarl.lang.core.AgentContext; /** * @author $Author: sgalland$ @@ -48,4 +49,9 @@ public UUID getBootAgentIdentifier() { throw new IllegalStateException(); } + @Override + public AgentContext startWithoutAgent() { + throw new IllegalStateException(); + } + }