io.sarl.sre.janus.services.lifecycle
Class AbstractLifecycleService
All Superinterfaces:
LifecycleService, org.arakhne.afc.services.IService
All Known Subclasses:
InjectionBasedLifecycleService, StandardLifecycleService
@javax.inject.Singleton
@org.eclipse.xtext.xbase.lib.XbaseGenerated
abstract class AbstractLifecycleService
extends java.lang.Object
implements LifecycleService
Implementation of a spawning service that is based on the other services of the SRE platform.
Maven Group Identifier:
io.sarl.sre.janus
Maven Artifact Identifier:
janus.kernel
Property Summary
Modifier and type Property and description
protected ExecutorService executor
protected java.util.logging.Logger logger
Replies the backend logger.
java.lang.Class<T> referenceType
boolean spawnEnable
Nested Type Summary
Modifier and type Type and description
protected class AbstractLifecycleService.AgentCreationProcess
A class that is runnable into a thread and implements the creation of a single agent.
protected class AbstractLifecycleService.AgentIdProvider
A dynamic provider of UUID for the newly created agents.
protected class AbstractLifecycleService.ShutdownLookUp
A class that is looking for stopping the SRE kernel when o more agent is alive.
protected class AbstractLifecycleService.SpawnQueries
A class enables to update the number of "spawn" queries and supporting the multiple spawning of agents within a single call to "spawn".
Constructor Summary
Action Summary
Modifier and type Action and description
void addDynamicSkillProvider(DynamicSkillProvider)
Add a dynamic skill provider that must be used for the agents that are spawned after the call to this function.
void addKernelAgentLifecycleListener(KernelAgentLifecycleListener)
void addLifecycleServiceListener(LifecycleServiceListener)
boolean canSpawnAgent
Replies if the service can spawn.
protected void fireAgentDestroy(Agent,ConcurrentCollection<T>,Object)
Notify the listeners outside the parent context.
protected void fireAgentDestructionEvents(Agent,ContextReference,ConcurrentCollection<T>,Object)
protected void fireAgentKillFailureEvent(Agent,ContextReference,Object)
Fire the events related a failure of agent killing.
protected void fireAgentSpawned(UUID,Context,Class<T>,Agent,Object*)
Notify the listeners outside the parent context.
protected void fireAgentSpawnFailureEvent(UUID,Context,Class<T>,String)
Fire the events related a failure of agent spawn.
protected void fireAgentSpawningEvents(UUID,Context,Class<T>,Object,Agent)
Fire the events related to the agent spawn.
protected void fireKernelAgentDestroy
Notifies the listeners about the kernel agent destruction.
protected ExecutorService getExecutor
protected java.util.logging.Logger getLogger
Replies the backend logger.
java.lang.Class<T> getReferenceType
boolean getSpawnEnable
boolean isAlive(AgentLife)
Replies if the agent is alive.
protected boolean isEmptyRootContext(Context)
Replies if the given context is the root context and is empty.
boolean isKillableAgent(AgentLife,UUID)
Replies if the given agent could be kill according to the SARL specification.
boolean killAgent(Agent,boolean,Object)
protected AgentCreationProcess newAgentCreatorProcess(SpawnQueries,UUID,Context,Class<T>,Object,Function0<Result>,Function1<Param,Result>)
Invoked to create the function for launching an agent.
protected void onAgentCreated(Agent)
This function is called each time an agent was created.
protected void onAgentFrameworkStop
This function is called each time the agent framework should be stopped.
protected void onAgentKilled(Agent)
This function is called each time an agent was killed.
void onStart
void onStop
void removeDynamicSkillProvider(DynamicSkillProvider)
Remove a dynamic skill provider that must be not be used any more for the agents that are spawned.
void removeKernelAgentLifecycleListener(KernelAgentLifecycleListener)
void removeLifecycleServiceListener(LifecycleServiceListener)
void setSpawnEnable(boolean)
protected void spawnAgent(int,UUID,Context,Class<T>,Object,Function0<Result>)
Spawn agents of the given type, and pass the parameters to its initialization function.
final void spawnAgent(int,UUID,Context,UUID,Class<T>,Object)
Property Details
executor
protected val executor : ExecutorService

This property is an alias for the action: getExecutor

logger
protected val logger : java.util.logging.Logger
Replies the backend logger.

This property is an alias for the action: getLogger

