/*
 * P2Psum.java
 *
 * Created on May 2, 2005, 7:20 PM
 */

package DDMT.Nodes;

import java.util.Vector;
import java.io.*;
import jade.lang.acl.*;
import java.util.regex.*;
import DDMT.Agents.NodeAgent.AgentInterface;//not initial

/**
 *
 * @author  jk3
 */
public class L2Monitoring extends NodeCode
{
    
    //Define patterns for integers, strings, doubles, first string, and last string
    private Pattern integerP = Pattern.compile("\\d+");
    private Pattern doubleP = Pattern.compile("\\d+\\p{Punct}\\d+");
    private Pattern stringP = Pattern.compile("\\S+\\s");
    private Pattern alphaStringP = Pattern.compile("[a-zA-Z]\\S*");
    private Pattern neighborP = Pattern.compile("\\s\\d+\\s\\d+\\p{Punct}\\d+");
    private Pattern fileP = Pattern.compile("\\S+\\s\\S+");
    private Pattern firstP = Pattern.compile("\\A\\S+");
    private Pattern lastP = Pattern.compile("\\S+\\Z");
    private Pattern middleP = Pattern.compile("\\s\\S+\\s");
    private Pattern relationP = Pattern.compile("\\A@[Rr][Ee][Ll][Aa][Tt][Ii][Oo][Nn]");
    private Pattern attributeTypeP = Pattern.compile("\\A@[Aa][Tt][Tt][Rr][Ii][Bb][Uu][Tt][Ee]\\s+\\S+\\s+\\S+");
    private Pattern attributeP = Pattern.compile("\\[S^,]*");
    private Pattern heteroDistP = Pattern.compile("\\s(\\S+)");
    private Matcher heteroDistM;
    private Matcher attributeM;
    private Matcher attributeTypeM;
    private Matcher relationM;
    private Matcher fileM;
    private Matcher firstM;
    private Matcher lastM;
    private Matcher middleM;
    private Matcher integerM;
    private Matcher doubleM;
    private Matcher stringM;
    private Matcher alphaStringM;
    private Matcher neighborM;
    
    public L2Monitoring()
    {
    }
    
    public void start()
    {
        if( this.getNumber() == 40)
        {
            Vector nbors = this.getNeighbors();
            for( int i= 0; i<nbors.size(); i++)
            {
                iface.sendMessage("send", ((Neighbor)nbors.elementAt(i)).getNumber());
                iface.printMessage("sending to "+((Neighbor)nbors.elementAt(i)).getNumber());
                
            }
        }
    }
    
    
    public void run(String m, int num)
    {
        
        //iface.printMessage("got message "+m);
        if( m.equals("send"))
        {
            System.out.println("msg received from "+num+" by :"+this.getNumber());
        }
    }
}
