io.sarl.sre.janus.skills.internal
Class EventBus
@org.eclipse.xtext.xbase.lib.XbaseGenerated
class EventBus
extends java.lang.Object
The class in charge of dispatching every single events coming from the outside of this agent (i.e. from a space) or from an agent's behavior.
Maven Group Identifier:
io.sarl.sre.janus
Maven Artifact Identifier:
janus.kernel
Property Summary
Modifier and type Property and description
InternalSchedules executor
Replies the agent's task scheduler that must be used by the event bus.
Constructor Summary
Constructor and description
new(Supplier<T>,IBehaviorGuardEvaluatorRegistry,Provider<T>)
Instantiates a dispatcher.
Action Summary
Modifier and type Action and description
void asyncDispatch(Event,[Logger])
Posts an event to all registered BehaviorGuardEvaluator.
void asyncDispatchTo(Object,Event,[Logger])
Posts an event to the registered BehaviorGuardEvaluator of the given listener only.
protected java.util.Collection<E> evaluateGuards(Event,ConcurrentCollection<T>,Logger)
Evaluate the guard associated to the specified event and returns the list of behaviors methods that must be executed.
protected void executeAsynchronouslyBehaviorMethods(Collection<E>)
Execute every single Behaviors runnable, a dedicated thread will created by the executor local to this class and be used to execute each runnable in parallel.
protected void executeBehaviorMethodsInParalellWithSynchroAtTheEnd(Collection<E>,boolean,Logger)
Execute every single Behaviors runnable, a dedicated thread will created by the executor local to this class and be used to execute each runnable in parallel, and this method waits until its future has been completed before leaving.
InternalSchedules getExecutor
Replies the agent's task scheduler that must be used by the event bus.
ConcurrentCollection<T> getRegisteredEventListeners(Class<T>)
Extract the registered listeners with the given type.
boolean hasRegisteredEventListener(Class<T>)
Replies if a listener with the given type is registered.
void immediateDispatch(Event,boolean,[Logger])
Posts an event to all registered BehaviorGuardEvaluator.
void immediateDispatchTo(Object,Event,boolean,[Logger])
Posts an event to the registered BehaviorGuardEvaluator of the given listener only.
void register(Object,Function1<Param,Result>,Procedure1<Param>)
Registers all PerceptGuardEvaluator methods on object to receive events.
void unregister(Class<T>,Function1<Param,Result>)
Unregisters all PerceptGuardEvaluator methods on the objects of the given type.
void unregister(Object,Procedure1<Param>)
Unregisters all PerceptGuardEvaluator methods on a registered object.
void unregisterAll(Function1<Param,Result>)
Unregisters all PerceptGuardEvaluator methods on all registered objects.
Property Details
executor
val executor : InternalSchedules
Replies the agent's task scheduler that must be used by the event bus.

This property is an alias for the action: getExecutor

Returns:
the executor.
Since:
0.11
Constructor Details
new(Supplier<T>,IBehaviorGuardEvaluatorRegistry,Provider<T>)
new(Supplier<T>,IBehaviorGuardEvaluatorRegistry,Provider<T>)
Instantiates a dispatcher.
Parameters:
taskSchedulerProvider - a provider of scheduler for the agent tasks that may be invoked on demand.
dispatcher - the event dispatcher.
factories - the provider of factories tool.
Action Details
asyncDispatch(Event,[Logger])
def asyncDispatch(Event,[Logger])
Posts an event to all registered BehaviorGuardEvaluator. The dispatch of this event will be done asynchronously. This method will return successfully after the event has been posted to all BehaviorGuardEvaluator, and regardless of any exceptions thrown by BehaviorGuardEvaluator.
Parameters:
event - an event to dispatch asynchronously.
logger - the logger to use for notifying the errors.
asyncDispatchTo(Object,Event,[Logger])
def asyncDispatchTo(Object,Event,[Logger])
Posts an event to the registered BehaviorGuardEvaluator of the given listener only. The dispatch of this event will be done asynchronously. This method will return successfully after the event has been posted to all BehaviorGuardEvaluator, and regardless of any exceptions thrown by BehaviorGuardEvaluator.
Parameters:
listener - the listener to dispatch to.
event - an event to dispatch asynchronously.
logger - the logger to use for notifying the errors.
Since:
0.12
evaluateGuards(Event,ConcurrentCollection<T>,Logger)
protected def evaluateGuards(Event,ConcurrentCollection<T>,Logger) : java.util.Collection<E>
Evaluate the guard associated to the specified event and returns the list of behaviors methods that must be executed.

