Develop #1

Open
Fateme_Azizi wants to merge 6 commits from develop into main
Showing only changes of commit fa47ea93ae - Show all commits
+15 -14
View File
@@ -21,54 +21,55 @@ public class DownloadWorker implements Runnable {
@Override
public void run() {
// TODO: Record the chunk start time in chunkStatus.
// Record the chunk start time in chunkStatus.
chunkStatus.setStartTimeMs(System.currentTimeMillis());
double downloaded = 0.0;
// TODO: Print a message that this chunk has started downloading.
System.out.println("Starting download for Chunk ID: " + chunkStatus.getChunkId());
// Print a message that this chunk has started downloading.
System.out.println("Starting download for Chunk " + chunkStatus.getChunkId());
while (downloaded < chunkStatus.getChunkSizeMB()) {
// TODO: Generate a random sleep delay between min and max delay.
// Generate a random sleep delay between min and max delay.
long minDelay = config.getMinStepDelayMs();
long maxDelay = config.getMaxStepDelayMs();
long sleepTime = minDelay + (long) ((maxDelay - minDelay) * random.nextDouble());
// TODO: Sleep for that delay.
// Sleep for that delay.
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// TODO: Generate a random download amount for this step.
// Generate a random download amount for this step.
double minStep = config.getMinStepDownloadMB();
double maxStep = config.getMaxStepDownloadMB();
double downloadAmount = minStep + ((maxStep - minStep) * random.nextDouble());
// TODO: Increase downloaded, but do not go beyond chunk size.
// Increase downloaded, but do not go beyond chunk size.
if(downloaded + downloadAmount >= chunkStatus.getChunkSizeMB())
downloaded = chunkStatus.getChunkSizeMB();
else
downloaded += downloadAmount;
// TODO: Save the updated downloaded value into chunkStatus.
// Save the updated downloaded value into chunkStatus.
chunkStatus.setDownloadedMB(downloaded);
// TODO: Optionally print step-by-step progress.
System.out.println("Chunk ID: " + chunkStatus.getChunkId() + " | downloaded: " + downloaded);
// Optionally print step-by-step progress.
System.out.print("Chunk " + chunkStatus.getChunkId() + " | downloaded: ");
System.out.printf("%.2f%n", downloaded);
}
// TODO: Mark the chunk as completed.
// Mark the chunk as completed.
chunkStatus.setCompleted(true);
// TODO: Record the chunk end time in chunkStatus.
// Record the chunk end time in chunkStatus.
chunkStatus.setEndTimeMs(System.currentTimeMillis());
// TODO: Print a message that this chunk has finished downloading.
System.out.println("Chunk ID: " + chunkStatus.getChunkId() + " | COMPLETED!");
// Print a message that this chunk has finished downloading.
System.out.println("\nChunk " + chunkStatus.getChunkId() + " | COMPLETED!\n");
}
}