This is a law that permits arbitrary communication, but it also establishes the following monitoring regime: when any new agent is created, a monitoring agent ( operating under the same law) is informed automatically; and whenever a message is sent under this law, a copy of it, along with the address of its target, is reported to the monitor.
The monitor is defined here by its LGI name. Thus, when running this example using your own infrastructure, the law requires to change the name of the monitor accordingly.
This example can be performed using the human interface
The Prolog version of the law follows:
law(monitoring,language(prolog)). alias(monitor, 'monitor@research.rutgers.edu'). adopted(par(A)) :- do(forward(Self,justCreated,#monitor)). sent(X,M,Y) :- do(forward(X,[M,Y],#monitor)), do(forward). arrived(X,M,Y) :- do(deliver). disconnected :- do(quit).
The Monitoring law written in Java has the following rules
law(monitoring,language(java))
public class Monitoring extends Law{
public static final String monitor = "monitor@research.rutgers.edu";
public void adopted(String arg) {
doForward(Self, "justCreated", monitor, ThisLawName);
}
public void sent(String source, String message, String dest) {
String monitorMessage = "message(" + message + "," + dest + ")";
doForward(source, monitorMessage, monitor, ThisLawName);
doForward();
}
public void arrived(String source, String message, String dest) {
doDeliver();
}
public void disconnected() {
doQuit();
}
}
It can be observed that, comparing to the simple law, the
adopted and sent events are augmented such
that a message is sent to the monitor every time the event is triggered.
This example requires the pre-existence of a monitoring
agents. Since the name of the monitor is hard-coded in the law (only
to keep the law simple ), prior to running the example one has to
modify the law in order to reflect the proper monitor.
Perform the following steps:
monitor@hostname;
monitor and with the modified law; observe that
the monitor receives its own notification when created;