/*
 * MasterNode.java
 *
 * Created on February 14, 2005, 4:34 PM
 */

package DDMT.Nodes;

import java.util.Vector;
import jade.lang.acl.*;
import DDMT.Agents.NodeAgent.AgentInterface;
import DDMT.Nodes.Node;

/**
 *
 * @author  jk3
 */
public class MasterNode extends NodeCode{

    //Node information
    Node thisNode;
    
    //State of the node
    int state;
    
    //total recieved so far
    int total;
    
    //Recieved
    int recieved;
    
    //Current time
    long time;
    
    //sync boolean
    public boolean isRunning = false;
    
    /** Creates a new instance of MasterNode */
    public MasterNode() {
        total = 0;
        recieved = 0;
    }
    
    public void run(String message, int nodeNumber)
    {
        //add the message
        total += Integer.parseInt(message);
        recieved++;
        //System.out.println("Got message from "+nodeNumber);
        //System.out.println("Message "+recieved+" recieved1: "+message+", current sum = "+total);
        if( recieved >= 99 )
        {
            iface.printMessage("Total is "+total);
            //iface.done();
            iface.printMessage("Time is: "+ (System.currentTimeMillis() - time));
        }
    }
    
    public void start()
    {
        System.out.println("Here");
        //Store the start time
        time = System.currentTimeMillis();
    }    
    
}
