Class MethodActivator
java.lang.Object
madkit.kernel.Activator
madkit.simulation.scheduler.MethodActivator
- All Implemented Interfaces:
Comparable<Activator>
- Direct Known Subclasses:
DateBasedDiscreteEventActivator
An activator that invokes a single method on a group of agents. This class encapsulates
behavior invocation on MaDKit agents for scheduler agents. It allows to call a
particular Java method on agents regardless of their actual class type as long as they
extend
Agent
. This has to be used by Scheduler
subclasses to create
simulation applications.- Since:
- MaDKit 5.0.0.1
-
Constructor Summary
ConstructorsConstructorDescriptionMethodActivator
(String group, String role, String methodName, Class<?>... argTypes) Builds a new GenericBehaviorActivator on the given CGR location of the artificial society. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Makes all the agents leave the corresponding role at once.void
Executes the behavior on the agents.void
Executes the behavior on the given list of agents.void
executeInParallel
(List<? extends Agent> agents, Object... args) Executes the behavior on the given list of agents in parallel.Returns a snapshot at moment t of the agents handling the group/role coupleGets the community to which this activator/probe is binded to.getGroup()
Gets the group to which this activator/probe is binded to.Returns the name of the method to be invoked on the agents.getName()
Gets the name.getRole()
Gets the role to which this activator/probe is binded to.boolean
isEmpty()
Checks if there is no agent in the group/role coupleboolean
Returns whether the activator is in parallel mode.boolean
Returns whether the activation list should be shuffled before execution.void
Kills all the agents which are monitored.protected void
Automatically called when an agent joins the corresponding group and role.protected void
onRemoving
(Agent agent) Automatically called when an agent leaves the corresponding group and role.void
setParallelMode
(boolean parallelMode) Sets the activator in parallel mode.void
setShufflingMode
(boolean shufflingMode) Sets whether the activation list should be shuffled before execution.int
size()
Returns the number of targeted agents.toString()
returns a string containing the CGR location and the number of monitored agents.Methods inherited from class madkit.kernel.Activator
compareTo, executeBehaviorOf, getPriority, getScheduler, getSimuTimer, setPriority
-
Constructor Details
-
MethodActivator
Builds a new GenericBehaviorActivator on the given CGR location of the artificial society. Once created, it has to be added by aScheduler
agent using theScheduler.addActivator(Activator)
method. Once added, it could be used to trigger the behavior on all the agents which are at this CGR location, regardless of their class type as long as they extendAgent
.- Parameters:
group
- the group of the agentsrole
- the role of the agentsmethodName
- the name of the Java method which will be invokedargTypes
- the class types of the method arguments
-
-
Method Details
-
execute
-
execute
-
executeInParallel
-
toString
-
getMethod
Returns the name of the method to be invoked on the agents.- Returns:
- the method name
-
isShufflingMode
public boolean isShufflingMode()Returns whether the activation list should be shuffled before execution.- Returns:
- true if the activation list should be shuffled, false otherwise
-
setShufflingMode
public void setShufflingMode(boolean shufflingMode) Sets whether the activation list should be shuffled before execution. The shuffling mode is done using the PRNG defined by the Model agent. If the parallel mode is enabled, the shuffling mode has no effect.- Parameters:
shufflingMode
- true if the activation list should be shuffled, false otherwise
-
isParallelMode
public boolean isParallelMode()Returns whether the activator is in parallel mode.- Returns:
true
if the activator is in parallel mode,false
otherwise
-
setParallelMode
public void setParallelMode(boolean parallelMode) Sets the activator in parallel mode.- Parameters:
parallelMode
- the parallelMode to set
-
getCommunity
Gets the community to which this activator/probe is binded to.- Returns:
- a string representing the community's name
-
getGroup
Gets the group to which this activator/probe is binded to.- Returns:
- a string representing the group's name
-
getRole
Gets the role to which this activator/probe is binded to.- Returns:
- a string representing the role's name
-
onAdding
Automatically called when an agent joins the corresponding group and role. Override this method when you want to do some initialization when an agent enters the group/role.- Parameters:
agent
- which has been added to this group/role
-
onRemoving
Automatically called when an agent leaves the corresponding group and role. Override this method when you want to do some work when an agent leaves the group/role. Note that the role is still handled by the agent when invoked.- Parameters:
agent
- the agent which is being removed from this group/role
-
size
public int size()Returns the number of targeted agents.- Returns:
- the number of targeted agents
-
isEmpty
public boolean isEmpty()Checks if there is no agent in the group/role couple- Returns:
- true, if no agent is handling the group/role couple
-
getAgents
-
getName
-
killAgents
public void killAgents()Kills all the agents which are monitored. -
allAgentsLeaveRole
public void allAgentsLeaveRole()Makes all the agents leave the corresponding role at once.
-