finishing DownloadWorker, ProgressMonitor, and Main

This commit is contained in:
2026-06-04 18:46:19 +03:30
parent 9e5c715088
commit 0240bdb2ea
3 changed files with 56 additions and 4 deletions
+33 -2
View File
@@ -22,22 +22,53 @@ public class DownloadWorker implements Runnable {
@Override
public void run() {
// TODO: Record the chunk start time in chunkStatus.
chunkStatus.setStartTimeMs(System.currentTimeMillis());
double downloaded = 0.0;
System.out.printf("[%s] Started — Chunk #%d (%.1f MB)%n",
Thread.currentThread().getName(),
chunkStatus.getChunkId(),
chunkStatus.getChunkSizeMB());
// TODO: Print a message that this chunk has started downloading.
while (downloaded < chunkStatus.getChunkSizeMB()) {
int delay = config.getMinStepDelayMs()
+ random.nextInt(config.getMaxStepDelayMs() - config.getMinStepDelayMs() + 1);
// TODO: Generate a random sleep delay between min and max delay.
// TODO: Sleep for that delay.
// TODO: Generate a random download amount for this step.
// TODO: Increase downloaded, but do not go beyond chunk size.
// TODO: Save the updated downloaded value into chunkStatus.
// TODO: Optionally print step-by-step progress.
}
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
double step = config.getMinStepDownloadMB()
+ random.nextDouble() * (config.getMaxStepDownloadMB() - config.getMinStepDownloadMB());
downloaded = Math.min(downloaded + step, chunkStatus.getChunkSizeMB());
chunkStatus.setDownloadedMB(downloaded);
System.out.printf("[%s] Chunk #%d → %.2f / %.1f MB (%.1f%%)%n",
Thread.currentThread().getName(),
chunkStatus.getChunkId(),
chunkStatus.getDownloadedMB(),
chunkStatus.getChunkSizeMB(),
chunkStatus.getProgressPercentage());
}
// TODO: Mark the chunk as completed.
// TODO: Record the chunk end time in chunkStatus.
// TODO: Print a message that this chunk has finished downloading.
}
chunkStatus.setCompleted(true);
chunkStatus.setEndTimeMs(System.currentTimeMillis());
System.out.printf("[%s] Finished — Chunk #%d in %d ms%n",
Thread.currentThread().getName(),
chunkStatus.getChunkId(),
chunkStatus.getDownloadDurationMs());
}
}