Skip to content

Commit

Permalink
[sre][docs] Rename startJanus.
Browse files Browse the repository at this point in the history
close #557

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Dec 16, 2016
1 parent 4784cfb commit 357b1fe
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
Expand Up @@ -71,7 +71,6 @@ describe "Run SARL Agent from a Java Program" {
class MyProgram {
static def main(args : String[]) : void {
Boot::startJanus(
null,
typeof(MyAgent),
args)
}
Expand Down Expand Up @@ -107,7 +106,6 @@ describe "Run SARL Agent from a Java Program" {
class MyProgram {
static def main(args : String[]) : void {
var janusKernel = Boot::startJanus(
null,
typeof(MyAgent),
args)
janusKernel.spawn(typeof(MyAgent), args)
Expand Down
Expand Up @@ -404,7 +404,7 @@ private static Class<? extends Agent> loadAgentClass(String fullyQualifiedName)
* Main function that is parsing the command line and launching the first agent.
*
* @param args - command line arguments
* @see #startJanus(Class, Class, Object...)
* @see #startJanus(Class, Object...)
*/
public static void main(String[] args) {
try {
Expand All @@ -428,7 +428,7 @@ public static void main(String[] args) {
final Class<? extends Agent> agent = loadAgentClass(agentToLaunch);
assert agent != null;

startJanus((Class<? extends Module>) null, (Class<? extends Agent>) agent, freeArgs);
startJanus(agent, freeArgs);
} catch (ChuckNorrisException exception) {
// Be silent
return;
Expand Down Expand Up @@ -802,12 +802,12 @@ public static void setPropertiesFrom(File propertyFile) throws IOException {

/**
* Replies the identifier of the boot agent from the system's properties. The boot agent is launched with
* {@link #startJanus(Class, Class, Object...)}.
* {@link #startJanus(Class, Object...)}.
*
* @return the identifier of the boot agent, or <code>null</code> if it is unknown.
* @since 2.0.2.0
* @see JanusConfig#BOOT_AGENT_ID
* @see #startJanus(Class, Class, Object...)
* @see #startJanus(Class, Object...)
*/
public static UUID getBootAgentIdentifier() {
final String id = JanusConfig.getSystemProperty(JanusConfig.BOOT_AGENT_ID);
Expand All @@ -821,6 +821,31 @@ public static UUID getBootAgentIdentifier() {
return null;
}

/**
* Launch the Janus kernel and the first agent in the kernel.
*
* <p>Thus function does not parse the command line. See {@link #main(String[])} for the command line management. When this
* function is called, it is assumed that all the system's properties are correctly set.
*
* <p>The platformModule parameter permits to specify the injection module to use. The injection module is in change of
* creating/injecting all the components of the platform. The default injection module is retreived from the system property
* with the name stored in {@link JanusConfig#INJECTION_MODULE_NAME}. The default type for the injection module is stored in
* the constant {@link JanusConfig#INJECTION_MODULE_NAME_VALUE}.
*
* <p>The function {@link #getBootAgentIdentifier()} permits to retreive the identifier of the launched agent.
*
* @param agentCls - type of the first agent to launch.
* @param params - parameters to pass to the agent as its initliazation parameters.
* @return the kernel that was launched.
* @throws Exception - if it is impossible to start the platform.
* @see #main(String[])
* @see #getBootAgentIdentifier()
*/
public static Kernel startJanus(Class<? extends Agent> agentCls, Object... params)
throws Exception {
return startJanusWithModuleType(null, agentCls, params);
}

/**
* Launch the Janus kernel and the first agent in the kernel.
*
Expand All @@ -840,18 +865,19 @@ public static UUID getBootAgentIdentifier() {
* @param params - parameters to pass to the agent as its initliazation parameters.
* @return the kernel that was launched.
* @throws Exception - if it is impossible to start the platform.
* @since 0.5
* @see #main(String[])
* @see #getBootAgentIdentifier()
*/
public static Kernel startJanus(Class<? extends Module> platformModule, Class<? extends Agent> agentCls, Object... params)
public static Kernel startJanusWithModuleType(Class<? extends Module> platformModule, Class<? extends Agent> agentCls, Object... params)
throws Exception {
Class<? extends Module> startupModule = platformModule;
if (startupModule == null) {
startupModule = JanusConfig.getSystemPropertyAsClass(Module.class, JanusConfig.INJECTION_MODULE_NAME,
JanusConfig.INJECTION_MODULE_NAME_VALUE);
}
assert startupModule != null : "No platform injection module"; //$NON-NLS-1$
return startJanus(startupModule.newInstance(), agentCls, params);
return startJanusWithModule(startupModule.newInstance(), agentCls, params);
}

/**
Expand All @@ -872,10 +898,11 @@ public static Kernel startJanus(Class<? extends Module> platformModule, Class<?
* @param params - parameters to pass to the agent as its initliazation parameters.
* @return the kernel that was launched.
* @throws Exception - if it is impossible to start the platform.
* @since 0.5
* @see #main(String[])
* @see #getBootAgentIdentifier()
*/
public static Kernel startJanus(Module startupModule, Class<? extends Agent> agentCls, Object... params) throws Exception {
public static Kernel startJanusWithModule(Module startupModule, Class<? extends Agent> agentCls, Object... params) throws Exception {
// Set the boot agent classname
System.setProperty(JanusConfig.BOOT_AGENT, agentCls.getName());
// Get the start-up injection module
Expand Down
Expand Up @@ -1042,7 +1042,7 @@ public static class StartTests extends AbstractJanusTest {

@Test
public void startJanus() throws Exception {
Kernel kernel = Boot.startJanus(TestModule.class, AgentMock.class, "param1", "param2", "param3");
Kernel kernel = Boot.startJanusWithModuleType(TestModule.class, AgentMock.class, "param1", "param2", "param3");

assertNotNull(kernel);

Expand Down Expand Up @@ -1075,13 +1075,13 @@ public void getBootAgentIdentifier_notStarted() throws Exception {

@Test
public void getBootAgentIdentifier_started() throws Exception {
Boot.startJanus(TestModule.class, AgentMock.class);
Boot.startJanusWithModuleType(TestModule.class, AgentMock.class);
assertEquals(ID, Boot.getBootAgentIdentifier());
}

@Test
public void getBootAgentIdentifier_startedAgain() throws Exception {
Boot.startJanus(TestModule.class, AgentMock.class);
Boot.startJanusWithModuleType(TestModule.class, AgentMock.class);
assertEquals(ID, Boot.getBootAgentIdentifier());
assertEquals(ID, Boot.getBootAgentIdentifier());
}
Expand Down
Expand Up @@ -265,7 +265,7 @@ public void write(byte[] b, int off, int len) throws IOException {
module = Modules.override(new StandardJanusPlatformModule()).with(new ErrorLogTestingModule(this.results));
}
Boot.setOffline(offline);
this.janusKernel = Boot.startJanus(module, type, getAgentInitializationParameters());
this.janusKernel = Boot.startJanusWithModule(module, type, getAgentInitializationParameters());
Logger current = this.janusKernel.getLogger();
while (current.getParent() != null && current.getParent() != current) {
current = current.getParent();
Expand Down

0 comments on commit 357b1fe

Please sign in to comment.