@Singleton public abstract class AbstractLifecycleService extends AbstractSreService implements LifecycleService
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractLifecycleService.AgentCreationProcess
A class that is runnable into a thread and implements the creation of a single agent.
|
protected static class |
AbstractLifecycleService.AgentIdProvider
A dynamic provider of UUID for the newly created agents.
|
protected static class |
AbstractLifecycleService.ShutdownLookUp
A class that is looking for stopping the SRE kernel when o more agent is alive.
|
protected static 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 and Description |
---|
AbstractLifecycleService(sarlSpecificationChecker : SarlSpecificationChecker,
creator : AgentCreatorProvider,
lifecycleListener : javax.inject.Provider<LifecycleServiceListener>,
externalContextListener : javax.inject.Provider<ExternalContextMemberListener>,
factories : javax.inject.Provider<Factories>,
agentLevelInjector : javax.inject.Provider<ConfigurableAgentInjector>,
skillProvider : DynamicSkillProvider,
skillUninstaller : SkillUninstaller,
executor : ExecutorService,
loggingService : LoggingService,
lifecycleConfig : LifecycleConfig)
Constructs the service.
|
Modifier and Type | Method and Description |
---|---|
void |
addDynamicSkillProvider(provider : DynamicSkillProvider)
Add a dynamic skill provider that must be used for the agents that are spawned
after the call to this function.
|
void |
addKernelAgentLifecycleListener(listener : KernelAgentLifecycleListener)
Add a listener on the changes related to the kernel agent.
|
void |
addLifecycleServiceListener(agentLifecycleListener : LifecycleServiceListener)
Add a listener on the changes in the current state of an agent.
|
boolean |
canSpawnAgent()
Replies if the service can spawn.
|
protected void |
fireAgentDestroy(agent : Agent,
outerContexts : ConcurrentCollection<ContextReference>,
terminationCause : Object)
Notify the listeners outside the parent context.
|
protected void |
fireAgentDestructionEvents(agent : Agent,
defaultContextBeforeKilled : ContextReference,
leavedContexts : ConcurrentCollection<ContextReference>,
terminationCause : Object) |
protected void |
fireAgentKillFailureEvent(agent : Agent,
innerContext : ContextReference,
cause : Object)
Fire the events related a failure of agent killing.
|
protected void |
fireAgentSpawned(spawningAgent : UUID,
context : Context,
agentClazz : Class<? extends Agent>,
agent : Agent,
initializationParameters : Object*)
Notify the listeners outside the parent context.
|
protected void |
fireAgentSpawnFailureEvent(spawningAgent : UUID,
parent : Context,
agentClazz : Class<? extends Agent>,
cause : String)
Fire the events related a failure of agent spawn.
|
protected void |
fireAgentSpawningEvents(spawningAgent : UUID,
parent : Context,
agentClazz : Class<? extends Agent>,
params : Object[],
spawnedAgent : Agent)
Fire the events related to the agent spawn.
|
protected void |
fireKernelAgentDestroy()
Notifies the listeners about the kernel agent destruction.
|
protected ExecutorService |
getExecutor() |
protected Logger |
getLogger()
Replies the backend logger.
|
boolean |
getSpawnEnable()
Replies if the spawning of agents is enabled or disabled.
|
boolean |
isAlive(life : AgentLife)
Replies if the agent is alive.
|
protected boolean |
isEmptyRootContext(context : Context)
Replies if the given context is the root context and is empty.
|
boolean |
isKillableAgent(life : AgentLife,
id : UUID)
Replies if the given agent could be kill according to the SARL specification.
|
boolean |
killAgent(agent : Agent,
forceKillable : boolean,
terminationCause : Object)
Kill the given agent.
|
protected AbstractLifecycleService.AgentCreationProcess |
newAgentCreatorProcess(spawnQueries : AbstractLifecycleService.SpawnQueries,
spawningAgent : UUID,
parentContext : Context,
agentType : Class<? extends Agent>,
initializationParameters : Object[],
agentIds : (UUID)=>UUID,
agentInstanceCreator : (UUID)=>Agent)
Invoked to create the function for launching an agent.
|
protected void |
onAgentCreated(agent : 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 : Agent)
This function is called each time an agent was killed.
|
protected void |
onStart()
Do something when starting the service.
|
protected void |
onStop()
Do something when stopping the service.
|
void |
removeDynamicSkillProvider(provider : DynamicSkillProvider)
Remove a dynamic skill provider that must be not be used any more for the agents that are spawned.
|
void |
removeKernelAgentLifecycleListener(listener : KernelAgentLifecycleListener)
Remove a listener on the changes related to the kernel agent.
|
void |
removeLifecycleServiceListener(agentLifecycleListener : LifecycleServiceListener)
Remove a listener on the changes in the current state of an agent.
|
void |
setSpawnEnable(enable : boolean)
Enable or disable the spawning of agents.
|
protected void |
spawnAgent(nbAgents : int,
spawningAgent : UUID,
parent : Context,
agentClazz : Class<? extends Agent>,
params : Object[],
agentIds : (UUID)=>UUID)
Spawn agents of the given type, and pass the parameters to its initialization function.
|
void |
spawnAgent(nbAgents : int,
spawningAgent : UUID,
parent : Context,
agentId : UUID,
agentClazz : Class<? extends Agent>,
params : Object[])
Spawn agents of the given type, and pass the parameters to its initialization function.
|
doStart, doStop
addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, doCancelStart, failureCause, isRunning, notifyFailed, notifyStarted, notifyStopped, startAsync, state, stopAsync, toString
public new
(sarlSpecificationChecker : SarlSpecificationChecker,
creator : AgentCreatorProvider,
lifecycleListener : javax.inject.Provider<LifecycleServiceListener>,
externalContextListener : javax.inject.Provider<ExternalContextMemberListener>,
factories : javax.inject.Provider<Factories>,
agentLevelInjector : javax.inject.Provider<ConfigurableAgentInjector>,
skillProvider : DynamicSkillProvider,
skillUninstaller : SkillUninstaller,
executor : ExecutorService,
loggingService : LoggingService,
lifecycleConfig : LifecycleConfig)
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.skillProvider
- the system-wide provider of agent skills.skillUninstaller
- the object this is able to uninstall the skills.executor
- the executor service.lifecycleConfig
- the configuration of the lifecycle service.logger
- the logging service.@Pure
public def
getSpawnEnable() : boolean
LifecycleService
getSpawnEnable
in interface LifecycleService
public def
setSpawnEnable(enable : boolean) : void
LifecycleService
setSpawnEnable
in interface LifecycleService
enable
- indicates if the spawning of agents is enable or disable.@Pure
protected def
getLogger() : Logger
AbstractLifecycleService
protected def
onStart() : void
AbstractSreService
This function is called from AbstractSreService.doStart()
onStart
in class AbstractSreService
protected def
onStop() : void
AbstractSreService
This function is called from AbstractSreService.doStop()
onStop
in class AbstractSreService
public def
addLifecycleServiceListener(agentLifecycleListener : LifecycleServiceListener) : void
LifecycleService
addLifecycleServiceListener
in interface LifecycleService
agentLifecycleListener
- the listener on the any change in the life-cycle of the agent.public def
removeLifecycleServiceListener(agentLifecycleListener : LifecycleServiceListener) : void
LifecycleService
removeLifecycleServiceListener
in interface LifecycleService
agentLifecycleListener
- the listener on the any change in the life-cycle of the agent.public def
addKernelAgentLifecycleListener(listener : KernelAgentLifecycleListener) : void
LifecycleService
addKernelAgentLifecycleListener
in interface LifecycleService
listener
- listener on the spawning events in the local kernel.public def
removeKernelAgentLifecycleListener(listener : KernelAgentLifecycleListener) : void
LifecycleService
removeKernelAgentLifecycleListener
in interface LifecycleService
listener
- listener on the spawning events in the local kernel.protected def
fireAgentDestroy(agent : Agent,
outerContexts : ConcurrentCollection<ContextReference>,
terminationCause : Object) : void
AbstractLifecycleService
agents
- 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.protected def
fireAgentSpawned(spawningAgent : UUID,
context : Context,
agentClazz : Class<? extends Agent>,
agent : Agent,
initializationParameters : Object*) : void
AbstractLifecycleService
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.protected def
fireKernelAgentDestroy() : void
AbstractLifecycleService
public final def
spawnAgent(nbAgents : int,
spawningAgent : UUID,
parent : Context,
agentId : UUID,
agentClazz : Class<? extends Agent>,
params : Object[]) : void
LifecycleService
This function is not blocking until all the agents are spawned.
spawnAgent
in interface LifecycleService
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.agentId
- the identifier of the agent to spawn. If null
the identifier is randomly selected.
If nbAgents
is greater than 1, the agent identifier must be null
.agentClazz
- the type of the agents to spawn.params
- the list of the parameters to pass to the agent initialization function.@Pure
public def
canSpawnAgent() : boolean
AbstractLifecycleService
true
if the service can spawn an agent.protected def
spawnAgent(nbAgents : int,
spawningAgent : UUID,
parent : Context,
agentClazz : Class<? extends Agent>,
params : Object[],
agentIds : (UUID)=>UUID) : void
AbstractLifecycleService
This function is not blocking until all the agents are spawned.
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.callback
- function that is invoked when an identifier of spawned agent is known. The number of times this callback
is invoked depends on the service's implementation. But, the contract is that is must be called at least one time when
one or more agent is spawned.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.@Pure
protected def
newAgentCreatorProcess(spawnQueries : AbstractLifecycleService.SpawnQueries,
spawningAgent : UUID,
parentContext : Context,
agentType : Class<? extends Agent>,
initializationParameters : Object[],
agentIds : (UUID)=>UUID,
agentInstanceCreator : (UUID)=>Agent) : AbstractLifecycleService.AgentCreationProcess
AbstractLifecycleService
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.protected def
onAgentFrameworkStop() : void
AbstractLifecycleService
Within the AbstractLifecycleService
, this function fires the kernel agent
destruction event.
protected def
onAgentCreated(agent : Agent) : void
AbstractLifecycleService
Within the AbstractLifecycleService
, this function does nothing.
agent
- the spawned agent.protected def
fireAgentSpawningEvents(spawningAgent : UUID,
parent : Context,
agentClazz : Class<? extends Agent>,
params : Object[],
spawnedAgent : Agent) : void
AbstractLifecycleService
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.protected def
fireAgentSpawnFailureEvent(spawningAgent : UUID,
parent : Context,
agentClazz : Class<? extends Agent>,
cause : String) : void
AbstractLifecycleService
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.@Pure
protected def
isEmptyRootContext(context : Context) : boolean
AbstractLifecycleService
context
- the agent context to test.true
if the given context is the root context, and it is empty.@Pure
public def
isKillableAgent(life : AgentLife,
id : UUID) : boolean
AbstractLifecycleService
An agent could be kill if is has no internal member.
life
- the internal data structure for the agent.id
- the identifier of the agent.true
if the agent could be killed.@Pure
public def
isAlive(life : AgentLife) : boolean
AbstractLifecycleService
life
- the internal data structure for the agent.true
if the agent is alive.public def
killAgent(agent : Agent,
forceKillable : boolean,
terminationCause : Object) : boolean
LifecycleService
An agent could be killed only if it does not contain sub-agents.
Because the agent reference is passed to this function, only the objects which have this reference could kill the agent.
killAgent
in interface LifecycleService
agent
- the agent to kill.forceKillable
- indicates if the kill of the agent should be tested before killing it.
Usually, the agent cannot be killed when it contains other agents. This flag
enables or disables to the run of this test. If true
, the agent is always assumed
to be killable.terminationCause
- is the cause of the termination of the agent.
If it is null
, the agent does not provide a specific termination cause.true
if the agent was killed by this call; false
if the agent
is unknown or already killed.protected def
onAgentKilled(agent : Agent) : void
AbstractLifecycleService
Within the AbstractLifecycleService
, this function does nothing.
agent
- the killed agent.protected def
fireAgentDestructionEvents(agent : Agent,
defaultContextBeforeKilled : ContextReference,
leavedContexts : ConcurrentCollection<ContextReference>,
terminationCause : Object) : void
protected def
fireAgentKillFailureEvent(agent : Agent,
innerContext : ContextReference,
cause : Object) : void
AbstractLifecycleService
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.public def
addDynamicSkillProvider(provider : DynamicSkillProvider) : void
AbstractLifecycleService
addDynamicSkillProvider
in interface LifecycleService
provider
- is the provider of skills for newly created agents.public def
removeDynamicSkillProvider(provider : DynamicSkillProvider) : void
AbstractLifecycleService
removeDynamicSkillProvider
in interface LifecycleService
provider
- is the provider of skills to be removed.@Pure
protected def
getExecutor() : ExecutorService
Copyright © 2021 the original authors or authors.