Skip to content

Commit

Permalink
Replacing the last remaining Iterable by concurrentlikneddeque
Browse files Browse the repository at this point in the history
  • Loading branch information
ngaud committed Mar 25, 2020
1 parent f0b4141 commit 7c54888
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
Expand Up @@ -92,7 +92,7 @@ capacity InternalEventBusCapacity {
* @since 0.7
*/
def fireEventAndWait(^event : Event, gatherEvents : boolean, thrownExceptions : boolean,
listener : Object) : Iterable<Event>
listener : Object) : ConcurrentLinkedDeque<Event>

/** Fire the given event into the agent context, and wait for the execution of all the event handlers.
*
Expand All @@ -111,7 +111,7 @@ capacity InternalEventBusCapacity {
* to the agent's logger, and never thrown outside this function.
* @return the events that were received during the execution of this function. These events are not fired into the agent context yet.
*/
def fireEventAndWait(^event : Event, gatherEvents : boolean, thrownExceptions : boolean) : Iterable<Event>
def fireEventAndWait(^event : Event, gatherEvents : boolean, thrownExceptions : boolean) : ConcurrentLinkedDeque<Event>

/** Fire the given event into the agent context, and do not wait for the termination of the event handlers.
*
Expand Down
Expand Up @@ -59,6 +59,7 @@ import java.util.UUID
import java.util.logging.Logger

import static io.sarl.sre.services.lifecycle.AgentLife.*
import java.util.concurrent.ConcurrentLinkedDeque

/** Emit the space platform events.
*
Expand Down Expand Up @@ -219,7 +220,7 @@ class AgentEventEmitter implements LifecycleServiceListener {
defSpace.emit(null, ^event) [agentId != it.UUID]
}

override agentDestroyed(^agent : Agent, outerContexts : Iterable<ContextReference>) {
override agentDestroyed(^agent : Agent, outerContexts : ConcurrentLinkedDeque<ContextReference>) {
this.logger.config[MessageFormat::format(Messages::AgentEventEmitter_1, ^agent.ID)]
val size = outerContexts.size
val spaces = <EventSpace>newArrayOfSize(size)
Expand Down
Expand Up @@ -54,6 +54,7 @@ abstract class AbstractCreatorFactory implements AgentCreatorProvider {
*/
def mergeSkillProviders(providers : ConcurrentLinkedDeque<DynamicSkillProvider>) : DynamicSkillProvider {
if (providers !== null) {
//TODO tune this iterator call that seems to be useless or not the best option
var iterator = providers.iterator
if (iterator.hasNext) {
if (this.skillProvider === null) {
Expand All @@ -74,9 +75,9 @@ abstract class AbstractCreatorFactory implements AgentCreatorProvider {
*/
private static class CreatorFactory0 implements DynamicSkillProvider {

val providers : Iterable<DynamicSkillProvider>
val providers : ConcurrentLinkedDeque<DynamicSkillProvider>

new (providers : Iterable<DynamicSkillProvider>) {
new (providers : ConcurrentLinkedDeque<DynamicSkillProvider>) {
this.providers = providers
}

Expand Down
Expand Up @@ -146,7 +146,7 @@ abstract class AbstractLifecycleService extends AbstractSreService implements Li
* @param agents the destroyed agent.
* @param outerContexts the contexts in which the agent w destroyed.
*/
protected def fireAgentDestroy(^agent : Agent, outerContexts : Iterable<ContextReference>) {
protected def fireAgentDestroy(^agent : Agent, outerContexts : ConcurrentLinkedDeque<ContextReference>) {
// Notify the listeners on the spawn events (not restricted to a single agent)
this.globalListeners.notifyListeners(typeof(LifecycleServiceListener)) [
agentDestroyed(^agent, outerContexts)
Expand Down Expand Up @@ -435,7 +435,7 @@ abstract class AbstractLifecycleService extends AbstractSreService implements Li
}

protected def fireAgentDestructionEvents(^agent : Agent, defaultContextBeforeKilled : ContextReference,
leavedContexts : Iterable<ContextReference>) {
leavedContexts : ConcurrentLinkedDeque<ContextReference>) {
// Leave the default context because the ExternalContextAccessSkill does not fire events related
// to the default space.
this.platformContextEventEmitter.memberLeft(defaultContextBeforeKilled.context,
Expand Down
Expand Up @@ -26,6 +26,7 @@ import io.sarl.lang.core.DynamicSkillProvider
import io.sarl.sre.services.context.Context
import java.util.EventListener
import java.util.UUID
import java.util.concurrent.ConcurrentLinkedDeque

/**
* This service provides the tools to manage the life-cycle of the agents.
Expand Down Expand Up @@ -144,7 +145,7 @@ interface LifecycleServiceListener extends EventListener {
* @param agent the destroyed agent.
* @param outerContexts the contexts from which the given agent were removed after its destruction.
*/
def agentDestroyed(^agent : Agent, outerContexts : Iterable<ContextReference>)
def agentDestroyed(^agent : Agent, outerContexts : ConcurrentLinkedDeque<ContextReference>)

/**
* Invoked when the agent spawning has failed.
Expand Down
Expand Up @@ -191,7 +191,7 @@ skill InternalEventBusSkill extends Skill implements InternalEventBusCapacity {
return new ConcurrentLinkedDeque<Event>
}

def fireEventAndWait(^event : Event, gatherEvents : boolean, thrownExceptions : boolean) : Iterable<Event> {
def fireEventAndWait(^event : Event, gatherEvents : boolean, thrownExceptions : boolean) : ConcurrentLinkedDeque<Event> {
if (getLife(owner).state.blockingEventHandling) {
val logger = getLogger
if (gatherEvents) {
Expand All @@ -211,7 +211,7 @@ skill InternalEventBusSkill extends Skill implements InternalEventBusCapacity {
}
this.eventBus.immediateDispatch(^event, thrownExceptions, logger)
}
return emptyList
return new ConcurrentLinkedDeque<Event>
}

def fireEvent(^event : Event) {
Expand Down

0 comments on commit 7c54888

Please sign in to comment.