Exemplo n.º 1
0
 private static void waitABit(long timeout) {
   try {
     Thread.sleep(timeout);
   } catch (Exception e) {
   }
 }
Exemplo n.º 2
0
  public static void main(String[] args) {
    ExtendedProperties pp = parseArguments(args);
    Properties jadeProps = pp.extractSubset("jade.");
    System.out.println("JADE PROPERTIES: " + jadeProps);

    int contentSize = DEFAULT_CONTENT_SIZE;
    try {
      contentSize = Integer.parseInt(pp.getProperty(CONTENT_SIZE));
    } catch (Exception e) {
      // Keep default
    }
    content = new byte[contentSize];

    timeInterval = DEFAULT_TIME_INTERVAL;
    try {
      timeInterval = Long.parseLong(pp.getProperty(TIME_INTERVAL));
    } catch (Exception e) {
      // Keep default
    }

    nIterations = DEFAULT_N_ITERATIONS;
    try {
      nIterations = Integer.parseInt(pp.getProperty(N_ITERATIONS));
    } catch (Exception e) {
      // Keep default
    }

    nCouples = DEFAULT_N_COUPLES;
    try {
      nCouples = Integer.parseInt(pp.getProperty(N_COUPLES));
    } catch (Exception e) {
      // Keep default
    }

    base = DEFAULT_BASE;
    try {
      base = Integer.parseInt(pp.getProperty(BASE));
    } catch (Exception e) {
      // Keep default
    }

    mode = READY_GO_MODE;
    try {
      String modeStr = pp.getProperty(MODE);
      if (SLOW_MODE_S.equals(modeStr)) {
        mode = SLOW_MODE;
      } else if (FAST_MODE_S.equals(modeStr)) {
        mode = FAST_MODE;
      } else if (STEP_BY_STEP_MODE_S.equals(modeStr)) {
        mode = STEP_BY_STEP_MODE;
      }
    } catch (Exception e) {
      // Keep default
    }
    // Prepare the inputReader to get user inputs if necessary
    if (mode == READY_GO_MODE || mode == STEP_BY_STEP_MODE) {
      inputReader = new BufferedReader(new InputStreamReader(System.in));
    }

    randomStart = "true".equals(pp.getProperty(RANDOM_START_S, "false"));

    measure = BITRATE_MEASURE;
    try {
      String measureStr = pp.getProperty(MEASURE);
      if (RTT_MEASURE_S.equals(measureStr)) {
        measure = RTT_MEASURE;
      }
    } catch (Exception e) {
      // Keep default
    }

    String prefix = Profile.getDefaultNetworkName();
    for (int i = base; i < base + nCouples; i++) {
      initCouple(jadeProps, prefix, i);
      switch (mode) {
        case SLOW_MODE:
          waitABit();
          break;
        case STEP_BY_STEP_MODE:
          prompt("Couple #" + i + " started. Press enter to continue");
          break;
        default:
          Thread.currentThread().yield();
      }
    }

    waitUntilReady();
    if (mode == READY_GO_MODE) {
      prompt("All " + nCouples + " couples ready. Press enter to go");
    }
    start();
    if (nIterations > 0) {
      System.out.println("Measurement started....");
    }

    if (timeInterval == STEPBYSTEP_TIME_INTERVAL) {
      int i = 0;
      while (true) {
        waitUntilReady();
        prompt("Iteration # " + i + " terminated by all couples. Press enter to go");
        ++i;
        start();
      }
    }
  }
Exemplo n.º 3
0
  protected void setup() {
    // Printout a welcome message
    System.out.println("Hello World. I'm an agent!");
    System.out.println("My local-name is " + getAID().getLocalName());
    System.out.println("My GUID is " + getAID().getName());
    System.out.println("My addresses are:");
    Iterator it = getAID().getAllAddresses();

    // Parse param
    // This agent will receive 3 params: destinationAgentName, FileText to Send, delay_SleepTime
    Object[] args = getArguments();

    if (args != null) {
      try {
        int iNumparams = args.length;
        for (int i = 0; i < iNumparams; i++) {
          System.out.println("Agrs[" + i + "]: " + args[i].toString());
        }
        Thread.sleep(6000);
      } catch (InterruptedException ex) {
        Logger.getLogger(GPSsimulatorAgent.class.getName()).log(Level.SEVERE, null, ex);
      }
    }

    Behaviour b =
        new CyclicBehaviour(this) {
          public void action() {
            System.out.println("Action!");
            try {
              ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
              // AID dest = new AID(destAgentName, AID.ISLOCALNAME);
              String destAgentNameGlobalID = "gps@cs-at6nguyen:1099/JADE";

              // AID aid = new AID("da0", AID.ISLOCALNAME)
              // AID aid = new AID("[email protected]:1099/JADE", AID.ISGUID).

              // AID dest = new AID("[email protected]:1099/JADE", AID.ISGUID); // not work!
              // AID dest = new AID("[email protected]:1099/JADE", AID.ISGUID); //
              // not work!
              // AID dest = new AID("gps@localhost:1099/JADE", AID.ISGUID); // not work!
              AID dest = new AID("gps@cs-at6nguyen:1099/JADE", AID.ISGUID); // WORKS !!!

              msg.addReceiver(dest);

              Date d = new Date();

              String strtemp = "";
              for (int i = 0; i < 100; i++) {
                strtemp = strToSend + "," + d.getTime() + "," + d.toString();
                msg.setContent(strtemp);
                System.out.println("Sending: " + strtemp);
                send(msg);
                Thread.sleep(iDelayTime);
              }

            } catch (InterruptedException ex) {
              Logger.getLogger(GPSsimulatorAgent.class.getName()).log(Level.SEVERE, null, ex);
            }
          }
        }; // End Behaviour b
    addBehaviour(tbf.wrap(b));
  }