Skip to content

Commit

Permalink
[core] Add getUniverseContext within ExternalContextAccess.
Browse files Browse the repository at this point in the history
close #773

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Oct 17, 2017
1 parent f0344b6 commit fea2155
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
Expand Up @@ -11,6 +11,7 @@ top-right context in the figure above.
documented -->
[:Fact:]{typeof(io.sarl.core.[:externalcontextaccess!]).shouldHaveMethods(
"[:getcontext](getContext)(java.util.UUID) : io.sarl.lang.core.AgentContext",
"[:getuniversecontext](getUniverseContext) : io.sarl.lang.core.AgentContext",
"[:getallcontexts](getAllContexts) : io.sarl.lang.util.SynchronizedIterable",
"[:join](join)(java.util.UUID, java.util.UUID) : boolean",
"[:leave](leave)(java.util.UUID) : boolean",
Expand Down Expand Up @@ -60,6 +61,24 @@ may use its `[:getParentID](getParentID)` for accessing the context in which it
[:End:]


## Retrieving the Universe Context

In all the SARL application, a default context exists. It's name is the Universe context.
It is fully managed by the SARL run-time environment.
For retrieving this particular context, this built-in capacity provides the following function:

[:Success:]
package io.sarl.docs.reference.bic
import io.sarl.lang.core.AgentContext
import java.util.UUID
interface Tmp {
[:On]
def [:getuniversecontext!]() : AgentContext
[:Off]
}
[:End:]


## Retrieving the Contexts of an Agent

The following function enables an agent to retrieve all the contexts in which it is involved:
Expand Down
11 changes: 11 additions & 0 deletions main/apiplugins/io.sarl.core/src/io/sarl/core/bic.sarl
Expand Up @@ -65,6 +65,17 @@ capacity ExternalContextAccess {
@Pure
def getContext(contextID : UUID): AgentContext

/**
* Replies the AgentContext that is the root of all the contexts.
* Usually, the Universe context is managed by the SARL run-time environment.
* The agent may be a member of this context, or not.
*
* @return the context that is at the root of all the contexts.
* @since 0.7
*/
@Pure
def getUniverseContext(): AgentContext

/**
* Joins a new parent context (a new super holon).
* <p>
Expand Down
Expand Up @@ -151,6 +151,11 @@ public AgentContext getContext(UUID contextID) {
return this.contextRepository.getContext(contextID);
}

@Override
public AgentContext getUniverseContext() {
return this.contextRepository.getUniverseContext();
}

@Override
public boolean join(UUID futureContext, UUID futureContextDefaultSpaceID) {
assert futureContext != null;
Expand Down
Expand Up @@ -98,6 +98,8 @@ public class StandardContextSpaceService extends AbstractDependentService implem
*/
private ContextDMapListener dmapListener;

private AgentContext janusContext;

/**
* Log service.
*/
Expand All @@ -110,6 +112,17 @@ public StandardContextSpaceService() {
//
}

/**
* Change the Janus context of the kernel.
*
* @param janusContext the new janus kernel. It must be never <code>null</code>.
*/
@Inject
void setJanusContext(@io.janusproject.kernel.annotations.Kernel AgentContext janusContext) {
assert janusContext != null;
this.janusContext = janusContext;
}

@Override
public final Class<? extends Service> getServiceType() {
return ContextSpaceService.class;
Expand Down Expand Up @@ -279,6 +292,11 @@ public AgentContext getContext(UUID contextID) {
}
}

@Override
public AgentContext getUniverseContext() {
return this.janusContext;
}

@Override
public void addContextRepositoryListener(ContextRepositoryListener listener) {
this.listeners.add(ContextRepositoryListener.class, listener);
Expand Down
Expand Up @@ -126,6 +126,13 @@ public interface ContextSpaceService extends DependentService {
*/
AgentContext getContext(UUID contextID);

/**
* Returns the {@link AgentContext} that is the root of all the contexts.
*
* @return the root {@link AgentContext}.
*/
AgentContext getUniverseContext();

/**
* Add a listener on the context repository events.
*
Expand Down
Expand Up @@ -48,7 +48,7 @@ public void setUp() {
*/
@Test
public void memberCount() {
assertEquals(9, this.type.getDeclaredMethods().length);
assertEquals(10, this.type.getDeclaredMethods().length);
}

/**
Expand All @@ -65,6 +65,13 @@ public void getContext() {
assertMethod("getContext", AgentContext.class, UUID.class); //$NON-NLS-1$
}

/**
*/
@Test
public void getUniverseContext() {
assertMethod("getUniverseContext", AgentContext.class); //$NON-NLS-1$
}

/**
*/
@Test
Expand Down

0 comments on commit fea2155

Please sign in to comment.