io.sarl.api.core
Capacity ExternalContextAccess
All Superinterfaces:
Capacity
All Known Implementing Classes:
ExternalContextAccessSkill
capacity ExternalContextAccess
implements Capacity
Provides functions for accessing and managing the external contexts of an agent.
Property Summary
Modifier and type Property and description
ConcurrentCollection<T> allContexts
Replies all contexts this agent is a member of, including the default context.
AgentContext universeContext
Replies the AgentContext that is the root of all the contexts.
Action Summary
Modifier and type Action and description
abstract void emit(EventSpace,Event,[Scope<T>])
Emits a given event with the provided scope in the given space.
abstract ConcurrentCollection<T> getAllContexts
Replies all contexts this agent is a member of, including the default context.
abstract AgentContext getContext(UUID)
Replies the AgentContext for the given ID.
abstract AgentContext getUniverseContext
Replies the AgentContext that is the root of all the contexts.
abstract boolean isInSpace(Event,Space)
Replies if the given event was emitted in the given space.
abstract boolean isInSpace(Event,SpaceID)
Replies if the given event was emitted in the space with the given identifier..
abstract boolean isInSpace(Event,UUID)
Replies if the given event was emitted in the space with the given identifier..
abstract AgentContext join(UUID,UUID)
Joins a new parent context (a new super holon).
abstract boolean leave(UUID)
Leaves the parent's context.
Property Details
allContexts
val allContexts : ConcurrentCollection<T>
Replies all contexts this agent is a member of, including the default context.

This property is an alias for the action: getAllContexts

Returns:
the list of the known agent contexts.
universeContext
val universeContext : 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.

This property is an alias for the action: getUniverseContext

Returns:
the context that is at the root of all the contexts.
Since:
0.7
Action Details
emit(EventSpace,Event,[Scope<T>])
def emit(EventSpace,Event,[Scope<T>])
Emits a given event with the provided scope in the given space. Equivalent to space.emit(getID,event,scope)
Parameters:
space - the space in which the event should be fired.
event - the event to emit.
scope - the definition of the scope that will be used for selected the receivers of the events. If null, all the agents in the space will receive the event.
Since:
0.6
getAllContexts
def getAllContexts : ConcurrentCollection<T>
Replies all contexts this agent is a member of, including the default context.
Returns:
the list of the known agent contexts.
getContext(UUID)
def getContext(UUID) : AgentContext
Replies the AgentContext for the given ID. The agent must have joined the context before calling this action or use its parentContextID
Parameters:
contextID - the ID of the context to get.
Returns:
the agent context instance.
Throws exception:
See:
getParentID , #join
getUniverseContext
def getUniverseContext : 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.
Returns:
the context that is at the root of all the contexts.
Since:
0.7
isInSpace(Event,Space)
def isInSpace(Event,Space) : boolean
Replies if the given event was emitted in the given space.
Parameters:
event - the event to test.
space - the space in which the event may be.
Returns:
true if the given event was emitted in the given space. Otherwise false .
Since:
0.2
isInSpace(Event,SpaceID)
def isInSpace(Event,SpaceID) : boolean
Replies if the given event was emitted in the space with the given identifier..
Parameters:
event - the event to test.
spaceID - the identifier of the space in which the event may be.
Returns:
true if the given event was emitted in the space with the given identifier. Otherwise false .
Since:
0.2
isInSpace(Event,UUID)
def isInSpace(Event,UUID) : boolean
Replies if the given event was emitted in the space with the given identifier..
Parameters:
event - the event to test.
spaceID - the identifier of the space in which the event may be.
Returns:
true if the given event was emitted in the space with the given identifier. Otherwise false .
Since:
0.2
join(UUID,UUID)
def join(UUID,UUID) : AgentContext

fires ContextJoined, MemberJoined

Joins a new parent context (a new super holon).

The agent will be involved in the context with the ID given by contextID. The parameter expectedDefaultSpaceID is only used to check if the caller of this function knows the ID of the default space in the context to be involved in. Note that the context must already exists, and the default space inside this context must have the same ID as expectedDefaultSpaceID. If the given expectedDefaultSpaceID does not match the ID of the default space in the context contextID, then the access to the context is forbidden.

This actions registers the agent in the default Space of the context with the ID contextID.

This function replies false if one of the following conditions evaluates to true:
  • the agent is not alive;
  • the given context identifier does not corresponds to a known context;
  • the given space identifier is not the one of the context's default space;
  • the given context identifier corresponds to a context in which the agent is already member.
Parameters:
contextID - the identifier of the context to join.
expectedDefaultSpaceID - the known identifier of the default space in the agent context with the given identifier.
Returns:
the joined context. null if the context cannot be joined.
Fires SARL events:
ContextJoined in its inner Context default space (Behaviors#wake)., MemberJoined in its parent Context default Space
Since:
0.12 for the returned context.
leave(UUID)
def leave(UUID) : boolean

fires ContextLeft, MemberLeft

Leaves the parent's context.

Because an agent must be always into a context, this function fails (and replies false) when the context to be leaved is the current default context of the agent, and there is no other context or more than 1 other context that could be elected as the new default context.

This function replies false if one of the following conditions evaluates to true:
  • the agent is not alive;
  • the given context identifier does not corresponds to a known context;
  • the given context identifier corresponds to a context in which the agent is not member.
  • the given context identifier corresponds to a known external context, but there is no other context to be elected as the new default context for the agent.
Parameters:
contextID - the identifier of the context to leave.
Returns:
true if the agent has leaved the context. false if one of the conditions described in the function's comment evaluates to true.
Fires SARL events:
ContextLeft in its inner Context default space (Behaviors#wake)., MemberLeft in its parent Context default Space