Errors are logger by the executor service. But they are not stopping the call to this function.
Parameters:
event - the event triggering behaviors.
behaviorGuardEvaluators - the list of class containing a PerceptGuardEvaluator method.
logger - the logger to be used.
Returns:
the collection of couple associating a object and its collection of behavior methods that must be executed.
executeAsynchronouslyBehaviorMethods(Collection<E>)
protected def executeAsynchronouslyBehaviorMethods(Collection<E>)
Execute every single Behaviors runnable, a dedicated thread will created by the executor local to this class and be used to execute each runnable in parallel.

Errors are logged by the executor service. They are not thrown by this function.
Parameters:
behaviorsMethodsToExecute - the collection of Behaviors runnable that must be executed.
executeBehaviorMethodsInParalellWithSynchroAtTheEnd(Collection<E>,boolean,Logger)
protected def executeBehaviorMethodsInParalellWithSynchroAtTheEnd(Collection<E>,boolean,Logger)
Execute every single Behaviors runnable, a dedicated thread will created by the executor local to this class and be used to execute each runnable in parallel, and this method waits until its future has been completed before leaving.

Errors are logged by the executor service, and are thrown by this function.
Parameters:
behaviorsMethodsToExecute - the collection of Behaviors runnable that must be executed.
thrownExceptions - indicates if the exceptions in the event handlers should be thrown from this function, or logged out to the agent's log.
logger - the logger to use for notifying the errors.
getExecutor
def getExecutor : InternalSchedules
Replies the agent's task scheduler that must be used by the event bus.
Returns:
the executor.
Since:
0.11
getRegisteredEventListeners(Class<T>)
def getRegisteredEventListeners(Class<T>) : ConcurrentCollection<T>

with T

Extract the registered listeners with the given type.
Parameters:
<T> - the type of the listeners.
type - the type of the listeners.
Returns:
the collection of listeners that is filled by this function.
Since:
0.6.0
hasRegisteredEventListener(Class<T>)
def hasRegisteredEventListener(Class<T>) : boolean
Replies if a listener with the given type is registered.
Parameters:
type - the type of listener.
Returns:
true if a listener of the given type is registered.
Since:
0.5.0
immediateDispatch(Event,boolean,[Logger])
def immediateDispatch(Event,boolean,[Logger])
Posts an event to all registered BehaviorGuardEvaluator. The dispatch of the events within the agent is asynchronous. A rendez-vous point is set up in order to wait for all the event handlers to be finished. This method will return successfully after the event has been posted to all BehaviorGuardEvaluator, and regardless of any exceptions thrown by BehaviorGuardEvaluator.
Parameters:
event - an event to dispatch synchronously.
thrownExceptions - indicates if the exceptions in the event handlers should be thrown from this function, or logged out to the agent's log.
logger - the logger to use for notifying the errors.
immediateDispatchTo(Object,Event,boolean,[Logger])
def immediateDispatchTo(Object,Event,boolean,[Logger])
Posts an event to the registered BehaviorGuardEvaluator of the given listener only. The dispatch of this event will be done synchronously. This method will return successfully after the event has been posted to all BehaviorGuardEvaluator, and regardless of any exceptions thrown by BehaviorGuardEvaluator.
Parameters:
listener - the listener to dispatch to.
event - an event to dispatch synchronously.
thrownExceptions - indicates if the exceptions in the event handlers should be thrown from this function, or logged out to the agent's log.
logger - the logger to use for notifying the errors.
register(Object,Function1<Param,Result>,Procedure1<Param>)
def register(Object,Function1<Param,Result>,Procedure1<Param>)
Registers all PerceptGuardEvaluator methods on object to receive events.

If the filter is provided, it will be used for determining if the given behavior accepts a specific event. If the filter function replies true for a specific event as argument, the event is fired in the behavior context. If the filter function replies false, the event is not fired in the behavior context.
Parameters:
object - object whose PerceptGuardEvaluator methods should be registered.
filter - the filter function. It could be null.
callback - function which is invoked just after the first registration of the object. It could be null.
unregister(Class<T>,Function1<Param,Result>)
def unregister(Class<T>,Function1<Param,Result>)
Unregisters all PerceptGuardEvaluator methods on the objects of the given type.
Parameters:
type - type of the objects whose PerceptGuardEvaluator methods should be unregistered.
callback - function which is invoked just before the object is unregistered. The callback functions replies true if it should be called on the next removed object. If it replies false, it will be not called anymore.
Since:
0.7
unregister(Object,Procedure1<Param>)
def unregister(Object,Procedure1<Param>)
Unregisters all PerceptGuardEvaluator methods on a registered object.
Parameters:
object - object whose PerceptGuardEvaluator methods should be unregistered.
callback - function which is invoked just before the object is unregistered.
unregisterAll(Function1<Param,Result>)
def unregisterAll(Function1<Param,Result>)
Unregisters all PerceptGuardEvaluator methods on all registered objects.
Parameters:
callback - function which is invoked just before the object is unregistered. The callback functions replies true if it should be called on the next removed object. If it replies false, it will be not called anymore.