import java.io.*; import java.util.*; import java.lang.*; import java.sql.Time; /**This class is the java-version of the Ping.c from GTW. It's used for testing the sim kernel. * *@author Yin Xiong *@version 1.7 (07/2006) */ public class Ping extends LogicalProcess{ /**class member for keeping track of how many messages have been sent.*/ int count; /**class member for store time increments*/ int[] incs; /** class member for keeping track of which time increment should be used */ int incsCount; /**the application-specified name of the destination to which this LP will send messages to*/ String dest; /**the time increment for messages sent by this LP; the message will be sent at currentTime+timeIncrement*/ int timeIncrement; /**Constructs a new Ping instance.*/ public Ping() { super(); count=0; incsCount=0; timeIncrement=0; } /**Sets application-specific configuration data. * @param cdata String representing configuration data. */ public void appSetConfigData(String cdata) { String[] s=cdata.split(" "); int slength=s.length; //System.out.println("in Ping, string length: " + slength); incs=new int[slength]; for(int i=0;i=0 && count<10){ //send 10 messages in total //count++; count=count+timeIncrement; newcontent=String.valueOf(count); //new: sendSimMessage(Object content, double timestamp, String targetid) sendSimMessage(newcontent, timeIncrement, dest); }//end if count<10 else{ setEndOfSimFlag(); // String dest="1"; //newcontent="-1"; //sendSimMessage(newcontent, tim, dest); }//end if not end of sim message if(newcontent!=null) System.out.println("\nPing: receive " + cont + " send " + newcontent); } /**Terminates LP and displays simulation statistics. It is optionally called at the end of the *simulation. It is the counterpart of "FProc" in GTW. */ public void appFinalizeLP() { System.out.println("LP " + myname + " " + PEid + "-" + LPid + " is finalizing...\n"); //System.out.println("LP " + myname + "-" + LPid + " is finalizing...\n"); } /*****************to be implemented*****************************/ /**Method to get the value of a given application-level monitorable variable. * @since 1.5 * @param name The name of the variable to monitor * @return The value of the variable in question */ public String appGetState(String name) { return "Not yet implemented"; } /**Method to set the value of a given application-level monitorable variable. * @since 1.5 * @param name The name of the variable to steer * @param val The value to assign to the variable * @return Null if the steering was successful, else a String describing the * error that occurred. */ public String appSetState(String name, String val) { return "under programming"; } /** Returns a List of Strings describing all application-specific steerable * parameters of this LP, each in the form "paramName, paramType". * @since 1.5 * @return List listing all application-specific steerable parameters. */ public List appGetSteerable() { return null; } /**Returns a List of Strings describing all application-specific monitorable * parameters of this LP, each in the form "paramName, paramType". * @since 1.5 * @return List listing all application-specific montiorable parameters. */ public List appGetMonitorable() { return null; } }//end Ping