public void update() { for (int i = 0; i < downloadingFiles.size(); i++) { DownloadingFile dFile = downloadingFiles.get(i); if (dFile.elapsedTime >= dFile.delay) { SimulationFile sf = downloadingFiles.get(i).sFile; // Simulate Download if (sf.LoadAmount < sf.size) { sf.LoadAmount += sf.polularity; } else // Finished downloading { downloadingFiles.remove(i); sFile.add(sf); Random rng = new Random(); if (rng.nextFloat() <= publishProb) // Check if file is to be published { tracker.publishFile(this, sf); } } } else { dFile.elapsedTime++; } } }
void onNewFileDetected(int fileID) { Random rng = new Random(); float dieRoll = rng.nextFloat(); if (dieRoll < downloadProb) { SimulationFile temp = tracker.queryAndDwldFile(this, fileID); DownloadingFile dFile = new DownloadingFile(new SimulationFile(temp.UID, temp.size, temp.polularity)); downloadingFiles.add(dFile); } }