From b2f11412478eeb900fda50d8ec244d26bf734ff3 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Mon, 25 Jun 2018 21:16:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BD=91=E7=BB=9C=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=97=B6=EF=BC=8C=E8=BF=87=E5=BA=A6=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/command/normal/ResumeAllCmd.java | 4 +- .../arialyy/aria/core/common/AbsFileer.java | 4 +- .../aria/core/common/AbsThreadTask.java | 24 +++++----- .../aria/core/common/StateConstance.java | 12 +++-- .../aria/core/download/BaseDListener.java | 3 +- .../download/downloader/AbsGroupUtil.java | 19 ++++---- .../download/downloader/FtpThreadTask.java | 10 ++--- .../download/downloader/HttpThreadTask.java | 44 +++++++++---------- .../arialyy/aria/core/queue/AbsTaskQueue.java | 8 +--- .../aria/core/scheduler/AbsSchedulers.java | 5 +++ .../common/ConnectionChangeReceiver.java | 5 ++- .../multi_download/FileListAdapter.java | 6 +-- .../multi_download/MultiDownloadActivity.java | 1 + 13 files changed, 75 insertions(+), 70 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 3f1ff7e7..4caa5bd0 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 @@ -27,7 +27,7 @@ import java.util.List; * 1.如果执行队列没有满,则开始下载任务,直到执行队列满 * 2.如果队列执行队列已经满了,则将所有任务添加到等待队列中 * 3.如果队列中只有等待状态的任务,如果执行队列没有满,则会启动等待状态的任务,如果执行队列已经满了,则会将所有等待状态的任务加载到缓存队列中 - * 4.恢复下载的任务规则是,停止时间越晚的任务启动越早,安装DESC来进行排序 + * 4.恢复下载的任务规则是,停止时间越晚的任务启动越早,按照DESC来进行排序 */ final class ResumeAllCmd extends AbsNormalCmd { private List mWaitList = new ArrayList<>(); @@ -96,7 +96,7 @@ final class ResumeAllCmd extends AbsNormalCmd { int state = te.getState(); if (state == IEntity.STATE_STOP || state == IEntity.STATE_OTHER) { resumeEntity(te); - } else if (state == IEntity.STATE_WAIT) { + } else if (state == IEntity.STATE_WAIT || state == IEntity.STATE_FAIL) { mWaitList.add(te); } else if (state == IEntity.STATE_RUNNING) { if (!mQueue.taskIsRunning(te.getEntity().getKey())) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java index 82e3f9c1..50035334 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java @@ -535,9 +535,7 @@ public abstract class AbsFileer= START_THREAD_NUM; + && FAIL_NUM == START_THREAD_NUM; } /** * 所有子线程是否都已经完成 */ public boolean isComplete() { - return COMPLETE_THREAD_NUM >= START_THREAD_NUM; + return COMPLETE_THREAD_NUM == START_THREAD_NUM; } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java index 1758da73..a3a4ac32 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java @@ -174,7 +174,8 @@ class BaseDListener 0) { + } + if (location > 0) { mEntity.setCurrentProgress(location); } mTaskEntity.update(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java index 39faefbe..1ad43cd9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java @@ -262,9 +262,8 @@ public abstract class AbsGroupUtil implements IUtil { dt.stop(); } } - if (mDownloaderMap.size() == 0) { - mListener.onStop(mCurrentLocation); - } + clearState(); + mListener.onStop(mCurrentLocation); } protected void onStop() { @@ -279,7 +278,7 @@ public abstract class AbsGroupUtil implements IUtil { mListener.onPre(); mGroupSize = mGTEntity.getSubTaskEntities().size(); mTotalLen = mGTEntity.getEntity().getFileSize(); - isNeedLoadFileSize = mTotalLen <= 1; + isNeedLoadFileSize = mTotalLen <= 10; for (DownloadTaskEntity te : mGTEntity.getSubTaskEntities()) { File file = new File(te.getKey()); if (te.getState() == IEntity.STATE_COMPLETE && file.exists()) { @@ -455,7 +454,7 @@ public abstract class AbsGroupUtil implements IUtil { mListener.onSubStop(subEntity); synchronized (AbsGroupUtil.LOCK) { mStopNum++; - if (mStopNum + mCompleteNum + mFailMap.size() == mGroupSize) { + if (mStopNum + mCompleteNum + mFailMap.size() == mGroupSize && !isStop) { closeTimer(false); mListener.onStop(mCurrentLocation); } @@ -479,7 +478,9 @@ public abstract class AbsGroupUtil implements IUtil { if (mCompleteNum == mGroupSize) { closeTimer(false); mListener.onComplete(); - } else if (mFailMap.size() > 0 && mStopNum + mCompleteNum + mFailMap.size() >= mGroupSize) { + } else if (mFailMap.size() > 0 + && mStopNum + mCompleteNum + mFailMap.size() >= mGroupSize + && !isStop) { //如果子任务完成数量加上失败的数量和总任务数一致,则任务组停止下载 closeTimer(false); mListener.onStop(mCurrentLocation); @@ -500,10 +501,10 @@ public abstract class AbsGroupUtil implements IUtil { private void reTry(boolean needRetry) { Downloader dt = mDownloaderMap.get(subEntity.getUrl()); synchronized (AbsGroupUtil.LOCK) { - if (dt != null + if (!isCancel && !isStop && dt != null && !dt.isBreak() && needRetry - && subEntity.getFailNum() < 5 + && subEntity.getFailNum() < 3 && (NetUtils.isConnected(AriaManager.APP) || isNotNetRetry)) { reStartTask(dt); } else { @@ -533,7 +534,7 @@ public abstract class AbsGroupUtil implements IUtil { dt.retryThreadTask(); } } - }, 3000); + }, 5000); } private void handleSpeed(long speed) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java index 40fdc2fb..e5c2a046 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java @@ -101,12 +101,8 @@ class FtpThreadTask extends AbsFtpThreadTask readDynamicFile(is); } else { readNormal(is); + handleComplete(); } - - if (isBreak()) { - return; - } - handleComplete(); } catch (IOException e) { fail(mChildCurrentLocation, String.format("下载失败【%s】", mConfig.URL), e); } catch (Exception e) { @@ -129,6 +125,9 @@ class FtpThreadTask extends AbsFtpThreadTask * 处理线程完成的情况 */ private void handleComplete() { + if (isBreak()) { + return; + } ALog.i(TAG, String.format("任务【%s】线程__%s__下载完毕", mConfig.TEMP_FILE.getName(), mConfig.THREAD_ID)); writeConfig(true, mConfig.END_LOCATION); @@ -178,6 +177,7 @@ class FtpThreadTask extends AbsFtpThreadTask bf.compact(); progress(len); } + handleComplete(); } catch (InterruptedException e) { e.printStackTrace(); } catch (IOException e) { 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 314a0286..70a54650 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 @@ -99,12 +99,8 @@ final class HttpThreadTask extends AbsThreadTask