package avnmp.java.tutorial.BuildingApplications;


import java.util.*;


public class LoadGenAppBasic extends LoadGenAppBasicBase
{
l    ong numPkts = 0;


     long PacketsPerSecond = 20;


     const Date d = new Date();


    public LoadGenAppBasic()
    {
    }


    private long milliSeconds() {
      return new Date().getTime() - d.getTime();
    }


    // This method converts milliSeconds to Seconds, thus returning the current time the application
    // has been running in seconds.

    private long Seconds()
    {
         long s = milliSeconds() / (long) 1000;

         if(s == 0)
              return 1;
         if(s < 0) {
              System.err.println("Time less than zero.");
              halt();
         }
         return s;
    }


    private double Rate() {
         return (double) numPkts / (double) Seconds();
    }


    public void exec()
    {
           while(Rate() < PacketsPerSecond)
           {

               System.out.println("Packets/Second: "+ Rate());
               LoadPacket lp = new LoadPacket();
               lp.SendForProcessing("AN-5");
               numPkts++;
          }

         try {
           SPThread.currentSPThread().sleep(250);
         } catch (InterruptedException ex)
         {}
     }
}