コード例 #1
0
  private void executeSecondLife() {
    VirtualEntity entity;
    VirtualEntityShell shell;
    VirtualWorldDistributionShell firstStep;
    Iterator it;
    SolipsisProtocol solipsis;
    int i, toPercentCoef, percent, userNb;
    VirtualWorldDistribution vwd;

    Globals.mapSize = 25600;
    try {
      Globals.slTrace = new SecondLifeTraceDistribution("data/SecondLifeRecord2.txt");
      this.trace = Globals.slTrace;
    } catch (IOException e) {
      System.err.println("File error");
      System.exit(1);
    }

    vwd = new VirtualWorldDistribution();
    Globals.distribution = vwd;
    if (this.trace.getTrace().isEmpty()) {
      System.err.println("The file is corrupted");
      System.exit(1);
    }
    System.err.println("Joining nodes...");
    userNb = this.trace.getTrace().get(0).countAvatars();
    percent = 0;
    firstStep = this.trace.getTrace().get(0);
    it = firstStep.getDistribution().entrySet().iterator();
    userNb = firstStep.countAvatars();
    toPercentCoef = (userNb > 100) ? userNb / 100 : 1;
    i = 0;
    Globals.stepCount = 1;
    while (it.hasNext()) {
      shell = (VirtualEntityShell) ((Map.Entry) it.next()).getValue();
      entity = new VirtualEntity(shell.getCoord());
      solipsis = (SolipsisProtocol) Network.get(i).getProtocol(applicativeLayerId);
      solipsis.setPeersimNodeId(i);
      solipsis.setVirtualEntity(entity);
      entity.setProtocol(solipsis);
      entity.setOrder(i + 1);
      entity.setId(shell.getId());
      vwd.addToDistribution(entity);
      if (i > 0) {
        solipsis.join((SolipsisProtocol) Network.get(i - 1).getProtocol(applicativeLayerId));
      }
      i++;
      if (i % toPercentCoef == 0) System.err.println(++percent + "%");
    }
    Network.setCapacity(userNb);
    System.err.println("Done.");
    System.err.println("Normalizing Solipsis topology...");
    percent = 0;
    it = vwd.getDistribution().entrySet().iterator();
    for (i = 0; i < userNb; i++) {
      entity = (VirtualEntity) ((Map.Entry) it.next()).getValue();
      //        	System.out.println("peer "+i+": "+entity.getNeighbors().size());
      entity.getProtocol().finalizeKnowledgeZone();
      //        	System.out.println("peer "+i+": "+entity.getNeighbors().size());
      entity.getProtocol().simplifyTopology();
      //        	System.out.println("peer "+i+": "+entity.getNeighbors().size());
      if (i % (3 * toPercentCoef) == 0) System.err.println(++percent + "%");
    }

    it = vwd.getDistribution().entrySet().iterator();
    for (i = 0; i < userNb; i++) {
      entity = (VirtualEntity) ((Map.Entry) it.next()).getValue();
      entity.refreshState();
      if (i % (3 * toPercentCoef) == 0) System.err.println(++percent + "%");
    }

    it = vwd.getDistribution().entrySet().iterator();
    for (i = 0; i < userNb; i++) {
      entity = (VirtualEntity) ((Map.Entry) it.next()).getValue();
      entity.getProtocol().maintainKnowledgeZone();
      entity.getProtocol().finalizeKnowledgeZone();
      entity.getProtocol().removeUnwantedNeighbors();
      //        	System.out.println("peer "+i+": "+entity.getNeighbors().size());
      if (i % (3 * toPercentCoef) == 0) System.err.println(++percent + "%");
    }

    System.err.println("Done.");
    //    	for (int i = 0; i < 15; i++) {
    //    		System.out.println("cycle...");
    //    		Globals.distribution.animate();
    //
    //    	}
    Globals.topologyIsReady = true;
    System.err.println("Populated");
    //		System.err.println("Collisions:" + this.collisionCount());
    //		System.exit(2);
    if (Globals.realTime) {
      //    		VirtualWorldMonitor map = new VirtualWorldMonitor(vwd);
      //    		Globals.monitor = map;
      //        	map.showVirtualWorld();
      Globals.recorder = new VirtualWorldRecorder();
    } else {
      Globals.evaluator = new StatisticsGatherer();
    }
  }
