Class Probe

java.lang.Object
madkit.kernel.Probe
Direct Known Subclasses:
PropertyProbe

public class Probe extends Object
This class defines a watcher's generic probe. A probe is configured according to a community, a group and a role. It is used to monitor agents that play specific roles in specific groups. Once added to a Watcher agent, it can use the #findFieldOn(Class, String) method to access the fields of the underlying agents.
Since:
MaDKit 2.0
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Probe(String groupName, String roleName)
    Builds a new Probe on the given CGR location, without specifying the community.
    Probe(String communityName, String groupName, String roleName)
    Builds a new Probe on the given CGR location of the artificial society.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Makes all the agents leave the corresponding role at once.
    static Field
    findFieldOn(Class<?> agentClass, String fieldName)
    Returns the agent's field named fieldName.
    <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.
    Gets the role to which this activator/probe is binded to.
    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.
    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

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

    • 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 - the community name
      groupName - the group name
      roleName - the role name
    • Probe

      public Probe(String groupName, String roleName)
      Builds a new Probe on the given CGR location, 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 Watcher agent using the Watcher.addProbe(Probe) method.
      Parameters:
      groupName - the group name
      roleName - the role name
  • Method Details

    • findFieldOn

      public static Field findFieldOn(Class<?> 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's class
      fieldName - the name of the field
      Returns:
      the agent's field named fieldName
      Throws:
      NoSuchFieldException - if the field was not found
    • 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
    • toString

      public String toString()
      returns a string containing the CGR location and the number of monitored agents.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this tool.
    • 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.