Skip to content

Commit

Permalink
[sre] Janus provides a SRE bootstrap service.
Browse files Browse the repository at this point in the history
The bootstrap service enables to launch an agent on a SRE without
knowning the SRE itself.

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Sep 12, 2017
1 parent a109e3b commit 0535178
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sre/io.janusproject/io.janusproject.plugin/pom.xml
Expand Up @@ -17,6 +17,7 @@
<properties>
<jkernel.version>2.${project.version}</jkernel.version>
<cliRunnerMainClass>io.janusproject.Boot</cliRunnerMainClass>
<bootstrap>io.janusproject.Bootstrap</bootstrap>
</properties>

<build>
Expand Down Expand Up @@ -115,12 +116,14 @@
<noMoreOption>--</noMoreOption>
</commandLineOptions>
<mainClass>${cliRunnerMainClass}</mainClass>
<bootstrap>${bootstrap}</bootstrap>
</configuration>

<executions>
<execution>
<goals>
<goal>updatemanifest</goal>
<goal>addbootstrap</goal>
</goals>
</execution>
</executions>
Expand Down
Expand Up @@ -57,6 +57,8 @@
import io.janusproject.services.network.NetworkConfig;
import io.janusproject.util.LoggerCreator;

import io.sarl.core.SRE;
import io.sarl.core.SREBootstrap;
import io.sarl.lang.SARLVersion;
import io.sarl.lang.core.Agent;

Expand Down Expand Up @@ -909,6 +911,11 @@ public static Kernel startJanusWithModule(Module startupModule, Class<? extends
// 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 Logger logger = k.getLogger();
if (logger != null) {
logger.info(MessageFormat.format(Messages.Boot_22, agentCls.getName()));
Expand Down
@@ -0,0 +1,89 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2017 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.janusproject;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import io.janusproject.kernel.Kernel;

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

/**
* Represents an access point to the SARL run-time environment (SRE).
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.6
*/
public final class Bootstrap implements SREBootstrap {

private volatile Kernel kernel;

/** Change the current kernel.
*
* @param kernel the kernel.
*/
void setKernel(Kernel kernel) {
this.kernel = kernel;
}

@Override
public UUID startAgent(Class<? extends Agent> agentCls, Object... params) throws Exception {
final Kernel kern = this.kernel;
if (kern == null) {
synchronized (this) {
this.kernel = Boot.startJanus(agentCls, params);
}
return Boot.getBootAgentIdentifier();
}
return kern.spawn(agentCls, params);
}

@Override
public Iterable<UUID> startAgent(int nbAgents, Class<? extends Agent> agentCls, Object... params) throws Exception {
Kernel kern = this.kernel;
if (kern == null) {
final List<UUID> spawned = new ArrayList<>();
synchronized (this) {
this.kernel = Boot.startJanus(agentCls, params);
kern = this.kernel;
}
spawned.add(Boot.getBootAgentIdentifier());
if (nbAgents > 1) {
spawned.addAll(kern.spawn(nbAgents - 1, agentCls, params));
}
return spawned;
}
return kern.spawn(nbAgents, agentCls, params);
}

@Override
public UUID getBootAgentIdentifier() {
return Boot.getBootAgentIdentifier();
}

}
Expand Up @@ -31,6 +31,7 @@
import org.w3c.dom.Element;

import io.janusproject.Boot;
import io.janusproject.Bootstrap;
import io.janusproject.JanusConfig;
import io.janusproject.eclipse.buildpath.JanusClasspathContainer;

Expand Down Expand Up @@ -76,6 +77,7 @@ public JanusSREInstall() {
this.location = this.janusSREInstallPath.toPortableString();
setName(JanusConfig.JANUS_DEFAULT_PLATFORM_NAME);
setMainClass(Boot.class.getName());
setBootstrap(Bootstrap.class.getName());
//
setClassPathEntries(dependencies.getTransitiveRuntimeClasspathEntries(true));
}
Expand Down

0 comments on commit 0535178

Please sign in to comment.