Class MethodActivator

java.lang.Object
madkit.kernel.Activator
madkit.simulation.scheduler.MethodActivator
All Implemented Interfaces:
Comparable<Activator>
Direct Known Subclasses:
DateBasedDiscreteEventActivator

public class MethodActivator extends Activator
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 Details

    • MethodActivator

      public MethodActivator(String group, String role, String methodName, Class<?>... argTypes)
      Builds a new GenericBehaviorActivator on the given CGR location of the artificial society. Once created, it has to be added by a Scheduler agent using the Scheduler.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 extend Agent.
      Parameters:
      group - the group of the agents
      role - the role of the agents
      methodName - the name of the Java method which will be invoked
      argTypes - the class types of the method arguments
  • Method Details

    • execute

      public void execute(Object... args)
      Executes the behavior on the agents.

      If the

      Specified by:
      execute in class Activator
      Parameters:
      args - the arguments to pass to the behavior
      See Also:
    • execute

      public void execute(List<? extends Agent> agents, Object... args)
      Executes the behavior on the given list of agents.
      Parameters:
      agents - the list of agents
      args - the arguments to pass to the behavior
    • executeInParallel

      public void executeInParallel(List<? extends Agent> agents, Object... args)
      Executes the behavior on the given list of agents in parallel.
      Parameters:
      agents - the list of agents
      args - the arguments to pass to the behavior
    • toString

      public String toString()
      returns a string containing the CGR location and the number of monitored agents.
      Overrides:
      toString in class Activator
      Returns:
      a string representation of this tool.
    • getMethod

      public String 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

      public String getCommunity()
      Gets the community to which this activator/probe is binded to.
      Returns:
      a string representing the community's name
    • getGroup

      public String getGroup()
      Gets the group to which this activator/probe is binded to.
      Returns:
      a string representing the group's name
    • getRole

      public String getRole()
      Gets the role to which this activator/probe is binded to.
      Returns:
      a string representing the role's name
    • onAdding

      protected void onAdding(Agent agent)
      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

      protected void onRemoving(Agent agent)
      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

      public <A extends Agent> List<A> getAgents()
      Returns a snapshot at moment t of the agents handling the group/role couple
      Returns:
      a list view (a snapshot at moment t) of the agents that handle the group/role couple (in proper sequence)
      Since:
      MaDKit 3.0
    • getName

      public String getName()
      Gets the name.
      Returns:
      the name
    • 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.