Skip to content

Commit

Permalink
[sre] Fixing invalid event dipatching.
Browse files Browse the repository at this point in the history
close #861

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Sep 28, 2018
1 parent 230210e commit 7c41f3c
Show file tree
Hide file tree
Showing 5 changed files with 641 additions and 8 deletions.
Expand Up @@ -243,6 +243,7 @@ private void runInitializationStage(Event event) {
} finally {
setOwnerState(OwnerState.ALIVE);
}
this.agentAsEventListener.fireEnqueuedEvents(this);
} catch (Exception e) {
// Log the exception
final Logging loggingCapacity = getLoggingSkill();
Expand Down Expand Up @@ -396,7 +397,7 @@ public void receiveEvent(Event event) {
}

@SuppressWarnings("synthetic-access")
private void fireEnqueuedEvents(InternalEventBusSkill skill) {
void fireEnqueuedEvents(InternalEventBusSkill skill) {
final Queue<Event> queue = this.buffer;
if (queue != null && !queue.isEmpty()) {
this.buffer = null;
Expand Down
Expand Up @@ -655,8 +655,10 @@ public Agent get() {
assert this.constructor1 != null || this.constructor2 != null;
try {
if (this.constructor1 != null) {
this.constructor1.setAccessible(true);
return this.constructor1.newInstance(this.parentID, agId);
}
this.constructor2.setAccessible(true);
return this.constructor2.newInstance(null, this.parentID, agId);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException exception) {
throw new CannotSpawnException(this.agentType, exception);
Expand Down
Expand Up @@ -23,6 +23,7 @@

import java.text.MessageFormat;
import java.util.UUID;
import java.util.stream.StreamSupport;

import com.google.inject.Inject;

Expand Down Expand Up @@ -171,7 +172,7 @@ protected void doEmit(Event event, Scope<? super Address> scope) {
final UniqueAddressParticipantRepository<Address> particips = getParticipantInternalDataStructure();
final SynchronizedCollection<EventListener> listeners = particips.getListeners();
synchronized (listeners.mutex()) {
listeners.stream()
StreamSupport.stream(listeners.spliterator(), true)
.filter(agent -> scope.matches(getAddress(agent)))
.forEach(agent -> {
this.executorService.submit(new AsyncRunner(agent, event));
Expand Down
Expand Up @@ -143,7 +143,7 @@ public static class MyEvent extends Event {
@SarlSpecification(SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING)
public static class RegisteredInInitializeAgent extends TestingAgent {

public MyBehavior behavior = new MyBehavior(this);
public MyBehavior behavior;


public RegisteredInInitializeAgent(BuiltinCapacitiesProvider provider, UUID parentID, UUID agentID) {
Expand All @@ -153,6 +153,7 @@ public RegisteredInInitializeAgent(BuiltinCapacitiesProvider provider, UUID pare
@Override
protected boolean runAgentTest() {
addResult(this);
this.behavior = new MyBehavior(this);
getSkill(Behaviors.class).registerBehavior(this.behavior);
getSkill(Schedules.class).in(TIMEOUT, (agent) ->
getSkill(Lifecycle.class).killMe());
Expand All @@ -164,7 +165,7 @@ protected boolean runAgentTest() {
@SarlSpecification(SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING)
public static class RegisteredInHandlerAgent extends TestingAgent {

public MyBehavior behavior = new MyBehavior(this);
public MyBehavior behavior;

public RegisteredInHandlerAgent(BuiltinCapacitiesProvider provider, UUID parentID, UUID agentID) {
super(provider, parentID, agentID);
Expand All @@ -173,6 +174,7 @@ public RegisteredInHandlerAgent(BuiltinCapacitiesProvider provider, UUID parentI
@Override
protected boolean runAgentTest() {
addResult(this);
this.behavior = new MyBehavior(this);
getSkill(DefaultContextInteractions.class).emit(new MyEvent());
getSkill(Schedules.class).in(TIMEOUT, (agent) -> getSkill(Lifecycle.class).killMe());
return false;
Expand All @@ -192,7 +194,7 @@ private void onMyEvent(MyEvent occurrence, MyEvent it) {
@SarlSpecification(SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING)
public static class RegisteredInDestroyAgent extends TestingAgent {

public MyBehavior behavior = new MyBehavior(this);
public MyBehavior behavior;

public RegisteredInDestroyAgent(BuiltinCapacitiesProvider provider, UUID parentID, UUID agentID) {
super(provider, parentID, agentID);
Expand All @@ -201,6 +203,7 @@ public RegisteredInDestroyAgent(BuiltinCapacitiesProvider provider, UUID parentI
@Override
protected boolean runAgentTest() {
addResult(this);
this.behavior = new MyBehavior(this);
return true;
}

Expand All @@ -218,7 +221,7 @@ private void onDestroy(Destroy occurrence, Destroy it) {
@SarlSpecification(SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING)
public static class UnregisteredInInitializeAgent extends TestingAgent {

public MyBehavior behavior = new MyBehavior(this);
public MyBehavior behavior;


public UnregisteredInInitializeAgent(BuiltinCapacitiesProvider provider, UUID parentID, UUID agentID) {
Expand All @@ -228,6 +231,7 @@ public UnregisteredInInitializeAgent(BuiltinCapacitiesProvider provider, UUID pa
@Override
protected boolean runAgentTest() {
addResult(this);
this.behavior = new MyBehavior(this);
getSkill(Behaviors.class).registerBehavior(this.behavior);
getSkill(Behaviors.class).unregisterBehavior(this.behavior);
getSkill(Schedules.class).in(TIMEOUT, (agent) -> getSkill(Lifecycle.class).killMe());
Expand All @@ -239,7 +243,7 @@ protected boolean runAgentTest() {
@SarlSpecification(SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING)
public static class UnregisteredInHandlerAgent extends TestingAgent {

public MyBehavior behavior = new MyBehavior(this);
public MyBehavior behavior;

public UnregisteredInHandlerAgent(BuiltinCapacitiesProvider provider, UUID parentID, UUID agentID) {
super(provider, parentID, agentID);
Expand All @@ -248,6 +252,7 @@ public UnregisteredInHandlerAgent(BuiltinCapacitiesProvider provider, UUID paren
@Override
protected boolean runAgentTest() {
addResult(this);
this.behavior = new MyBehavior(this);
getSkill(Behaviors.class).registerBehavior(this.behavior);
getSkill(DefaultContextInteractions.class).emit(new MyEvent());
getSkill(Schedules.class).in(TIMEOUT, (agent) -> getSkill(Lifecycle.class).killMe());
Expand All @@ -268,7 +273,7 @@ private void onMyEvent(MyEvent occurrence, MyEvent it) {
@SarlSpecification(SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING)
public static class UnregisteredInDestroyAgent extends TestingAgent {

public MyBehavior behavior = new MyBehavior(this);
public MyBehavior behavior;

public UnregisteredInDestroyAgent(BuiltinCapacitiesProvider provider, UUID parentID, UUID agentID) {
super(provider, parentID, agentID);
Expand All @@ -277,6 +282,7 @@ public UnregisteredInDestroyAgent(BuiltinCapacitiesProvider provider, UUID paren
@Override
protected boolean runAgentTest() {
addResult(this);
this.behavior = new MyBehavior(this);
return true;
}

Expand Down

0 comments on commit 7c41f3c

Please sign in to comment.