コード例 #2
0
  private void executeSynthetic() {

    int toPercentCoef, percent = 0;
    int userNb = Network.size();
    HashMap<Integer, VirtualEntity> coords;
    SolipsisProtocol solipsis;
    VirtualEntity entity;
    System.err.println("Populating Virtual World with " + userNb + " participants...");
    VirtualWorldDistribution vwd =
        new VirtualWorldDistribution(
            this.distribution,
            userNb,
            Globals.zoneNb,
            Globals.outOfZoneNb,
            Globals.mapSize,
            Globals.zoneSize,
            Globals.smallZoneSize,
            Globals.smallZoneNb,
            this.applicativeLayerId);
    Globals.distribution = vwd;
    coords = vwd.getDistribution();
    Iterator it = coords.entrySet().iterator();
    toPercentCoef = userNb / 100;
    System.err.println("Joining nodes...");
    for (int i = 0; i < userNb; i++) {
      entity = (VirtualEntity) ((Map.Entry) it.next()).getValue();
      solipsis = (SolipsisProtocol) Network.get(i).getProtocol(applicativeLayerId);
      solipsis.setVirtualEntity(entity);
      solipsis.setPeersimNodeId(i);
      entity.setProtocol(solipsis);
      entity.setOrder(i + 1);
      if (i > 0) {
        solipsis.join((SolipsisProtocol) Network.get(i - 1).getProtocol(applicativeLayerId));
      }
      if (i % toPercentCoef == 0) System.err.println(++percent + "%");
      //        	System.out.println("peer "+i+":
      // "+solipsis.getVirtualEntity().getNeighbors().size());
    }
    System.err.println("Done.");
    //    	System.out.println("uci2");
    System.err.println("Normalizing Solipsis topology...");
    percent = 0;
    it = coords.entrySet().iterator();
    for (int i = 0; i < userNb; i++) {
      entity = (VirtualEntity) ((Map.Entry) it.next()).getValue();
      //        	System.out.println("peer "+i+": "+entity.getNeighbors().size());
      entity.getProtocol().finalizeKnowledgeZone();
      //        	System.out.println("peer "+i+": "+entity.getNeighbors().size());
      entity.getProtocol().simplifyTopology();
      //        	System.out.println("peer "+i+": "+entity.getNeighbors().size());
      if (i % (3 * toPercentCoef) == 0) System.err.println(++percent + "%");
    }

    it = coords.entrySet().iterator();
    for (int i = 0; i < userNb; i++) {
      entity = (VirtualEntity) ((Map.Entry) it.next()).getValue();
      entity.refreshState();
      if (i % (3 * toPercentCoef) == 0) System.err.println(++percent + "%");
    }

    it = coords.entrySet().iterator();
    for (int i = 0; i < userNb; i++) {
      entity = (VirtualEntity) ((Map.Entry) it.next()).getValue();
      entity.getProtocol().maintainKnowledgeZone();
      entity.getProtocol().finalizeKnowledgeZone();
      entity.getProtocol().removeUnwantedNeighbors();
      //        	System.out.println("peer "+i+": "+entity.getNeighbors().size());
      if (i % (3 * toPercentCoef) == 0) System.err.println(++percent + "%");
    }

    System.out.println("Done.");
    //    	for (int i = 0; i < 15; i++) {
    //    		System.out.println("cycle...");
    //    		Globals.distribution.animate();
    //
    //    	}
    Globals.topologyIsReady = true;
    System.err.println("Populated");
    //		System.err.println("Collisions:" + this.collisionCount());
    //		System.exit(2);
    if (Globals.realTime) {
      //    		VirtualWorldMonitor map = new VirtualWorldMonitor(vwd);
      //    		Globals.monitor = map;
      //        	map.showVirtualWorld();
      Globals.recorder = new VirtualWorldRecorder();
    } else {
      Globals.evaluator = new StatisticsGatherer();
    }
  }