From 89289204a09483d2e6f2727563943831e570c834 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Fri, 1 Sep 2017 16:08:23 +0800 Subject: [PATCH] fix bug https://github.com/AriaLyy/Aria/issues/105 --- .../core/command/normal/ResumeAllCmd.java | 30 +++++++++++-------- .../arialyy/aria/core/queue/AbsTaskQueue.java | 6 ++-- .../aria/core/queue/pool/BaseCachePool.java | 11 +++++++ 3 files changed, 32 insertions(+), 15 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 412a0ff3..11247523 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 @@ -39,17 +39,21 @@ final class ResumeAllCmd extends AbsNormalCmd { private void resumeDownload() { List dTaskEntity = DbEntity.findDatas(DownloadTaskEntity.class, "isGroupTask=?", "false"); - for (DownloadTaskEntity te : dTaskEntity) { - int state = te.getState(); - if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue; - resumeEntity(te); + if (dTaskEntity != null && !dTaskEntity.isEmpty()) { + for (DownloadTaskEntity te : dTaskEntity) { + int state = te.getState(); + if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue; + resumeEntity(te); + } } List groupTask = DbEntity.findAllData(DownloadGroupTaskEntity.class); - for (DownloadGroupTaskEntity te : groupTask) { - int state = te.getState(); - if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue; - resumeEntity(te); + if (groupTask != null && !groupTask.isEmpty()) { + for (DownloadGroupTaskEntity te : groupTask) { + int state = te.getState(); + if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue; + resumeEntity(te); + } } } @@ -59,10 +63,12 @@ final class ResumeAllCmd extends AbsNormalCmd { private void resumeUpload() { List dTaskEntity = DbEntity.findDatas(UploadTaskEntity.class, "isGroupTask=?", "false"); - for (UploadTaskEntity te : dTaskEntity) { - int state = te.getState(); - if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue; - resumeEntity(te); + if (dTaskEntity != null && !dTaskEntity.isEmpty()) { + for (UploadTaskEntity te : dTaskEntity) { + int state = te.getState(); + if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue; + resumeEntity(te); + } } } 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 acb59430..50f659ad 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 @@ -26,7 +26,9 @@ import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.queue.pool.BaseCachePool; import com.arialyy.aria.core.queue.pool.BaseExecutePool; +import java.security.Key; import java.util.Iterator; +import java.util.Map; import java.util.Set; /** @@ -66,13 +68,11 @@ abstract class AbsTaskQueue implements IPool { return mCacheMap; } + /** + * 清除所有缓存的任务 + */ + public void clear(){ + for (String key : mCacheMap.keySet()){ + TASK task = mCacheMap.get(key); + mCacheQueue.remove(task); + mCacheMap.remove(key); + } + } + /** * 将任务放在队首 */