AriaLyy 7 years ago
parent ce36165e1d
commit 89289204a0
  1. 30
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  2. 6
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  3. 11
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java

@ -39,17 +39,21 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
private void resumeDownload() { private void resumeDownload() {
List<DownloadTaskEntity> dTaskEntity = List<DownloadTaskEntity> dTaskEntity =
DbEntity.findDatas(DownloadTaskEntity.class, "isGroupTask=?", "false"); DbEntity.findDatas(DownloadTaskEntity.class, "isGroupTask=?", "false");
for (DownloadTaskEntity te : dTaskEntity) { if (dTaskEntity != null && !dTaskEntity.isEmpty()) {
int state = te.getState(); for (DownloadTaskEntity te : dTaskEntity) {
if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue; int state = te.getState();
resumeEntity(te); if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue;
resumeEntity(te);
}
} }
List<DownloadGroupTaskEntity> groupTask = DbEntity.findAllData(DownloadGroupTaskEntity.class); List<DownloadGroupTaskEntity> groupTask = DbEntity.findAllData(DownloadGroupTaskEntity.class);
for (DownloadGroupTaskEntity te : groupTask) { if (groupTask != null && !groupTask.isEmpty()) {
int state = te.getState(); for (DownloadGroupTaskEntity te : groupTask) {
if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue; int state = te.getState();
resumeEntity(te); if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue;
resumeEntity(te);
}
} }
} }
@ -59,10 +63,12 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
private void resumeUpload() { private void resumeUpload() {
List<UploadTaskEntity> dTaskEntity = List<UploadTaskEntity> dTaskEntity =
DbEntity.findDatas(UploadTaskEntity.class, "isGroupTask=?", "false"); DbEntity.findDatas(UploadTaskEntity.class, "isGroupTask=?", "false");
for (UploadTaskEntity te : dTaskEntity) { if (dTaskEntity != null && !dTaskEntity.isEmpty()) {
int state = te.getState(); for (UploadTaskEntity te : dTaskEntity) {
if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue; int state = te.getState();
resumeEntity(te); if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue;
resumeEntity(te);
}
} }
} }

@ -26,7 +26,9 @@ import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.queue.pool.BaseCachePool; import com.arialyy.aria.core.queue.pool.BaseCachePool;
import com.arialyy.aria.core.queue.pool.BaseExecutePool; import com.arialyy.aria.core.queue.pool.BaseExecutePool;
import java.security.Key;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
@ -66,13 +68,11 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
* 停止所有任务 * 停止所有任务
*/ */
@Override public void stopAllTask() { @Override public void stopAllTask() {
mCachePool.clear();
for (String key : mExecutePool.getAllTask().keySet()) { for (String key : mExecutePool.getAllTask().keySet()) {
TASK task = mExecutePool.getAllTask().get(key); TASK task = mExecutePool.getAllTask().get(key);
if (task != null && task.isRunning()) task.stop(); if (task != null && task.isRunning()) task.stop();
} }
for (String key : mCachePool.getAllTask().keySet()) {
mCachePool.removeTask(key);
}
} }
@Override public int getMaxTaskNum() { @Override public int getMaxTaskNum() {

@ -53,6 +53,17 @@ public class BaseCachePool<TASK extends AbsTask> implements IPool<TASK> {
return mCacheMap; return mCacheMap;
} }
/**
* 清除所有缓存的任务
*/
public void clear(){
for (String key : mCacheMap.keySet()){
TASK task = mCacheMap.get(key);
mCacheQueue.remove(task);
mCacheMap.remove(key);
}
}
/** /**
* 将任务放在队首 * 将任务放在队首
*/ */

Loading…
Cancel
Save