develop
This commit is contained in:
@@ -23,8 +23,11 @@ public class DownloadWorker implements Runnable {
|
||||
public void run() {
|
||||
// TODO: Record the chunk start time in chunkStatus.
|
||||
double downloaded = 0.0;
|
||||
chunkStatus.setStartTimeMs(System.currentTimeMillis());
|
||||
chunkStatus.setDownloadedMB(downloaded);
|
||||
|
||||
// TODO: Print a message that this chunk has started downloading.
|
||||
System.out.println("Chunk #" + chunkStatus.getChunkId() + " started downloading.");
|
||||
|
||||
while (downloaded < chunkStatus.getChunkSizeMB()) {
|
||||
// TODO: Generate a random sleep delay between min and max delay.
|
||||
@@ -33,11 +36,28 @@ public class DownloadWorker implements Runnable {
|
||||
// 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.
|
||||
int delay = config.getMinStepDelayMs() + random.nextInt(config.getMaxStepDelayMs() - config.getMinStepDelayMs());
|
||||
try {
|
||||
Thread.sleep(delay);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
downloaded+=0.5;
|
||||
|
||||
if (downloaded > chunkStatus.getChunkSizeMB())
|
||||
downloaded = chunkStatus.getChunkSizeMB();
|
||||
chunkStatus.setDownloadedMB(downloaded);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 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.setEndTimeMs(System.currentTimeMillis());
|
||||
chunkStatus.setCompleted(true);
|
||||
System.out.println("Chunk #" + chunkStatus.getChunkId() + " finished downloading.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user