/*
 * NodeCode.java
 *
 * Created on February 14, 2005, 4:45 PM
 */

package DDMT.Nodes;

import jade.lang.acl.*;
import jade.core.Agent;
import DDMT.Agents.NodeAgent.AgentInterface;
import DDMT.Nodes.Node;
/**
 *
 * @author  jk3
 */
public class NodeCode extends Node implements Runnable{
    
    //Interface with the main agent
    public AgentInterface iface;
    
    private Agent agent;
    
    /**
     *Method called to set up the process/callback for this message.
     */
    public void processMessage(String message, int num)
    {
        //save the message
    //    iface.setMessage(message);
        
        //System.out.println(message.getReplyWith());
        
        //Run the process, passing the sending node as a parameter
        this.run( message, num );
        
        //Send the reply
//        ACLMessage reply = message.createReply();
//        reply.setConversationId("postoffice");
//        reply.setPerformative(reply.CONFIRM);
//        reply.setReplyWith( message.getReplyWith());
//        reply.setLanguage(message.getLanguage());
//        reply.setEncoding(message.getEncoding());
//        iface.sendMessage(reply);
        //System.out.println("sent callback");
    }
    
    /**
     *This method is called when the node recieves a message.
     *It will store the values that are needed for the user, then
     *call the run() method.
     */
    public void run(String message, int nodeNumber)
    {
        this.run(message);
    }
    public void run(String message)
    {
        this.run();   
    }
    
    /**
     *This method is executed when the algorithm terminates, 
     *either by user intervention (clicking Cancel) or when the 
     *user's code calls iface.done();
     */
    public void end()
    {
        System.out.println("Killing node "+this.getNumber()+"...");
    }
    
    
    public void run()
    {
        
    }
    
    //Method to be executed when the algorithm has started
    public void start()
    {
        
    }
    
    public void setIface(AgentInterface face)
    {
        iface = face;
    }
 
    public void setAgent( Agent a )
    {
        agent = a;
    }
    
    /**
     *Queued Node class models one node in the threadpool
     */
}
