package examples.jsp;

import jade.core.*;
import jade.core.behaviours.*;
import jade.lang.acl.*;

/**
 * This agent is to be used in a JSP page. It just sends
 * messages to a buffer agent.
 */
public class Snooper extends Agent {
    private ACLMessage msg;

    public Snooper() {
	// Create the message to send to the client
	msg = new ACLMessage(ACLMessage.INFORM);
	// JADE 1.4:
	//msg.addDest("buffer");

    }

    /**
     * The method that will be invoked in the JSP page.
     * @param str the message to send to the client
     */
    public void snoop(String str) {
	// JADE 2.0: 
	// getHap() cannot be moved in the constructor because 
	// it would not work!
	// We need to remove each time the previous entry.
	msg.clearAllReceiver();
	msg.addReceiver(new AID("buffer@"+getHap()));
	msg.setContent(str);
	send(msg);
    }
}