madkit.kernel

## Class Watcher

- java.lang.Object
- - madkit.kernel.AbstractAgent
  - - madkit.kernel.Watcher

- All Implemented Interfaces:
    Comparable<AbstractAgent>
  Direct Known Subclasses:
    SwingViewer

      public class Watcher
      extends AbstractAgent

  This class defines a generic watcher agent. It holds a collection of probes to explore agents' internal properties.
  Since:
    MaDKit 2.0
  Version:
    5.0
  Author:
    Fabien Michel, Olivier Gutknecht

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class madkit.kernel.AbstractAgent

      `AbstractAgent.ReturnCode, AbstractAgent.State`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Watcher()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `activate()` This method corresponds to the first behavior which is called by the MaDKit kernel when an agent is launched.
    `void` | `addProbe(Probe<? extends AbstractAgent> probe)` Adds the probe to the artificial organization so that it starts to probe the agents which are at the corresponding CGR location.
    `Probe<AbstractAgent>[]` | `allProbes()`
    `Set<Probe<? extends AbstractAgent>>` | `getProbes()` Returns the probes which have been successfully added
    `void` | `removeAllProbes()` Remove all probes at once.
    `void` | `removeProbe(Probe<? extends AbstractAgent> probe)` Removes the probe from the artificial organization, thus stopping the probing activity.
    `String` | `toString()`

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

      `broadcastMessage, broadcastMessageWithRole, bucketModeCreateGroup, bucketModeRequestRole, checkAgentAddress, compareTo, createGroup, createGroup, createGroup, createGroupIfAbsent, createGroupIfAbsent, createGroupIfAbsent, createGUIOnStartUp, destroyCommunity, destroyGroup, destroyRole, end, executeThisAgent, executeThisAgent, executeThisAgent, getAgentAddressIn, getAgentsWithRole, getAgentsWithRole, getAgentWithRole, getDistantAgentWithRole, getExistingCommunities, getExistingGroups, getExistingRoles, getKernelAddress, getLastReceivedMessage, getLastReceivedMessage, getLogger, getMadkitConfig, getMadkitProperty, getMadkitProperty, getMyGroups, getMyRoles, getName, getNetworkID, getNextEventDate, getOrganizationSnapShot, getReplyTo, getServerInfo, getSimpleNetworkID, getSimulationTime, getState, hasGUI, hashCode, hasRole, isAlive, isCommunity, isGroup, isKernelOnline, isMadkitPropertyTrue, isMessageBoxEmpty, isRole, killAgent, killAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgentBucket, launchAgentBucket, launchAgentBucket, launchAgentBucket, launchNode, launchXmlAgents, leaveGroup, leaveRole, nextMessage, nextMessage, nextMessages, proceedEnumMessage, purgeMailbox, receiveMessage, reload, requestRole, requestRole, sendMessage, sendMessage, sendMessageWithRole, sendMessageWithRole, sendReply, sendReplyWithRole, setLogLevel, setMadkitProperty, setMadkitProperty, setName, setupFrame`

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

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

- - ### Constructor Detail

    - #### Watcher

          public Watcher()

  - ### Method Detail

    - #### addProbe

          public void addProbe(Probe<? extends AbstractAgent> probe)

      Adds the probe to the artificial organization so that it starts to probe the agents which are at the corresponding CGR location.
      Parameters:
        `probe` - the probe to add

    - #### removeProbe

          public void removeProbe(Probe<? extends AbstractAgent> probe)

      Removes the probe from the artificial organization, thus stopping the probing activity.
      Parameters:
        `probe` - the probe to remove

    - #### activate

          protected void activate()

      Description copied from class: `AbstractAgent`
      This method corresponds to the first behavior which is called by the MaDKit kernel when an agent is launched. Usually a good place to take a position in the organization of the artificial society.

      Here is a typical example:

           @Override
           protected void activate()
           {
                  AbstractAgent.ReturnCode returnCode = requestRole("a community", "a group", "my role");
                  if (returnCode == AbstractAgent.ReturnCode.SUCCESS){
                          if(logger != null)
                                  logger.info("I am now playing my role in the artificial society");
                  }
                  else{
                          if(logger != null)
                                  logger.warning("something wrong, return code is "+returnCode);
                  }
           }

      Overrides:
        `activate` in class `AbstractAgent`

    - #### removeAllProbes

          public void removeAllProbes()

      Remove all probes at once.

    - #### allProbes

          public Probe<AbstractAgent>[] allProbes()

    - #### getProbes

          public Set<Probe<? extends AbstractAgent>> getProbes()

      Returns the probes which have been successfully added
      Returns:
        all the added probes

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `AbstractAgent`
      Returns:
        a `String` giving the name and the current state of the agent

Fabien Michel, Olivier Gutknecht, Jacques Ferber - February 17 2020