madkit.simulation.activator

## Class GenericBehaviorActivator<A extends AbstractAgent>

- java.lang.Object
- - madkit.kernel.Activator<A>
  - - madkit.simulation.activator.GenericBehaviorActivator<A>

-     public class GenericBehaviorActivator<A extends AbstractAgent>
      extends Activator<A>

  An activator that invokes a single method with no parameters on a group of agents. This class encapsulates behavior invocation on MaDKit agents for scheduler agents. This activator allows to call a particular Java method on agents regardless of their actual class type as long as they extend `AbstractAgent`. This has to be used by `Scheduler` subclasses to create simulation applications.
  Since:
    MaDKit 5.0.0.1
  Version:
    1.0
  Author:
    Fabien Michel

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `GenericBehaviorActivator(String community, String group, String role, String theBehaviorToActivate)` Builds a new GenericBehaviorActivator on the given CGR location of the artificial society.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `adding(A agent)` This method is automatically called when an agent joins the corresponding group and role.
    `protected void` | `adding(List<A> agents)` Called when a list of agents joins the corresponding group and role.
    `void` | `allAgentsLeaveRole()` Makes all the agents leave the corresponding role at once.
    `void` | `execute(List<A> agents, Object... args)` Triggers the corresponding behavior on all the agents which are at the CGR location defined by this activator.
    `String` | `getBehaviorName()`
    `String` | `getCommunity()` Gets the community to which this activator/probe is binded to.
    `List<A>` | `getCurrentAgentsList()` Returns a snapshot at moment t of the agents handling the group/role couple
    `String` | `getGroup()` Gets the group to which this activator/probe is binded to.
    `String` | `getRole()` Gets the role to which this activator/probe is binded to.
    `List<A>` | `getShuffledList()` Returns a ListIterator over the agents which is shuffled
    `void` | `initialize()` Called by the MaDKit kernel when the Activator or Probe is first added.
    `void` | `killAgents()` Kills all the agents which are monitored.
    `protected void` | `removing(A agent)` This method is automatically called when an agent leaves the corresponding group and role.
    `protected void` | `removing(List<A> agents)` This method is automatically called when a list of agents has leaved the corresponding group and role.
    `int` | `size()` Returns the number of the agents handling the group/role couple

    - ### Methods inherited from class madkit.kernel.Activator

      `execute, findMethodOn, getMadkitServiceExecutor, isMulticoreModeOn, multicoreExecute, nbOfParallelTasks, toString, useMulticore`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### GenericBehaviorActivator

          public GenericBehaviorActivator(String community,
                                          String group,
                                          String role,
                                          String theBehaviorToActivate)

      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 `AbstractAgent`
      Parameters:
        `community` -
        `group` -
        `role` -
        `theBehaviorToActivate` - name of the Java method which will be invoked

  - ### Method Detail

    - #### getBehaviorName

          public String getBehaviorName()

    - #### execute

          public void execute(List<A> agents,
                              Object... args)

      Triggers the corresponding behavior on all the agents which are at the CGR location defined by this activator.
      Specified by:
        `execute` in class `Activator<A extends AbstractAgent>`
      See Also:
        `Activator.execute(List, Object...)`

    - #### 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

    - #### initialize

          public void initialize()

      Called by the MaDKit kernel when the Activator or Probe is first added. Default behavior is: `adding(getCurrentAgentsList());`

    - #### adding

          protected void adding(List<A> agents)

      Called when a list of agents joins the corresponding group and role. This method is automatically called by the MaDKit kernel when agents enter a role due to the use of `AbstractAgent.launchAgentBucket(String, int, String...)`. Override this method when you want to do some initialization on the agents that enter the group/role. Default implementation is:

           protected void adding(final List<A> agents) {
                  for (A agent : agents) {
                          adding(agent);
                  }
           }

      Parameters:
        `agents` - the list of agents which have been added to this group/role at once.

    - #### adding

          protected void adding(A agent)

      This method is automatically called when an agent joins the corresponding group and role. This method is empty by default. 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

    - #### removing

          protected void removing(List<A> agents)

      This method is automatically called when a list of agents has leaved the corresponding group and role. This method is empty by default. Override this method when you want to do some initialization on the agents that enter the group/role. Default implementation is:

           protected void removing(final List<A> agents) {
                  for (A agent : agents) {
                          removing(agent);
                  }
           }

      Parameters:
        `agents` - the list of agents which have been removed from this group/role

    - #### removing

          protected void removing(A agent)

      This method is automatically called when an agent leaves the corresponding group and role. This method is empty by default. Override this method when you want to do some work when an agent leaves the group/role.
      Parameters:
        `agent` - which has been removed from this group/role

    - #### size

          public int size()

      Returns the number of the agents handling the group/role couple
      Returns:
        the number of the agents that handle the group/role couple

    - #### getCurrentAgentsList

          public List<A> getCurrentAgentsList()

      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

    - #### getShuffledList

          public List<A> getShuffledList()

      Returns a ListIterator over the agents which is shuffled
      Returns:
        a ListIterator which has been previously shuffled
      Since:
        MaDKit 3.0

    - #### 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.

Fabien Michel, Olivier Gutknecht, Jacques Ferber - September 27 2016