예제 #1
0
  public static void init() {
    EventHandler.setController(new PullBasedPeerController());
    Network.init();
    OverlayFactory.init();
    PeerFactory.init();
    Network.init();
    Message.init();

    Iterator<Video> itv = Repository.getVideoIterator();
    p2pOverlay = new ArrayList<Overlay>();
    Servers = new ArrayList<Server>();
    while (itv.hasNext()) {
      p2pOverlay.add(OverlayFactory.genOverlay(itv.next()));
    }

    Peer tmp = PeerFactory.genPeer(null);
    while (tmp != null) {
      Output.printP2PEvent(
          "Server"
              + tmp.getPeerID()
              + " created! Bandwidth:"
              + Utilities.displayDouble(tmp.getUploadBW()));
      Servers.add((Server) tmp);
      tmp = PeerFactory.genPeer(null);
    }
  }
예제 #2
0
  public static void dropService(User who) {

    Iterator<Video> itvr = who.getPlayedIterator();
    while (itvr.hasNext()) {
      getOverlay(itvr.next()).leaveOverlay(who);
    }
    who.leave();

    who.getPeer().destroy();

    Output.printTrack(
        who,
        "User"
            + who.getUserID()
            + " stayed in system for:"
            + Utilities.displayDouble(who.getLeaveTime() - who.getInitTime())
            + " network overload:"
            + Utilities.displayPercentage(who.getPeer().networkOverload())
            + "% be interrupted:"
            + who.getInterruptedTime()
            + "s");
    Output.stopTracing(who);
  }
예제 #3
0
  public static void printOverlay() {
    // 输出服务器繁忙率
    Iterator<Server> its = Servers.iterator();
    Server tmp;
    while (its.hasNext()) {
      tmp = its.next();
      Output.printSTAT(
          "server"
              + tmp.getServerID()
              + ": percentage of busy time: "
              + Utilities.displayPercentage(tmp.getUtilizationRate())
              + "%");
    }

    // 输出每个Overlay信息。
    Iterator<Overlay> ito = p2pOverlay.iterator();

    while (ito.hasNext()) {
      ito.next().printInfo();
    }
  }