Class Probe
java.lang.Object
madkit.kernel.Probe
- Direct Known Subclasses:
PropertyProbe
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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
Makes all the agents leave the corresponding role at once.static Field
findFieldOn
(Class<?> agentClass, String fieldName) Returns the agent's field namedfieldName
.Returns a snapshot at moment t of the agents handling the group/role coupleGets the community to which this activator/probe is binded to.getGroup()
Gets the group to which this activator/probe is binded to.getName()
Gets the name.getRole()
Gets the role to which this activator/probe is binded to.boolean
isEmpty()
Checks if there is no agent in the group/role couplevoid
Kills all the agents which are monitored.protected void
Automatically called when an agent joins the corresponding group and role.protected void
onRemoving
(Agent agent) Automatically called when an agent leaves the corresponding group and role.int
size()
Returns the number of targeted agents.toString()
returns a string containing the CGR location and the number of monitored agents.
-
Constructor Details
-
Probe
Builds a new Probe on the given CGR location of the artificial society. Once created, it has to be added by aWatcher
agent using theWatcher.addProbe(Probe)
method.- Parameters:
communityName
- the community namegroupName
- the group nameroleName
- the role name
-
Probe
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 aWatcher
agent using theWatcher.addProbe(Probe)
method.- Parameters:
groupName
- the group nameroleName
- the role name
-
-
Method Details
-
findFieldOn
Returns the agent's field namedfieldName
. This also works onprivate
fields, even inherited ones.- Parameters:
agentClass
- the targeted agent's classfieldName
- the name of the field- Returns:
- the agent's field named
fieldName
- Throws:
NoSuchFieldException
- if the field was not found
-
getCommunity
Gets the community to which this activator/probe is binded to.- Returns:
- a string representing the community's name
-
getGroup
Gets the group to which this activator/probe is binded to.- Returns:
- a string representing the group's name
-
getRole
Gets the role to which this activator/probe is binded to.- Returns:
- a string representing the role's name
-
onAdding
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
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
-
toString
-
getName
-
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.
-