package avnmp.java.tutorial.BuildingApplications;


// We need the Date class from the java.util package.

import java.util.*;


public class LoadGenAppBasic extends LoadBase
{
    long numPkts = 0;


     long PacketsPerSecond = 20;


     Date d = new Date();


    public LoadGenAppBasic()
    {
    }


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


    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)
         {}
     }
}