Description

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 law

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).
It is published at:
http://www.moses.rutgers.edu/examples/monitoring/Monitoring.law
and it can be provided to the controller via this URL.

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 is published at:
http://www.moses.rutgers.edu/examples/monitoring/Monitoring.java1

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.

Running the example

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:

  • giving a running controller on host hostname, download the law and change the monitor address line to the new value monitor@hostname;
  • publish the modified law on your own law server;
  • using the human interface, create the monitor with the name monitor and with the modified law; observe that the monitor receives its own notification when created;
  • create another agent with any name; observe that the monitor receives the modification upon creation;
  • from this agent, send a message with the destination itself; observe that the message is transfered to the monitor as well;
  • if needed, create other agents and exchange messages between them.