Skip to content

Commit

Permalink
fix(status-sync): sync the pause status when the status changed simul…
Browse files Browse the repository at this point in the history
…taneously
  • Loading branch information
Jacksgong committed Jun 27, 2017
1 parent a65fddf commit 4870da2
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ public void run() {
handleFirstConnected(firstConnectionTask.getRequestHeader(),
firstConnectionTask, connection);

if (paused) return;
if (paused) {
model.setStatus(FileDownloadStatus.paused);
return;
}

// 2. fetch
checkupBeforeFetch();
Expand All @@ -290,7 +293,11 @@ public void run() {
" must be larger than 0", connection));
}

if (paused) return;
if (paused) {
model.setStatus(FileDownloadStatus.paused);
return;
}

isSingleConnection = connectionCount == 1;
if (isSingleConnection) {
// single connection
Expand Down Expand Up @@ -504,8 +511,12 @@ private void fetchWithSingleConnection(final ConnectionProfile profile, FileDown
model.setConnectionCount(1);
database.updateConnectionCount(model.getId(), 1);
singleFetchDataTask = builder.build();
singleFetchDataTask.run();
if (paused) singleFetchDataTask.pause();
if (paused) {
model.setStatus(FileDownloadStatus.paused);
singleFetchDataTask.pause();
} else {
singleFetchDataTask.run();
}
}

private void fetchWithMultipleConnectionFromResume(final int connectionCount, final List<ConnectionModel> connectionModelList) throws InterruptedException {
Expand Down Expand Up @@ -623,7 +634,10 @@ private void fetchWithMultipleConnection(final List<ConnectionModel> connectionM
}
subTasks.add(Executors.callable(runnable));
}
if (paused) return;
if (paused) {
model.setStatus(FileDownloadStatus.paused);
return;
}

List<Future<Object>> subTaskFutures = DOWNLOAD_EXECUTOR.invokeAll(subTasks);
if (FileDownloadLog.NEED_LOG) {
Expand Down

0 comments on commit 4870da2

Please sign in to comment.