Skip to content

Commit

Permalink
[core] Reason of the call to a killMe passes from Throwable to Object.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Dec 3, 2020
1 parent 19976f1 commit 8420cfa
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 31 deletions.
Expand Up @@ -477,13 +477,13 @@ capacity Lifecycle {
* <li>the agent is not alive.</li>
* </ul>
*
* @param abnormalTerminationCause indicates the cause of an abnormal termination of the agent.
* If this argument is {@code null}, the agent terminates in a "normal" situation.
* @param terminationCause indicates the cause of the termination of the agent.
* If this argument is {@code null}, the agent terminates without specific cause.
* @fires AgentKilled in DefaultSpace of all Contexts to which this agent belongs
* @fires Destroy inside the agent
* @since 0.12
*/
def killMe(abnormalTerminationCause : Throwable = null) fires AgentKilled, Destroy
def killMe(terminationCause : Object = null) fires AgentKilled, Destroy
}


Expand Down
Expand Up @@ -177,22 +177,25 @@ final event AgentKilled {
*/
val agentType : String

/** The exception that is the cause of the killing of the agent.
* If it is {@code null}, the agent has commited a suicide in "normal" situation.
/** The object that is the cause of the killing of the agent or explains the cause
* of the "abnormal" killing.
* If it is {@code null}, the agent has committed a suicide in "normal" situation.
*
* @since 0.12
*/
val abnormalTerminationCause : Throwable
val terminationCause : Object

/** Construct the event.
*
* @param source the address of the emitter.
* @param agentType fully qualified name of the type of the agent.
* @param terminationCause cause of the termination of the agent, or {@code null} if there is
* no specific termination cause.
*/
new (source : Address, agentType : String, abnormalTerminationCause : Throwable) {
new (source : Address, agentType : String, terminationCause : Object) {
setSource(source)
this.agentType = agentType
this.abnormalTerminationCause = abnormalTerminationCause
this.terminationCause = terminationCause
}

}
Expand Down
Expand Up @@ -276,7 +276,7 @@ class Kernel {

lifeCycleService.addLifecycleServiceListener(new LifecycleServiceAdapter() {
override agentDestroyed(^agent : Agent, outerContexts : ConcurrentLinkedDeque<ContextReference>,
abnormalTerminationCause : Throwable) {
terminationCause : Object) {
agentIds.remove(^agent.ID)
}
})
Expand Down
Expand Up @@ -225,7 +225,7 @@ class AgentEventEmitter implements LifecycleServiceListener {
}

override agentDestroyed(^agent : Agent, outerContexts : ConcurrentLinkedDeque<ContextReference>,
abnormalTerminationCause : Throwable) {
terminationCause : Object) {
this.logger.config[MessageFormat::format(Messages::AgentEventEmitter_1, ^agent.ID)]
val size = outerContexts.size
val spaces = <EventSpace>newArrayOfSize(size)
Expand All @@ -235,7 +235,7 @@ class AgentEventEmitter implements LifecycleServiceListener {
val ^event = new AgentKilled(
contextReference.addressInDefaultSpace,
^agent.class.name,
abnormalTerminationCause)
terminationCause)
spaces.set(i, contextReference.defaultSpace)
events.set(i, ^event)
i++
Expand Down
Expand Up @@ -174,15 +174,15 @@ abstract class AbstractLifecycleService extends AbstractSreService implements Li
*
* @param agents the destroyed agent.
* @param outerContexts the contexts in which the agent w destroyed.
* @param abnormalTerminationCause is the cause of the abnormal termination of the agent.
* If it is {@code null}, the agent is terminated in a "normal" situation.
* @param terminationCause is the cause of the termination of the agent.
* If it is {@code null}, the agent does not provide a cause for its termination.
* @since 0.12
*/
protected def fireAgentDestroy(^agent : Agent, outerContexts : ConcurrentLinkedDeque<ContextReference>,
abnormalTerminationCause : Throwable) {
terminationCause : Object) {
// Notify the listeners on the spawn events (not restricted to a single agent)
this.globalListeners.notifyListeners(typeof(LifecycleServiceListener)) [
agentDestroyed(^agent, outerContexts, abnormalTerminationCause)
agentDestroyed(^agent, outerContexts, terminationCause)
]
}

Expand Down Expand Up @@ -443,7 +443,7 @@ abstract class AbstractLifecycleService extends AbstractSreService implements Li
life.state.isAlive
}

def killAgent(^agent : Agent, forceKillable : boolean, abnormalTerminationCause : Throwable) : boolean {
def killAgent(^agent : Agent, forceKillable : boolean, terminationCause : Object) : boolean {
val agentId = ^agent.ID
val life = getLifeOrNull(^agent)
if (life !== null && life.isAlive) {
Expand All @@ -452,7 +452,7 @@ abstract class AbstractLifecycleService extends AbstractSreService implements Li
var defaultContext = life.defaultContext
var contexts = life.stop(this.skillUninstaller, getLogger)
^agent.onAgentKilled
fireAgentDestructionEvents(^agent, defaultContext, contexts, abnormalTerminationCause)
fireAgentDestructionEvents(^agent, defaultContext, contexts, terminationCause)
// Test if the agent is the latest on this kernel.
defaultContext?.context?.startShutdownLookup
return true
Expand Down Expand Up @@ -485,13 +485,13 @@ abstract class AbstractLifecycleService extends AbstractSreService implements Li

protected def fireAgentDestructionEvents(^agent : Agent, defaultContextBeforeKilled : ContextReference,
leavedContexts : ConcurrentLinkedDeque<ContextReference>,
abnormalTerminationCause : Throwable) {
terminationCause : Object) {
// Leave the default context because the ExternalContextAccessSkill does not fire events related
// to the default space.
this.platformContextEventEmitter.memberLeft(defaultContextBeforeKilled.context,
defaultContextBeforeKilled.defaultSpace.spaceID, ^agent.ID, ^agent.class.name)
// Fire the agent destroy event
^agent.fireAgentDestroy(leavedContexts, abnormalTerminationCause)
^agent.fireAgentDestroy(leavedContexts, terminationCause)
}

/** Replies the dynamic skill providers that are defined by the user of the service.
Expand Down
Expand Up @@ -85,15 +85,15 @@ interface LifecycleService extends Service {
* @param agent the agent to kill.
* @param 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 {@code true}, the agent is allways assumed
* enables or disables to the run of this test. If {@code true}, the agent is always assumed
* to be killable.
* @param abnormalTerminationCause is the cause of the abnormal termination of the agent.
* If it is {@code null}, the agent is terminated in "normal" situation.
* @param terminationCause is the cause of the termination of the agent.
* If it is {@code null}, the agent does not provide a specific termination cause.
* @return {@code true} if the agent was killed by this call; {@code false} if the agent
* is unknown or already killed.
* @since 0.12
*/
def killAgent(^agent : Agent, forceKillable : boolean, abnormalTerminationCause : Throwable) : boolean
def killAgent(^agent : Agent, forceKillable : boolean, terminationCause : Object) : boolean

/**
* Add a listener on the changes in the current state of an agent.
Expand Down Expand Up @@ -167,11 +167,11 @@ interface LifecycleServiceListener extends EventListener {
* Invoked when the agent is destroyed.
* @param agent the destroyed agent.
* @param outerContexts the contexts from which the given agent were removed after its destruction.
* @param abnormalTerminationCause the cause of the termination of the agent in an abnormal case.
* If it is {@code null}, the agent was destroyed in a "normal" situation.
* @param terminationCause the cause of the termination of the agent.
* If it is {@code null}, the agent was destroyed without providing a reason.
*/
def agentDestroyed(^agent : Agent, outerContexts : ConcurrentLinkedDeque<ContextReference>,
abnormalTerminationCause : Throwable)
terminationCause : Object)

/**
* Invoked when the agent spawning has failed.
Expand Down Expand Up @@ -200,7 +200,7 @@ interface LifecycleServiceListener extends EventListener {
}

override agentDestroyed(^agent : Agent, outerContexts : ConcurrentLinkedDeque<ContextReference>,
abnormalTerminationCause : Throwable) {
abnormalTerminationCause : Object) {
}

override agentSpawnFailure(spawningAgent : UUID, parent : Context, agentType : Class<? extends Agent>) {
Expand Down
Expand Up @@ -56,7 +56,7 @@ skill LifecycleSkill implements Lifecycle {
}

@SuppressWarnings("discouraged_reference")
def killMe(abnormalTerminationCause : Throwable) {
def killMe(terminationCause : Object) {
var postTreatment : Runnable = null
var state = getLife(owner).state
// The agent should be killed by a specific asynchronous event.
Expand All @@ -66,7 +66,7 @@ skill LifecycleSkill implements Lifecycle {
postTreatment = [getLife(owner).state = AgentState::DYING]
} else if (state == AgentState::ALIVE) {
// Synchronous killing
postTreatment = [this.lifecycle.killAgent(this.owner, false, abnormalTerminationCause)]
postTreatment = [this.lifecycle.killAgent(this.owner, false, terminationCause)]
}
// Never return from the killMe
Thread::yield
Expand Down
Expand Up @@ -64,7 +64,7 @@ skill LifeSkill implements Lifecycle {
this.installOrder.intValue;
}

def killMe(abnormalTerminationCause : Throwable) {
def killMe(terminationCause : Object) {
}

def spawn(agentType : Class<? extends Agent>, params : Object*) {
Expand Down
Expand Up @@ -74,7 +74,7 @@ public void agentType() {
*/
@Test
public void constructor() {
assertConstructor(Address.class, String.class, Throwable.class);
assertConstructor(Address.class, String.class, Object.class);
}

}

0 comments on commit 8420cfa

Please sign in to comment.