From 018b6238304f1469c8d31a18bc503a56b04416c3 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Mon, 6 Nov 2017 20:23:21 +0800 Subject: [PATCH] fix bug https://github.com/AriaLyy/Aria/issues/157 --- .../core/command/normal/AbsNormalCmd.java | 7 ++++++ .../core/command/normal/ResumeAllCmd.java | 12 ++++----- .../aria/core/command/normal/StartCmd.java | 16 +++++++----- .../aria/core/common/AbsFtpInfoThread.java | 3 +++ .../aria/core/download/DownloadEntity.java | 2 ++ .../aria/core/download/DownloadReceiver.java | 6 +++++ .../aria/core/download/FtpDownloadTarget.java | 9 +++++++ .../downloader/SimpleDownloadUtil.java | 4 ++- .../arialyy/aria/core/inf/AbsTaskEntity.java | 2 +- .../arialyy/aria/core/queue/AbsTaskQueue.java | 25 +++++++++++++------ .../core/queue/DownloadGroupTaskQueue.java | 4 +++ .../aria/core/queue/DownloadTaskQueue.java | 4 +++ .../arialyy/aria/core/queue/ITaskQueue.java | 9 +++++++ .../aria/core/queue/UploadTaskQueue.java | 4 +++ .../aria/core/scheduler/AbsSchedulers.java | 4 +-- DEV_LOG.md | 5 ++-- .../simple/download/FtpDownloadActivity.java | 9 ++++--- .../service_download/DownloadService.java | 1 - 18 files changed, 94 insertions(+), 32 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java index b6819314..cfe019dd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java @@ -116,6 +116,13 @@ public abstract class AbsNormalCmd extends AbsCmd { mQueue.startTask(tempTask); } + /** + * 恢复任务 + */ + void resumeTask() { + mQueue.resumeTask(tempTask); + } + /** * 启动指定任务 * 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 0ffe8715..98708c73 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 @@ -12,6 +12,7 @@ import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; +import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.NetUtils; import java.util.ArrayList; import java.util.List; @@ -105,13 +106,7 @@ final class ResumeAllCmd extends AbsNormalCmd { * 处理等待状态的任务 */ private void resumeWaitTask() { - int maxTaskNum; - AriaManager manager = AriaManager.getInstance(AriaManager.APP); - if (isDownloadCmd) { - maxTaskNum = manager.getDownloadConfig().getMaxTaskNum(); - } else { - maxTaskNum = manager.getUploadConfig().getMaxTaskNum(); - } + int maxTaskNum = mQueue.getMaxTaskNum(); if (mWaitList == null || mWaitList.isEmpty()) return; for (AbsTaskEntity te : mWaitList) { if (mQueue.getCurrentExePoolNum() < maxTaskNum) { @@ -129,6 +124,9 @@ final class ResumeAllCmd extends AbsNormalCmd { */ private void resumeEntity(AbsTaskEntity te) { if (te instanceof DownloadTaskEntity) { + if (te.requestType == AbsTaskEntity.FTP) { + te.urlEntity = CommonUtil.getFtpUrlInfo(te.getEntity().getKey()); + } mQueue = DownloadTaskQueue.getInstance(); } else if (te instanceof UploadTaskEntity) { mQueue = UploadTaskQueue.getInstance(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java index 32f6b54d..ceaca4cf 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java @@ -17,6 +17,7 @@ package com.arialyy.aria.core.command.normal; import android.text.TextUtils; +import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.QueueMod; import com.arialyy.aria.core.download.DownloadGroupTaskEntity; @@ -24,13 +25,13 @@ import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; +import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.NetUtils; import java.util.ArrayList; import java.util.List; @@ -53,14 +54,12 @@ class StartCmd extends AbsNormalCmd { return; } String mod; - int maxTaskNum; + int maxTaskNum = mQueue.getMaxTaskNum(); AriaManager manager = AriaManager.getInstance(AriaManager.APP); if (isDownloadCmd) { mod = manager.getDownloadConfig().getQueueMod(); - maxTaskNum = manager.getDownloadConfig().getMaxTaskNum(); } else { mod = manager.getUploadConfig().getQueueMod(); - maxTaskNum = manager.getUploadConfig().getMaxTaskNum(); } AbsTask task = getTask(); @@ -79,12 +78,14 @@ class StartCmd extends AbsNormalCmd { || task.getState() == IEntity.STATE_OTHER || task.getState() == IEntity.STATE_POST_PRE || task.getState() == IEntity.STATE_COMPLETE) { - startTask(); + //startTask(); + resumeTask(); } } } else { if (!task.isRunning()) { - startTask(); + //startTask(); + resumeTask(); } } if (mQueue.getCurrentCachePoolNum() == 0) { @@ -142,6 +143,9 @@ class StartCmd extends AbsNormalCmd { for (AbsTaskEntity te : waitList) { if (te.getEntity() == null) continue; if (te instanceof DownloadTaskEntity) { + if (te.requestType == AbsTaskEntity.FTP) { + te.urlEntity = CommonUtil.getFtpUrlInfo(te.getEntity().getKey()); + } mQueue = DownloadTaskQueue.getInstance(); } else if (te instanceof UploadTaskEntity) { mQueue = UploadTaskQueue.getInstance(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java index fc9b68bf..18911a09 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java @@ -89,6 +89,9 @@ public abstract class AbsFtpInfoThread extends DbEntity { /** * 请求类型 - * {@link AbsTaskEntity#HTTP}、{@link AbsTaskEntity#FTP} + * {@link AbsTaskEntity#HTTP}、{@link AbsTaskEntity#FTP}、{@link AbsTaskEntity#FTP_DIR} */ public int requestType = HTTP; diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java index b5f161dc..e55c1302 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java @@ -20,7 +20,6 @@ import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.queue.pool.BaseCachePool; import com.arialyy.aria.core.queue.pool.BaseExecutePool; import com.arialyy.aria.util.ALog; @@ -59,6 +58,23 @@ abstract class AbsTaskQueue= getMaxTaskNum()) { + task.getTaskEntity().getEntity().setState(IEntity.STATE_WAIT); + mCachePool.putTaskToFirst(task); + stopTask(mExecutePool.pollTask()); + } else { + startTask(task); + } + } + /** * 停止所有任务 */ @@ -70,10 +86,6 @@ abstract class AbsTaskQueue return AriaManager.getInstance(AriaManager.APP).getUploadConfig().oldMaxTaskNum; } + @Override public int getMaxTaskNum() { + return AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum(); + } + @Override public UploadTask createTask(String targetName, UploadTaskEntity entity) { UploadTask task = null; if (!TextUtils.isEmpty(targetName)) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java index bcdecc07..55916c1c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java @@ -161,9 +161,7 @@ abstract class AbsSchedulers { //private final String URL = "ftp://192.168.1.9:21/下载/AriaPrj.zip"; //private final String URL = "ftp://192.168.1.9:21/下载/[电影天堂www.dy2018.com]赛车总动员3BD中英双字.mp4"; - private final String URL = "ftp://h:h@tv.dl1234.com:2199/付岩洞复仇者们05.mkv"; - //private final String URL = "ftp://172.18.104.64:21/upload/测试/成都.mp3"; + //private final String URL = "ftp://h:h@tv.dl1234.com:2199/付岩洞复仇者们05.mkv"; + //private final String URL = "ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]xd联盟HD高清国粤双语中字.mkv"; + private final String URL = "ftp://172.18.104.71:21/upload/AS.zip"; @Override protected void init(Bundle savedInstanceState) { super.init(savedInstanceState); @@ -60,8 +61,8 @@ public class FtpDownloadActivity extends BaseActivity