madkit.kernel

## Class Probe<A extends AbstractAgent>

- java.lang.Object
- - madkit.kernel.Probe<A>

- Direct Known Subclasses:
    PropertyProbe, SingleAgentProbe

      public class Probe<A extends AbstractAgent>
      extends Object

  This class defines a watcher's generic probe. A probe is configured according to a community, a group and a role.
  Since:
    MaDKit 2.0
  Version:
    5.0
  Author:
    Fabien Michel, Olivier Gutknecht
  See Also:
    `Watcher`, `PropertyProbe`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Probe(String communityName, String groupName, String roleName)` Builds a new Probe<> on the given CGR location of the artificial society.

  - ### Method Summary

    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()`
    `static Field` | `findFieldOn(Class<? extends AbstractAgent> agentClass, String fieldName)` Returns the agent's field named `fieldName`.
    `String` | `getCommunity()`
    `List<A>` | `getCurrentAgentsList()` Returns a snapshot at moment t of the agents handling the group/role couple
    `String` | `getGroup()`
    `String` | `getRole()`
    `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()`
    `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
    `String` | `toString()`

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

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

- - ### Constructor Detail

    - #### Probe

          public Probe(String communityName,
               String groupName,
               String roleName)

      Builds a new Probe<> on the given CGR location of the artificial society. Once created, it has to be added by a `Watcher` agent using the `Watcher.addProbe(Probe)` method.
      Parameters:
        `communityName` -
        `groupName` -
        `roleName` -
      See Also:
        `Watcher`

  - ### Method Detail

    - #### findFieldOn

          public static Field findFieldOn(Class<? extends AbstractAgent> agentClass,
                          String fieldName)
                                   throws NoSuchFieldException

      Returns the agent's field named `fieldName`. This also works on `private` fields, even inherited ones.
      Parameters:
        `agentClass` - the targeted agent
        `fieldName` - the name of the field
      Returns:
        the agent's field named `fieldName`
      Throws:
        `NoSuchFieldException`

    - #### getCommunity

          public String getCommunity()

    - #### getGroup

          public String getGroup()

    - #### getRole

          public String getRole()

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

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### killAgents

          public void killAgents()

    - #### allAgentsLeaveRole

          public void allAgentsLeaveRole()

Fabien Michel, Olivier Gutknecht, Jacques Ferber