Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sre] Janus provides a SRE bootstrap service.
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
1 parent
a109e3b
commit 0535178
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Bootstrap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters