Skip to content

Commit

Permalink
[sre] Add startWithourAgent() function to the SRE bootstrap utility c…
Browse files Browse the repository at this point in the history
…lass.

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Sep 17, 2017
1 parent 4065ed9 commit 424fbf5
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 7 deletions.
14 changes: 14 additions & 0 deletions main/apiplugins/io.sarl.core/src/io/sarl/core/bootstrap.sarl
Expand Up @@ -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).
Expand All @@ -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.
*
Expand Down Expand Up @@ -185,6 +195,10 @@ final class SRE {
package new {
}

override startWithoutAgent : AgentContext {
null
}

override startAgent(agentCls : Class<? extends Agent>, params : Object*) : UUID {
throw new UnsupportedOperationException
}
Expand Down
Expand Up @@ -909,13 +909,7 @@ public static Kernel startJanusWithModule(Module startupModule, Class<? extends
// Set the boot agent classname
System.setProperty(JanusConfig.BOOT_AGENT, agentCls.getName());
// Get the start-up injection module
assert startupModule != null : "No platform injection module"; //$NON-NLS-1$
final Kernel k = Kernel.create(startupModule);
// Force the bootstrap to reference the created kernel.
final SREBootstrap bootstrap = SRE.getBootstrap();
if (bootstrap instanceof Bootstrap) {
((Bootstrap) bootstrap).setKernel(k);
}
final Kernel k = startWithoutAgent(startupModule);
final Logger logger = k.getLogger();
if (logger != null) {
logger.info(MessageFormat.format(Messages.Boot_22, agentCls.getName()));
Expand All @@ -929,6 +923,42 @@ public static Kernel startJanusWithModule(Module startupModule, Class<? extends
return k;
}

/**
* Start the SRE without an agent. This function prepare the default context.
*
* @param startupModule - the injection module to use for initializing the platform.
* @return the context that is created by the bootstrap. If {@code null} there is no context created.
* @since 2.0.7.0
*/
public static Kernel startWithoutAgent(Module startupModule) {
assert startupModule != null : "No platform injection module"; //$NON-NLS-1$
final Kernel k = Kernel.create(startupModule);
// Force the bootstrap to reference the created kernel.
final SREBootstrap bootstrap = SRE.getBootstrap();
if (bootstrap instanceof Bootstrap) {
((Bootstrap) bootstrap).setKernel(k);
}
return k;
}

/**
* 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 2.0.7.0
*/
public static Kernel startWithoutAgent() {
final Class<? extends Module> 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.
*
Expand Down
Expand Up @@ -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).
Expand Down Expand Up @@ -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();
}

}
Expand Up @@ -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 <code>null</code>.
* @since 2.0.7.0
*/
@Inject
public AgentContext getJanusContext() {
assert this.janusContext != null;
return this.janusContext;
}

/**
* Listener on platform events.
*
Expand Down
Expand Up @@ -24,6 +24,7 @@

import io.sarl.core.SREBootstrap;
import io.sarl.lang.core.Agent;
import io.sarl.lang.core.AgentContext;

/**
* @author $Author: sgalland$
Expand All @@ -48,4 +49,9 @@ public UUID getBootAgentIdentifier() {
throw new IllegalStateException();
}

@Override
public AgentContext startWithoutAgent() {
throw new IllegalStateException();
}

}

0 comments on commit 424fbf5

Please sign in to comment.