Class Activator

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

public abstract class Activator extends Object implements Comparable<Activator>
This class defines a tool for scheduling mechanism. An activator is configured according to a community, a group and a role.

Subclasses should override execute(Object...) for defining how a sequential execution of a list of agents take place. By default, this list corresponds to all the agents having the group and role defined in the activator.

Since:
MaDKit 2.0
See Also:
  • Constructor Summary Link icon

    Constructors
    Modifier
    Constructor
    Description
    protected
    Activator(String group, String role)
    Builds a new Activator on the given CGR location of the artificial society, without specifying the community.
    protected
    Activator(String community, String group, String role)
    Builds a new Activator on the given CGR location of the artificial society.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    void
    Makes all the agents leave the corresponding role at once.
    int
    Implementing the Comparable interface for sorting activators according to their priority.
    abstract void
    execute(Object... args)
    Trigger the execution of this activator.
    static void
    executeBehaviorOf(Agent agent, String behaviorName, Object... args)
    Executes a specific method on a targeted agent.
    <A extends Agent>
    List<A>
    Returns a snapshot at moment t of the agents handling the group/role couple
    Gets the community to which this activator/probe is binded to.
    Gets the group to which this activator/probe is binded to.
    Gets the name.
    int
    The priority of this activator when conflicting with another Activator.
    Gets the role to which this activator/probe is binded to.
    <S extends Scheduler<?>>
    S
    Gets the scheduler that manages this activator.
    Get the SimuTimer associated with the simulation
    boolean
    Checks if there is no agent in the group/role couple
    void
    Kills all the agents which are monitored.
    protected void
    onAdding(Agent agent)
    Automatically called when an agent joins the corresponding group and role.
    protected void
    Automatically called when an agent leaves the corresponding group and role.
    void
    setPriority(int priority)
    Sets the priority of the activator.
    int
    Returns the number of targeted agents.
    returns a string containing the CGR location and the number of monitored agents.

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details Link icon

    • Activator Link icon

      protected Activator(String community, String group, String role)
      Builds a new Activator 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).
      Parameters:
      community - the name of the community where the Activator will operate
      group - the name of the group within the community
      role - the role assigned to the Activator within the group
    • Activator Link icon

      protected Activator(String group, String role)
      Builds a new Activator on the given CGR location of the artificial society, without specifying the community. This constructor is used to simplify declaration when used with the default implementation of a simulation engine provided in the madkit.simulation package. Once created, it has to be added by a Scheduler agent using the Scheduler.addActivator(Activator).
      Parameters:
      group - the name of the group within the community
      role - the role assigned to the Activator within the group
  • Method Details Link icon

    • compareTo Link icon

      public int compareTo(Activator o)
      Implementing the Comparable interface for sorting activators according to their priority.
      Specified by:
      compareTo in interface Comparable<Activator>
    • getPriority Link icon

      public int getPriority()
      The priority of this activator when conflicting with another Activator. A lesser priority means that the activator will be triggered first. Default priority is 0. By default, when two activators have the same priority, the order of activation is not guaranteed.
      Returns:
      the priority of this activator.
    • getScheduler Link icon

      public <S extends Scheduler<?>> S getScheduler()
      Gets the scheduler that manages this activator.
      Returns:
      the scheduler that manages this activator.
    • setPriority Link icon

      public void setPriority(int priority)
      Sets the priority of the activator. see getPriority()
      Parameters:
      priority - an int defining the activator's priority
    • execute Link icon

      public abstract void execute(Object... args)
      Trigger the execution of this activator. For instance, subclasses can use the getAgents() to make all the agents do something. This method should be called by the scheduler.
      Parameters:
      args - arguments that could be passed by the scheduler
      See Also:
    • executeBehaviorOf Link icon

      public static void executeBehaviorOf(Agent agent, String behaviorName, Object... args)
      Executes a specific method on a targeted agent.
      Parameters:
      agent - the targeted agent.
      behaviorName - the name of a method belonging to the agents (even private or inherited ones)
      args - parameters to be passed for the invocation
    • toString Link icon

      public String toString()
      returns a string containing the CGR location and the number of monitored agents.
      Returns:
      a string representation of this tool.
    • getSimuTimer Link icon

      public SimuTimer<?> getSimuTimer()
      Get the SimuTimer associated with the simulation
      Returns:
      the simulationTime associated with the simulation
    • getCommunity Link icon

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

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

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

      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 Link icon

      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 Link icon

      public int size()
      Returns the number of targeted agents.
      Returns:
      the number of targeted agents
    • isEmpty Link icon

      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 Link icon

      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 Link icon

      public String getName()
      Gets the name.
      Returns:
      the name
    • killAgents Link icon

      public void killAgents()
      Kills all the agents which are monitored.
    • allAgentsLeaveRole Link icon

      public void allAgentsLeaveRole()
      Makes all the agents leave the corresponding role at once.