Skip to content

Commit

Permalink
[core] Allow null scope.
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 Feb 14, 2017
1 parent 7842138 commit 3f65b32
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Expand Up @@ -474,7 +474,7 @@ capacity DefaultContextInteractions {
* ...
* const mySpawnArgs = ...
* const myAgentAddr = MyAgent.spawn(mySpawnArgs)
* defaultSpace.emit(new StartWorkingEvent, AddressScope::scope(myAgentAddr)
* defaultSpace.emit(new StartWorkingEvent, AddressScope::scope(myAgentAddr))
* </code>
* <p>The equivalent using receive could be written:
* <code>
Expand Down
Expand Up @@ -23,6 +23,7 @@

import java.util.UUID;

import org.eclipse.xtext.xbase.lib.Inline;
import org.eclipse.xtext.xbase.lib.Pure;

/**
Expand Down Expand Up @@ -58,6 +59,7 @@ public interface EventSpace extends Space {
*
* @param event - the event to emit in the space.
*/
@Inline(value = "emit($1, null)")
void emit(Event event);

}
Expand Up @@ -122,10 +122,10 @@ public final void emit(Event event, Scope<Address> scope) {
assert event != null;
assert event.getSource() != null : "Every event must have a source"; //$NON-NLS-1$
assert this.getSpaceID().equals(event.getSource().getSpaceId()) : "The source address must belong to this space"; //$NON-NLS-1$

try {
this.network.publish(scope, event);
doEmit(event, scope);
final Scope<Address> scopeInstance = (scope == null) ? Scopes.<Address>allParticipants() : scope;
this.network.publish(scopeInstance, event);
doEmit(event, scopeInstance);
} catch (Throwable e) {
this.logger.error(Messages.AbstractEventSpace_0, event, scope, e);
}
Expand All @@ -141,7 +141,7 @@ public final void emit(Event event, Scope<Address> scope) {
* @see #emit(Event, Scope)
*/
public final void emit(Event event) {
emit(event, Scopes.<Address>allParticipants());
emit(event, null);
}

/**
Expand All @@ -153,6 +153,8 @@ public final void emit(Event event) {
* @param scope - description of the scope of the event, i.e. the receivers of the event.
*/
protected void doEmit(Event event, Scope<? super Address> scope) {
assert scope != null;
assert event != null;
synchronized (this.participants) {
for (final EventListener agent : this.participants.getListeners()) {
if (scope.matches(getAddress(agent))) {
Expand Down

0 comments on commit 3f65b32

Please sign in to comment.