Returns:
the logger.
referenceType
val referenceType : java.lang.Class<T>

This property is an alias for the action: getReferenceType

spawnEnable
var spawnEnable : boolean

This property is an alias for the action: getSpawnEnable

Constructor Details
new(SarlSpecificationChecker,AgentCreatorProvider,Provider<T>,Provider<T>,Provider<T>,Provider<T>,DynamicSkillProvider,SkillUninstaller,ExecutorService,LoggingService,LifecycleConfig)
new(SarlSpecificationChecker,AgentCreatorProvider,Provider<T>,Provider<T>,Provider<T>,Provider<T>,DynamicSkillProvider,SkillUninstaller,ExecutorService,LoggingService,LifecycleConfig)
Constructs the service.
Parameters:
sarlSpecificationChecker - the tool for checking the validity of the SARL specification supported by the agents to launch.
creator - the provider of agent creators that is used when spawning agents.
lifecycleListener - the listener at the platform scale on life cycle events.
externalContextListener - the listener at the platform scale on context membership events.
factories - the provider of factories tool.
agentLevelInjector - injector that is used only for injecting a specific agent.
skillProvider - the system-wide provider of agent skills.
skillUninstaller - the object this is able to uninstall the skills.
executor - the executor service.
loggingService - the logging service.
lifecycleConfig - the configuration of the lifecycle service.
Action Details
addDynamicSkillProvider(DynamicSkillProvider)
def addDynamicSkillProvider(DynamicSkillProvider)
Add a dynamic skill provider that must be used for the agents that are spawned after the call to this function.
Parameters:
provider - is the provider of skills for newly created agents.
addKernelAgentLifecycleListener(KernelAgentLifecycleListener)
def addKernelAgentLifecycleListener(KernelAgentLifecycleListener)
addLifecycleServiceListener(LifecycleServiceListener)
def addLifecycleServiceListener(LifecycleServiceListener)
canSpawnAgent
def canSpawnAgent : boolean
Replies if the service can spawn.
Returns:
true if the service can spawn an agent.
fireAgentDestroy(Agent,ConcurrentCollection<T>,Object)
protected def fireAgentDestroy(Agent,ConcurrentCollection<T>,Object)
Notify the listeners outside the parent context.
Parameters:
agent - the destroyed agent.
outerContexts - the contexts in which the agent w destroyed.
terminationCause - is the cause of the termination of the agent. If it is null, the agent does not provide a cause for its termination.
Since:
0.12
fireAgentDestructionEvents(Agent,ContextReference,ConcurrentCollection<T>,Object)
protected def fireAgentDestructionEvents(Agent,ContextReference,ConcurrentCollection<T>,Object)
fireAgentKillFailureEvent(Agent,ContextReference,Object)
protected def fireAgentKillFailureEvent(Agent,ContextReference,Object)
Fire the events related a failure of agent killing.
Parameters:
agent - the agent that has failed to commit a suicide.
innerContext - the context in which the events should be fired.
cause - the cause of the failure.
fireAgentSpawned(UUID,Context,Class<T>,Agent,Object*)
protected def fireAgentSpawned(UUID,Context,Class<T>,Agent,Object*)
Notify the listeners outside the parent context.
Parameters:
spawningAgent - the spawning agent.
context - the context in which the agents were spawned.
agentClazz - the type of the spawned agents.
agent - the spawned agent.
initializationParameters - the initialization parameters.
fireAgentSpawnFailureEvent(UUID,Context,Class<T>,String)
protected def fireAgentSpawnFailureEvent(UUID,Context,Class<T>,String)
Fire the events related a failure of agent spawn.
Parameters:
spawningAgent - the creator.
parent - the context in which the agents are created.
agentClazz - the type of the spawned agents.
cause - the cause of the failure.
fireAgentSpawningEvents(UUID,Context,Class<T>,Object,Agent)
protected def fireAgentSpawningEvents(UUID,Context,Class<T>,Object,Agent)
Fire the events related to the agent spawn.
Parameters:
spawningAgent - the creator, if null, the root agent (Janus kernel) is assumed.
parent - the context in which the agents are created.
agentClazz - the type of the spawned agents.
spawnedAgent - the spawned agent.
fireKernelAgentDestroy
protected def fireKernelAgentDestroy
Notifies the listeners about the kernel agent destruction.
getExecutor
protected def getExecutor : ExecutorService
getLogger
protected def getLogger : java.util.logging.Logger
Replies the backend logger.
Returns:
the logger.
getReferenceType
def getReferenceType : java.lang.Class<T>
getSpawnEnable
def getSpawnEnable : boolean
isAlive(AgentLife)
def isAlive(AgentLife) : boolean
Replies if the agent is alive. This function is usually invoked to determine if the agent is killable.
Parameters:
life - the internal data structure for the agent.
Returns:
true if the agent is alive.
Since:
0.11
isEmptyRootContext(Context)
protected def isEmptyRootContext(Context) : boolean
Replies if the given context is the root context and is empty.
Parameters:
context - the agent context to test.
Returns:
true if the given context is the root context, and it is empty. Otherwise false .
isKillableAgent(AgentLife,UUID)
def isKillableAgent(AgentLife,UUID) : boolean
Replies if the given agent could be kill according to the SARL specification.

