From 60f575c803a768954592dbceb685d4116027fabf Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Tue, 26 Jun 2018 21:27:51 +0800 Subject: [PATCH] fix bug --- .../core/command/normal/ResumeAllCmd.java | 8 +-- .../aria/core/common/AbsThreadTask.java | 14 +++--- .../download/downloader/AbsGroupUtil.java | 28 +++++------ .../downloader/DownloadGroupUtil.java | 2 +- .../download/downloader/HttpThreadTask.java | 49 ++++++++++--------- .../arialyy/aria/core/queue/AbsTaskQueue.java | 8 ++- build.gradle | 2 +- 7 files changed, 61 insertions(+), 50 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java index 4caa5bd0..76a80536 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java @@ -98,9 +98,9 @@ final class ResumeAllCmd extends AbsNormalCmd { resumeEntity(te); } else if (state == IEntity.STATE_WAIT || state == IEntity.STATE_FAIL) { mWaitList.add(te); - } else if (state == IEntity.STATE_RUNNING) { + } else { if (!mQueue.taskIsRunning(te.getEntity().getKey())) { - resumeEntity(te); + mWaitList.add(te); } } } @@ -122,7 +122,9 @@ final class ResumeAllCmd extends AbsNormalCmd { if (mQueue.getCurrentExePoolNum() < maxTaskNum) { startTask(createTask(te)); } else { - createTask(te); + te.getEntity().setState(IEntity.STATE_WAIT); + AbsTask task = createTask(te); + sendWaitState(task); } } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java index 31fab3f6..263e6e8c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java @@ -245,7 +245,7 @@ public abstract class AbsThreadTask 0) { mListener.onResume(mCurrentLocation); @@ -347,11 +344,12 @@ public abstract class AbsGroupUtil implements IUtil { } private void startTimer() { + isRunning = true; mTimer = new Timer(true); mTimer.schedule(new TimerTask() { @Override public void run() { if (!isRunning) { - closeTimer(false); + closeTimer(); } else if (mCurrentLocation >= 0) { long t = 0; for (DownloadTaskEntity te : mGTEntity.getSubTaskEntities()) { @@ -455,7 +453,7 @@ public abstract class AbsGroupUtil implements IUtil { synchronized (AbsGroupUtil.LOCK) { mStopNum++; if (mStopNum + mCompleteNum + mFailMap.size() == mGroupSize && !isStop) { - closeTimer(false); + closeTimer(); mListener.onStop(mCurrentLocation); } } @@ -476,13 +474,13 @@ public abstract class AbsGroupUtil implements IUtil { mCompleteNum++; //如果子任务完成的数量和总任务数一致,表示任务组任务已经完成 if (mCompleteNum == mGroupSize) { - closeTimer(false); + closeTimer(); mListener.onComplete(); } else if (mFailMap.size() > 0 && mStopNum + mCompleteNum + mFailMap.size() >= mGroupSize && !isStop) { //如果子任务完成数量加上失败的数量和总任务数一致,则任务组停止下载 - closeTimer(false); + closeTimer(); mListener.onStop(mCurrentLocation); } } @@ -511,7 +509,7 @@ public abstract class AbsGroupUtil implements IUtil { mFailMap.put(subTaskEntity.getUrl(), subTaskEntity); mListener.onSubFail(subEntity); if (mFailMap.size() == mExeMap.size() || mFailMap.size() + mCompleteNum == mGroupSize) { - closeTimer(false); + closeTimer(); } if (mFailMap.size() == mGroupSize) { mListener.onFail(true); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java index a552f8b2..f01a6436 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java @@ -164,7 +164,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { private void checkStartFlow() { synchronized (DownloadGroupUtil.class) { if (mInitFailNum == mExeNum) { - closeTimer(false); + closeTimer(); mListener.onFail(true); } if (!isStart && mInitCompleteNum + mInitFailNum == mExeNum || !isNeedLoadFileSize) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java index 70a54650..7708c4f6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java @@ -207,34 +207,39 @@ final class HttpThreadTask extends AbsThreadTask