Distributed Systems - Event-driven perspective of a P2P file transfer application

221 Views Asked by At

I have a P2P file transfer application working in background in wich the file sharing only should be activated when both machines aren't in use. Supposing that in one machine connected to n others the sharing program runs the following code in n+1 threads:

    /* For eache one of the n peers */
    synchronized void upload(Peer p) {
      while(p.notFinished()) {
      while(isBusy() || p.isBusy())
        wait();
        p.sendNextMB();
      }
    }



    synchronized void report() {
       while(true) {
          while(!isBusy()) wait();
          for(Peer p: peers) p.sendBusy();
          while(isBusy()) wait();
          for(Peer p: peers) p.sendIdle();
       }
    }

My question is how could, in a general way, this program be achieved in a event-driven perspective? And how and why would I choose, on each moment, which event is the next to be executed?

Best Regards

0

There are 0 best solutions below