An agent could be kill if is has no internal member.
Parameters:
life - the internal data structure for the agent.
id - the identifier of the agent.
Returns:
true if the agent could be killed.
killAgent(Agent,boolean,Object)
def killAgent(Agent,boolean,Object) : boolean
newAgentCreatorProcess(SpawnQueries,UUID,Context,Class<T>,Object,Function0<Result>,Function1<Param,Result>)
protected def newAgentCreatorProcess(SpawnQueries,UUID,Context,Class<T>,Object,Function0<Result>,Function1<Param,Result>) : AgentCreationProcess
Invoked to create the function for launching an agent. This function is defined for enabling overrding.
Parameters:
spawnQueries - the object ot track the spawn queries.
spawningAgent - is the identifier of the agent that has invoked the spawn function.
parentContext - is the context in which the agent is created.
agentType - is the type of agent to be created.
initializationParameters - is the list of parameters to pass to the agent for its initialization.
agentIds - is a lambda that replies a valid UUID for an agent. This lambda is thread-safe.
agentInstanceCreator - is a lambda that enables to create an instance of agent. This lambda is thread-safe.
Since:
0.12
onAgentCreated(Agent)
protected def onAgentCreated(Agent)
This function is called each time an agent was created. This function is provided for being overridden by the sub-classes of the current class.

Within the AbstractLifecycleService, this function does nothing.
Parameters:
agent - the spawned agent.
Since:
0.8.0
onAgentFrameworkStop
protected def onAgentFrameworkStop
This function is called each time the agent framework should be stopped. This function is provided for being overridden by the sub-classes of the current class.

Within the AbstractLifecycleService, this function fires the kernel agent destruction event.
Since:
0.8.0
onAgentKilled(Agent)
protected def onAgentKilled(Agent)
This function is called each time an agent was killed. This function is provided for being overridden by the sub-classes of the current class.

Within the AbstractLifecycleService, this function does nothing.
Parameters:
agent - the killed agent.
Since:
0.8.0
onStart
def onStart
onStop
def onStop
removeDynamicSkillProvider(DynamicSkillProvider)
def removeDynamicSkillProvider(DynamicSkillProvider)
Remove a dynamic skill provider that must be not be used any more for the agents that are spawned.
Parameters:
provider - is the provider of skills to be removed.
removeKernelAgentLifecycleListener(KernelAgentLifecycleListener)
def removeKernelAgentLifecycleListener(KernelAgentLifecycleListener)
removeLifecycleServiceListener(LifecycleServiceListener)
def removeLifecycleServiceListener(LifecycleServiceListener)
setSpawnEnable(boolean)
def setSpawnEnable(boolean)
spawnAgent(int,UUID,Context,Class<T>,Object,Function0<Result>)
protected def spawnAgent(int,UUID,Context,Class<T>,Object,Function0<Result>)
Spawn agents of the given type, and pass the parameters to its initialization function.

This function is not blocking until all the agents are spawned.
Parameters:
nbAgents - the number of agents to spawn.
spawningAgent - the agent which is spawning, if null, the root agent (Janus kernel) is assumed.
parent - the parent entity that is creating the agents.
agentClazz - the type of the agents to spawn.
params - the list of the parameters to pass to the agent initialization function.
agentIds - is the lambda that must be used to compute the UUID of an agent. This lambda should be thread-safe.
spawnAgent(int,UUID,Context,UUID,Class<T>,Object)
def spawnAgent(int,UUID,Context,UUID,Class<T>,Object)