修复进度有时错乱问题,task类优化 https://github.com/AriaLyy/Aria/issues/134

pull/330/head
AriaLyy 7 years ago
parent 506f8913b2
commit 95fe03cc63
  1. 6
      Aria/src/main/java/com/arialyy/aria/core/SubTaskManager.java
  2. 4
      Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java
  3. 13
      Aria/src/main/java/com/arialyy/aria/core/command/ICmd.java
  4. 6
      Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java
  5. 4
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCancelCmd.java
  6. 4
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java
  7. 4
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStartCmd.java
  8. 4
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStopCmd.java
  9. 44
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java
  10. 4
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java
  11. 4
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java
  12. 4
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java
  13. 4
      Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java
  14. 22
      Aria/src/main/java/com/arialyy/aria/core/command/normal/NormalCmdFactory.java
  15. 84
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  16. 69
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  17. 4
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StopAllCmd.java
  18. 4
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java
  19. 15
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  20. 11
      Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java
  21. 4
      Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java
  22. 3
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java
  23. 11
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java
  24. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTaskEntity.java
  25. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadListener.java
  26. 9
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  27. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  28. 11
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  29. 3
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java
  30. 7
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsDownloadTarget.java
  31. 8
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java
  32. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTaskEntity.java
  33. 5
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java
  34. 23
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTaskEntity.java
  35. 36
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  36. 36
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java
  37. 6
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java
  38. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsUploadTarget.java
  39. 5
      Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java
  40. 26
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  41. 6
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java
  42. 6
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  43. 34
      Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
  44. 5
      Aria/src/main/java/com/arialyy/aria/core/queue/QueueControl.java
  45. 6
      Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java
  46. 7
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java
  47. 20
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  48. 2
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadGroupSchedulers.java
  49. 2
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
  50. 4
      Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java
  51. 9
      Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java
  52. 5
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  53. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  54. 12
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  55. 1
      DEV_LOG.md
  56. 4
      README.md
  57. 2
      app/src/main/assets/aria_config.xml
  58. 16
      aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
  59. 4
      aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java
  60. 2
      build.gradle

@ -18,7 +18,7 @@ package com.arialyy.aria.core;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.command.group.GroupCmdFactory; import com.arialyy.aria.core.command.group.GroupCmdFactory;
import com.arialyy.aria.core.inf.BaseGroupTaskEntity; import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.util.List; import java.util.List;
@ -28,10 +28,10 @@ import java.util.List;
*/ */
public class SubTaskManager { public class SubTaskManager {
private String TAG = "SubTaskManager"; private String TAG = "SubTaskManager";
private BaseGroupTaskEntity mEntity; private AbsGroupTaskEntity mEntity;
private String mTargetName; private String mTargetName;
public SubTaskManager(String targetName, BaseGroupTaskEntity entity) { public SubTaskManager(String targetName, AbsGroupTaskEntity entity) {
mTargetName = targetName; mTargetName = targetName;
mEntity = entity; mEntity = entity;
} }

@ -26,6 +26,8 @@ public abstract class AbsCmdFactory<TASK_ENTITY extends AbsTaskEntity, CMD exten
/** /**
* @param target 创建任务的对象 * @param target 创建任务的对象
* @param entity 下载实体 * @param entity 下载实体
* @param taskType {@link ICmd#TASK_TYPE_DOWNLOAD}{@link ICmd#TASK_TYPE_DOWNLOAD_GROUP}{@link
* ICmd#TASK_TYPE_UPLOAD}
*/ */
public abstract CMD createCmd(String target, TASK_ENTITY entity, int type); public abstract CMD createCmd(String target, TASK_ENTITY entity, int type, int taskType);
} }

@ -20,6 +20,19 @@ package com.arialyy.aria.core.command;
*/ */
public interface ICmd { public interface ICmd {
/**
* 单任务下载任务
*/
int TASK_TYPE_DOWNLOAD = 0x01;
/**
* 任务组下载任务
*/
int TASK_TYPE_DOWNLOAD_GROUP = 0x02;
/**
* 上传任务
*/
int TASK_TYPE_UPLOAD = 0x10;
/** /**
* 执行命令 * 执行命令
*/ */

@ -19,8 +19,8 @@ import android.util.Log;
import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.command.AbsCmd;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.inf.AbsGroupTask; import com.arialyy.aria.core.inf.AbsGroupTask;
import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.BaseGroupTaskEntity;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -28,7 +28,7 @@ import com.arialyy.aria.util.CommonUtil;
* Created by AriaL on 2017/6/29. * Created by AriaL on 2017/6/29.
* 任务组命令 * 任务组命令
*/ */
public abstract class AbsGroupCmd<T extends BaseGroupTaskEntity> extends AbsCmd<T> { public abstract class AbsGroupCmd<T extends AbsGroupTaskEntity> extends AbsCmd<T> {
/** /**
* 需要控制的子任务url * 需要控制的子任务url
*/ */
@ -60,7 +60,7 @@ public abstract class AbsGroupCmd<T extends BaseGroupTaskEntity> extends AbsCmd<
} }
boolean checkTask() { boolean checkTask() {
tempTask = (AbsGroupTask) mQueue.getTask(mTaskEntity.getEntity()); tempTask = (AbsGroupTask) mQueue.getTask(mTaskEntity.getEntity().getKey());
if (tempTask == null) { if (tempTask == null) {
createTask(); createTask();
if (tempTask.isComplete()) { if (tempTask.isComplete()) {

@ -15,13 +15,13 @@
*/ */
package com.arialyy.aria.core.command.group; package com.arialyy.aria.core.command.group;
import com.arialyy.aria.core.inf.BaseGroupTaskEntity; import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
/** /**
* Created by AriaL on 2017/6/29. * Created by AriaL on 2017/6/29.
* 删除任务组 * 删除任务组
*/ */
class GroupCancelCmd<T extends BaseGroupTaskEntity> extends AbsGroupCmd<T> { class GroupCancelCmd<T extends AbsGroupTaskEntity> extends AbsGroupCmd<T> {
/** /**
* @param targetName 创建任务的对象名 * @param targetName 创建任务的对象名
*/ */

@ -16,7 +16,7 @@
package com.arialyy.aria.core.command.group; package com.arialyy.aria.core.command.group;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.BaseGroupTaskEntity; import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
/** /**
* Created by AriaL on 2017/6/29. * Created by AriaL on 2017/6/29.
@ -57,7 +57,7 @@ public class GroupCmdFactory {
* @param type 命令类型{@link #SUB_TASK_START}{@link #SUB_TASK_STOP}{@link #SUB_TASK_CANCEL} * @param type 命令类型{@link #SUB_TASK_START}{@link #SUB_TASK_STOP}{@link #SUB_TASK_CANCEL}
* @param childUrl 需要控制的子任务url * @param childUrl 需要控制的子任务url
*/ */
public AbsGroupCmd createCmd(String target, BaseGroupTaskEntity entity, int type, public AbsGroupCmd createCmd(String target, AbsGroupTaskEntity entity, int type,
String childUrl) { String childUrl) {
AbsGroupCmd cmd = null; AbsGroupCmd cmd = null;
switch (type) { switch (type) {

@ -15,13 +15,13 @@
*/ */
package com.arialyy.aria.core.command.group; package com.arialyy.aria.core.command.group;
import com.arialyy.aria.core.inf.BaseGroupTaskEntity; import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
/** /**
* Created by AriaL on 2017/6/29. * Created by AriaL on 2017/6/29.
* 任务组开始命令该命令负责处理任务组子任务的开始\恢复等工作 * 任务组开始命令该命令负责处理任务组子任务的开始\恢复等工作
*/ */
class GroupStartCmd<T extends BaseGroupTaskEntity> extends AbsGroupCmd<T> { class GroupStartCmd<T extends AbsGroupTaskEntity> extends AbsGroupCmd<T> {
/** /**
* @param targetName 创建任务的对象名 * @param targetName 创建任务的对象名
*/ */

@ -15,13 +15,13 @@
*/ */
package com.arialyy.aria.core.command.group; package com.arialyy.aria.core.command.group;
import com.arialyy.aria.core.inf.BaseGroupTaskEntity; import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
/** /**
* Created by AriaL on 2017/6/29. * Created by AriaL on 2017/6/29.
* 停止任务组的命令 * 停止任务组的命令
*/ */
class GroupStopCmd<T extends BaseGroupTaskEntity> extends AbsGroupCmd<T> { class GroupStopCmd<T extends AbsGroupTaskEntity> extends AbsGroupCmd<T> {
/** /**
* @param targetName 创建任务的对象名 * @param targetName 创建任务的对象名
*/ */

@ -16,7 +16,9 @@
package com.arialyy.aria.core.command.normal; package com.arialyy.aria.core.command.normal;
import android.util.Log;
import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.command.AbsCmd;
import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
@ -39,27 +41,43 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
boolean canExeCmd = true; boolean canExeCmd = true;
private AbsTask tempTask = null; private AbsTask tempTask = null;
int taskType;
/** /**
* @param targetName 产生任务的对象名 * @param targetName 产生任务的对象名
* @param taskType 下载任务类型{@link ICmd#TASK_TYPE_DOWNLOAD}{@link ICmd#TASK_TYPE_DOWNLOAD_GROUP}{@link
* ICmd#TASK_TYPE_UPLOAD}
*/ */
AbsNormalCmd(String targetName, T entity) { AbsNormalCmd(String targetName, T entity, int taskType) {
//canExeCmd = CheckUtil.checkCmdEntity(entity, this.taskType = taskType;
// !(this instanceof CancelCmd) || !(this instanceof StopCmd));
mTargetName = targetName; mTargetName = targetName;
mTaskEntity = entity; mTaskEntity = entity;
TAG = CommonUtil.getClassName(this); TAG = CommonUtil.getClassName(this);
if (entity instanceof DownloadTaskEntity) { if (taskType == ICmd.TASK_TYPE_DOWNLOAD) {
if (!(entity instanceof DownloadTaskEntity)) {
Log.w(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD");
return;
}
mQueue = DownloadTaskQueue.getInstance(); mQueue = DownloadTaskQueue.getInstance();
isDownloadCmd = true; } else if (taskType == ICmd.TASK_TYPE_DOWNLOAD_GROUP) {
} else if (entity instanceof UploadTaskEntity) { if (!(entity instanceof DownloadGroupTaskEntity)) {
mQueue = UploadTaskQueue.getInstance(); Log.w(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD_GROUP");
isDownloadCmd = false; return;
} else if (entity instanceof DownloadGroupTaskEntity) { }
mQueue = DownloadGroupTaskQueue.getInstance(); mQueue = DownloadGroupTaskQueue.getInstance();
isDownloadCmd = true; } else if (taskType == ICmd.TASK_TYPE_UPLOAD) {
if (!(entity instanceof UploadTaskEntity)) {
Log.w(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_UPLOAD");
return;
} }
mQueue = UploadTaskQueue.getInstance();
} else {
Log.w(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD、TASK_TYPE_DOWNLOAD_GROUP、TASK_TYPE_UPLOAD");
} }
isDownloadCmd = taskType < ICmd.TASK_TYPE_UPLOAD;
}
/** /**
* 删除所有任务 * 删除所有任务
@ -88,7 +106,7 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
*/ */
void removeTask() { void removeTask() {
if (tempTask == null) createTask(); if (tempTask == null) createTask();
mQueue.removeTask(tempTask); mQueue.cancelTask(tempTask);
} }
/** /**
@ -113,7 +131,7 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
* @return 执行任务 * @return 执行任务
*/ */
AbsTask getTask() { AbsTask getTask() {
tempTask = mQueue.getTask(mTaskEntity.getEntity()); tempTask = mQueue.getTask(mTaskEntity.getEntity().getKey());
return tempTask; return tempTask;
} }
@ -123,7 +141,7 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
* @return 执行任务 * @return 执行任务
*/ */
AbsTask getTask(AbsEntity entity) { AbsTask getTask(AbsEntity entity) {
tempTask = mQueue.getTask(entity); tempTask = mQueue.getTask(entity.getKey());
return tempTask; return tempTask;
} }

@ -27,8 +27,8 @@ import com.arialyy.aria.core.inf.AbsTaskEntity;
*/ */
class AddCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> { class AddCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
AddCmd(String targetName, T entity) { AddCmd(String targetName, T entity, int taskType) {
super(targetName, entity); super(targetName, entity, taskType);
} }
@Override public void executeCmd() { @Override public void executeCmd() {

@ -38,8 +38,8 @@ public class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
/** /**
* @param targetName 产生任务的对象名 * @param targetName 产生任务的对象名
*/ */
CancelAllCmd(String targetName, T entity) { CancelAllCmd(String targetName, T entity, int taskType) {
super(targetName, entity); super(targetName, entity, taskType);
} }
@Override public void executeCmd() { @Override public void executeCmd() {

@ -31,8 +31,8 @@ public class CancelCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
*/ */
public boolean removeFile = false; public boolean removeFile = false;
CancelCmd(String targetName, T entity) { CancelCmd(String targetName, T entity, int taskType) {
super(targetName, entity); super(targetName, entity, taskType);
} }
@Override public void executeCmd() { @Override public void executeCmd() {

@ -40,8 +40,8 @@ final class HighestPriorityCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T>
/** /**
* @param targetName 产生任务的对象名 * @param targetName 产生任务的对象名
*/ */
HighestPriorityCmd(String targetName, T entity) { HighestPriorityCmd(String targetName, T entity, int taskType) {
super(targetName, entity); super(targetName, entity, taskType);
} }
@Override public void executeCmd() { @Override public void executeCmd() {

@ -18,6 +18,7 @@ package com.arialyy.aria.core.command.normal;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.AbsCmdFactory; import com.arialyy.aria.core.command.AbsCmdFactory;
import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
/** /**
@ -81,29 +82,30 @@ public class NormalCmdFactory extends AbsCmdFactory<AbsTaskEntity, AbsNormalCmd>
* @param entity 下载实体 * @param entity 下载实体
* @param type 命令类型{@link #TASK_CREATE}{@link #TASK_START}{@link #TASK_CANCEL}{@link * @param type 命令类型{@link #TASK_CREATE}{@link #TASK_START}{@link #TASK_CANCEL}{@link
* #TASK_STOP}{@link #TASK_HIGHEST_PRIORITY}{@link #TASK_STOP_ALL}{@link #TASK_RESUME_ALL} * #TASK_STOP}{@link #TASK_HIGHEST_PRIORITY}{@link #TASK_STOP_ALL}{@link #TASK_RESUME_ALL}
* @param taskType {@link ICmd#TASK_TYPE_DOWNLOAD}{@link ICmd#TASK_TYPE_DOWNLOAD_GROUP}{@link
* ICmd#TASK_TYPE_UPLOAD}
*/ */
public AbsNormalCmd createCmd(String target, AbsTaskEntity entity, int type) { public AbsNormalCmd createCmd(String target, AbsTaskEntity entity, int type, int taskType) {
switch (type) { switch (type) {
case TASK_CREATE: case TASK_CREATE:
return new AddCmd<>(target, entity); return new AddCmd<>(target, entity, taskType);
case TASK_RESUME: case TASK_RESUME:
case TASK_START: case TASK_START:
return new StartCmd<>(target, entity); return new StartCmd<>(target, entity, taskType);
case TASK_CANCEL: case TASK_CANCEL:
return new CancelCmd<>(target, entity); return new CancelCmd<>(target, entity, taskType);
case TASK_STOP: case TASK_STOP:
return new StopCmd<>(target, entity); return new StopCmd<>(target, entity, taskType);
case TASK_HIGHEST_PRIORITY: case TASK_HIGHEST_PRIORITY:
return new HighestPriorityCmd<>(target, entity); return new HighestPriorityCmd<>(target, entity, taskType);
case TASK_STOP_ALL: case TASK_STOP_ALL:
return new StopAllCmd<>(target, entity); return new StopAllCmd<>(target, entity, taskType);
case TASK_RESUME_ALL: case TASK_RESUME_ALL:
return new ResumeAllCmd<>(target, entity); return new ResumeAllCmd<>(target, entity, taskType);
case TASK_CANCEL_ALL: case TASK_CANCEL_ALL:
return new CancelAllCmd<>(target, entity); return new CancelAllCmd<>(target, entity, taskType);
default: default:
return null; return null;
} }
} }
} }

@ -12,6 +12,7 @@ import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.NetUtils; import com.arialyy.aria.util.NetUtils;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -19,13 +20,16 @@ import java.util.List;
* 恢复所有停止的任务 * 恢复所有停止的任务
* 1.如果执行队列没有满则开始下载任务直到执行队列满 * 1.如果执行队列没有满则开始下载任务直到执行队列满
* 2.如果队列执行队列已经满了则将所有任务添加到等待队列中 * 2.如果队列执行队列已经满了则将所有任务添加到等待队列中
* 3.如果队列中只有等待状态的任务如果执行队列没有满则会启动等待状态的任务如果执行队列已经满了则会将所有等待状态的任务加载到缓存队列中
*/ */
final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> { final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
private List<AbsTaskEntity> mWaitList = new ArrayList<>();
/** /**
* @param targetName 产生任务的对象名 * @param targetName 产生任务的对象名
*/ */
ResumeAllCmd(String targetName, T entity) { ResumeAllCmd(String targetName, T entity, int taskType) {
super(targetName, entity); super(targetName, entity, taskType);
} }
@Override public void executeCmd() { @Override public void executeCmd() {
@ -34,53 +38,85 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
return; return;
} }
if (isDownloadCmd) { if (isDownloadCmd) {
resumeDownload(); resumeTask(findTaskData(1));
resumeTask(findTaskData(2));
} else { } else {
resumeUpload(); resumeTask(findTaskData(3));
} }
resumeWaitTask();
} }
/** /**
* 恢复下载包括普通任务和任务组 * 查找数据库中的所有任务数据
*
* @param type {@code 1}单任务下载任务{@code 2}任务组下载任务{@code 3} 单任务上传任务
*/ */
private void resumeDownload() { private List<AbsTaskEntity> findTaskData(int type) {
List<AbsTaskEntity> tempList = new ArrayList<>();
switch (type) {
case 1:
List<DownloadTaskEntity> dTaskEntity = List<DownloadTaskEntity> dTaskEntity =
DbEntity.findDatas(DownloadTaskEntity.class, "isGroupTask=?", "false"); DbEntity.findDatas(DownloadTaskEntity.class, "isGroupTask=?", "false");
if (dTaskEntity != null && !dTaskEntity.isEmpty()) { if (dTaskEntity != null && !dTaskEntity.isEmpty()) {
for (DownloadTaskEntity te : dTaskEntity) { tempList.addAll(dTaskEntity);
if (te == null || te.getEntity() == null) continue;
int state = te.getState();
if (state == IEntity.STATE_STOP || state == IEntity.STATE_OTHER) {
resumeEntity(te);
} }
break;
case 2:
List<DownloadGroupTaskEntity> groupTask =
DbEntity.findAllData(DownloadGroupTaskEntity.class);
if (groupTask != null && !groupTask.isEmpty()) {
tempList.addAll(groupTask);
} }
break;
case 3:
List<UploadTaskEntity> uTaskEntity =
DbEntity.findDatas(UploadTaskEntity.class, "isGroupTask=?", "false");
if (uTaskEntity != null && !uTaskEntity.isEmpty()) {
tempList.addAll(uTaskEntity);
}
break;
}
return tempList;
} }
List<DownloadGroupTaskEntity> groupTask = DbEntity.findAllData(DownloadGroupTaskEntity.class); /**
if (groupTask != null && !groupTask.isEmpty()) { * 恢复任务
for (DownloadGroupTaskEntity te : groupTask) { */
private void resumeTask(List<AbsTaskEntity> taskList) {
if (taskList != null && !taskList.isEmpty()) {
for (AbsTaskEntity te : taskList) {
if (te == null || te.getEntity() == null) continue; if (te == null || te.getEntity() == null) continue;
int state = te.getState(); int state = te.getState();
if (state == IEntity.STATE_STOP || state == IEntity.STATE_OTHER) { if (state == IEntity.STATE_STOP || state == IEntity.STATE_OTHER) {
resumeEntity(te); resumeEntity(te);
} else if (state == IEntity.STATE_WAIT) {
mWaitList.add(te);
} else if (state == IEntity.STATE_RUNNING) {
if (!mQueue.taskIsRunning(te.getEntity().getKey())) {
resumeEntity(te);
}
} }
} }
} }
} }
/** /**
* 恢复上传包括普通任务和任务组 * 处理等待状态的任务
*/ */
private void resumeUpload() { private void resumeWaitTask() {
List<UploadTaskEntity> dTaskEntity = int maxTaskNum;
DbEntity.findDatas(UploadTaskEntity.class, "isGroupTask=?", "false"); AriaManager manager = AriaManager.getInstance(AriaManager.APP);
if (dTaskEntity != null && !dTaskEntity.isEmpty()) { if (isDownloadCmd) {
for (UploadTaskEntity te : dTaskEntity) { maxTaskNum = manager.getDownloadConfig().getMaxTaskNum();
if (te == null || te.getEntity() == null) continue; } else {
int state = te.getState(); maxTaskNum = manager.getUploadConfig().getMaxTaskNum();
if (state == IEntity.STATE_STOP || state == IEntity.STATE_OTHER) {
resumeEntity(te);
} }
if (mWaitList == null || mWaitList.isEmpty()) return;
for (AbsTaskEntity te : mWaitList) {
if (mQueue.getCurrentExePoolNum() < maxTaskNum) {
startTask(createTask(te));
} else {
createTask(te);
} }
} }
} }

@ -20,10 +20,16 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.QueueMod; import com.arialyy.aria.core.common.QueueMod;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity; 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.upload.UploadTaskEntity;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.NetUtils; import com.arialyy.aria.util.NetUtils;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by lyy on 2016/8/22. * Created by lyy on 2016/8/22.
@ -32,8 +38,8 @@ import com.arialyy.aria.util.NetUtils;
*/ */
class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> { class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
StartCmd(String targetName, T entity) { StartCmd(String targetName, T entity, int taskType) {
super(targetName, entity); super(targetName, entity, taskType);
} }
@Override public void executeCmd() { @Override public void executeCmd() {
@ -65,6 +71,9 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
} else if (mod.equals(QueueMod.WAIT.getTag())) { } else if (mod.equals(QueueMod.WAIT.getTag())) {
if (mQueue.getCurrentExePoolNum() < maxTaskNum if (mQueue.getCurrentExePoolNum() < maxTaskNum
|| task.getState() == IEntity.STATE_STOP || task.getState() == IEntity.STATE_STOP
|| task.getState() == IEntity.STATE_FAIL
|| task.getState() == IEntity.STATE_OTHER
|| task.getState() == IEntity.STATE_POST_PRE
|| task.getState() == IEntity.STATE_COMPLETE) { || task.getState() == IEntity.STATE_COMPLETE) {
startTask(); startTask();
} }
@ -74,5 +83,61 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
startTask(); startTask();
} }
} }
if (mQueue.getCurrentCachePoolNum() == 0){
findAllWaitTask();
}
}
/**
* 当缓冲队列为null时查找数据库中所有等待中的任务
*/
private void findAllWaitTask() {
new Thread(new WaitTaskThread()).start();
}
private class WaitTaskThread implements Runnable {
@Override public void run() {
if (isDownloadCmd) {
handleTask(findWaitData(1));
handleTask(findWaitData(2));
} else {
handleTask(findWaitData(3));
}
}
private List<AbsTaskEntity> findWaitData(int type) {
List<AbsTaskEntity> waitList = new ArrayList<>();
switch (type) {
case 1:
List<DownloadTaskEntity> dEntity =
DbEntity.findDatas(DownloadTaskEntity.class, "groupName=? and state=?", "", "3");
if (dEntity != null && !dEntity.isEmpty()) {
waitList.addAll(dEntity);
}
break;
case 2:
List<DownloadGroupTaskEntity> dgEntity =
DbEntity.findDatas(DownloadGroupTaskEntity.class, "state=?", "3");
if (dgEntity != null && !dgEntity.isEmpty()) {
waitList.addAll(dgEntity);
}
break;
case 3:
List<UploadTaskEntity> uEntity =
DbEntity.findDatas(UploadTaskEntity.class, "groupName=? and state=?", "", "3");
if (uEntity != null && !uEntity.isEmpty()) {
waitList.addAll(uEntity);
}
break;
}
return waitList;
}
private void handleTask(List<AbsTaskEntity> waitList) {
for (AbsTaskEntity te : waitList) {
createTask(te);
}
}
} }
} }

@ -10,8 +10,8 @@ final class StopAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
/** /**
* @param targetName 产生任务的对象名 * @param targetName 产生任务的对象名
*/ */
StopAllCmd(String targetName, T entity) { StopAllCmd(String targetName, T entity, int taskType) {
super(targetName, entity); super(targetName, entity, taskType);
} }
@Override public void executeCmd() { @Override public void executeCmd() {

@ -28,8 +28,8 @@ import com.arialyy.aria.core.inf.AbsTaskEntity;
*/ */
class StopCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> { class StopCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
StopCmd(String targetName, T entity) { StopCmd(String targetName, T entity, int taskType) {
super(targetName, entity); super(targetName, entity, taskType);
} }
@Override public void executeCmd() { @Override public void executeCmd() {

@ -59,6 +59,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
private int mFailNum = 0; private int mFailNum = 0;
private String mTaskType; private String mTaskType;
private Timer mFailTimer; private Timer mFailTimer;
private long mLastSaveTime;
protected AbsThreadTask(StateConstance constance, IEventListener listener, protected AbsThreadTask(StateConstance constance, IEventListener listener,
SubThreadConfig<TASK_ENTITY> info) { SubThreadConfig<TASK_ENTITY> info) {
@ -74,6 +75,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
mBufSize = manager.getDownloadConfig().getBuffSize(); mBufSize = manager.getDownloadConfig().getBuffSize();
setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed()); setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed());
mTaskType = getTaskType(); mTaskType = getTaskType();
mLastSaveTime = System.currentTimeMillis();
} }
protected abstract String getTaskType(); protected abstract String getTaskType();
@ -131,6 +133,19 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
mChildCurrentLocation += len; mChildCurrentLocation += len;
STATE.CURRENT_LOCATION += len; STATE.CURRENT_LOCATION += len;
if (System.currentTimeMillis() - mLastSaveTime > 5000) {
mLastSaveTime = System.currentTimeMillis();
new Thread(new Runnable() {
@Override public void run() {
final long currentTemp = mChildCurrentLocation;
try {
writeConfig(false, currentTemp);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
} }
} }

@ -19,6 +19,7 @@ import android.os.Handler;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
@ -28,13 +29,14 @@ import java.lang.ref.WeakReference;
/** /**
* 下载监听类 * 下载监听类
*/ */
class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>> class BaseDListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>, TASK extends AbsTask<TASK_ENTITY>>
implements IDownloadListener { implements IDownloadListener {
protected WeakReference<Handler> outHandler; protected WeakReference<Handler> outHandler;
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度 private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
private long mLastLen = 0; //上一次发送长度 private long mLastLen = 0; //上一次发送长度
private boolean isFirst = true; private boolean isFirst = true;
protected ENTITY mEntity; protected ENTITY mEntity;
protected TASK_ENTITY mTaskEntity;
protected TASK mTask; protected TASK mTask;
private boolean isConvertSpeed = false; private boolean isConvertSpeed = false;
boolean isWait = false; boolean isWait = false;
@ -43,7 +45,8 @@ class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
BaseDListener(TASK task, Handler outHandler) { BaseDListener(TASK task, Handler outHandler) {
this.outHandler = new WeakReference<>(outHandler); this.outHandler = new WeakReference<>(outHandler);
this.mTask = new WeakReference<>(task).get(); this.mTask = new WeakReference<>(task).get();
this.mEntity = this.mTask.getEntity(); this.mEntity = mTask.getTaskEntity().getEntity();
this.mTaskEntity = mTask.getTaskEntity();
final AriaManager manager = AriaManager.getInstance(AriaManager.APP); final AriaManager manager = AriaManager.getInstance(AriaManager.APP);
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed(); isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
mLastLen = mEntity.getCurrentProgress(); mLastLen = mEntity.getCurrentProgress();
@ -85,7 +88,7 @@ class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
} }
handleSpeed(speed); handleSpeed(speed);
sendInState2Target(ISchedulers.RUNNING); sendInState2Target(ISchedulers.RUNNING);
if (System.currentTimeMillis() - mLastSaveTime >= RUN_SAVE_INTERVAL){ if (System.currentTimeMillis() - mLastSaveTime >= RUN_SAVE_INTERVAL) {
saveData(IEntity.STATE_RUNNING, currentLocation); saveData(IEntity.STATE_RUNNING, currentLocation);
mLastSaveTime = System.currentTimeMillis(); mLastSaveTime = System.currentTimeMillis();
} }
@ -141,6 +144,7 @@ class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
private void saveData(int state, long location) { private void saveData(int state, long location) {
mEntity.setComplete(state == IEntity.STATE_COMPLETE); mEntity.setComplete(state == IEntity.STATE_COMPLETE);
mTaskEntity.state = state;
if (state == IEntity.STATE_CANCEL) { if (state == IEntity.STATE_CANCEL) {
mEntity.setState(state); mEntity.setState(state);
mEntity.deleteData(); mEntity.deleteData();
@ -156,5 +160,6 @@ class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
} }
mEntity.update(); mEntity.update();
} }
mTaskEntity.update();
} }
} }

@ -19,7 +19,7 @@ import android.text.TextUtils;
import com.arialyy.aria.core.SubTaskManager; import com.arialyy.aria.core.SubTaskManager;
import com.arialyy.aria.core.inf.AbsDownloadTarget; import com.arialyy.aria.core.inf.AbsDownloadTarget;
import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.BaseGroupTaskEntity; import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.io.File; import java.io.File;
@ -29,7 +29,7 @@ import java.util.List;
/** /**
* Created by Aria.Lao on 2017/7/26. * Created by Aria.Lao on 2017/7/26.
*/ */
abstract class BaseGroupTarget<TARGET extends AbsTarget, TASK_ENTITY extends BaseGroupTaskEntity> abstract class BaseGroupTarget<TARGET extends AbsTarget, TASK_ENTITY extends AbsGroupTaskEntity>
extends AbsDownloadTarget<TARGET, DownloadGroupEntity, TASK_ENTITY> { extends AbsDownloadTarget<TARGET, DownloadGroupEntity, TASK_ENTITY> {
List<String> mUrls = new ArrayList<>(); List<String> mUrls = new ArrayList<>();

@ -24,7 +24,8 @@ import com.arialyy.aria.core.scheduler.ISchedulers;
* Created by Aria.Lao on 2017/7/20. * Created by Aria.Lao on 2017/7/20.
* 任务组下载事件 * 任务组下载事件
*/ */
class DownloadGroupListener extends BaseDListener<DownloadGroupEntity, DownloadGroupTask> class DownloadGroupListener
extends BaseDListener<DownloadGroupEntity, DownloadGroupTaskEntity, DownloadGroupTask>
implements IDownloadGroupListener { implements IDownloadGroupListener {
private final String TAG = "DownloadGroupListener"; private final String TAG = "DownloadGroupListener";
private GroupSendParams<DownloadGroupTask, DownloadEntity> mSeedEntity; private GroupSendParams<DownloadGroupTask, DownloadEntity> mSeedEntity;

@ -19,8 +19,6 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.IUtil;
import com.arialyy.aria.core.download.downloader.AbsGroupUtil;
import com.arialyy.aria.core.download.downloader.DownloadGroupUtil; import com.arialyy.aria.core.download.downloader.DownloadGroupUtil;
import com.arialyy.aria.core.download.downloader.FtpDirDownloadUtil; import com.arialyy.aria.core.download.downloader.FtpDirDownloadUtil;
import com.arialyy.aria.core.inf.AbsGroupTask; import com.arialyy.aria.core.inf.AbsGroupTask;
@ -32,13 +30,12 @@ import com.arialyy.aria.util.CheckUtil;
* Created by AriaL on 2017/6/27. * Created by AriaL on 2017/6/27.
* 任务组任务 * 任务组任务
*/ */
public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity, DownloadGroupEntity> { public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity> {
private final String TAG = "DownloadGroupTask"; private final String TAG = "DownloadGroupTask";
private DownloadGroupListener mListener; private DownloadGroupListener mListener;
private DownloadGroupTask(DownloadGroupTaskEntity taskEntity, Handler outHandler) { private DownloadGroupTask(DownloadGroupTaskEntity taskEntity, Handler outHandler) {
mTaskEntity = taskEntity; mTaskEntity = taskEntity;
mEntity = taskEntity.getEntity();
mOutHandler = outHandler; mOutHandler = outHandler;
mContext = AriaManager.APP; mContext = AriaManager.APP;
mListener = new DownloadGroupListener(this, mOutHandler); mListener = new DownloadGroupListener(this, mOutHandler);
@ -56,6 +53,10 @@ public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity, Dow
return mUtil.isRunning(); return mUtil.isRunning();
} }
public DownloadGroupEntity getEntity() {
return mTaskEntity.getEntity();
}
@Override public void start() { @Override public void start() {
if (mUtil.isRunning()) { if (mUtil.isRunning()) {
Log.d(TAG, "任务正在下载"); Log.d(TAG, "任务正在下载");
@ -66,7 +67,7 @@ public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity, Dow
@Override public void stop() { @Override public void stop() {
if (!mUtil.isRunning()) { if (!mUtil.isRunning()) {
mListener.onStop(mEntity.getCurrentProgress()); mListener.onStop(getCurrentProgress());
} }
mUtil.stop(); mUtil.stop();
} }

@ -15,13 +15,13 @@
*/ */
package com.arialyy.aria.core.download; package com.arialyy.aria.core.download;
import com.arialyy.aria.core.inf.BaseGroupTaskEntity; import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
import com.arialyy.aria.orm.OneToOne; import com.arialyy.aria.orm.OneToOne;
/** /**
* Created by AriaL on 2017/7/1. * Created by AriaL on 2017/7/1.
*/ */
public class DownloadGroupTaskEntity extends BaseGroupTaskEntity<DownloadGroupEntity> { public class DownloadGroupTaskEntity extends AbsGroupTaskEntity<DownloadGroupEntity> {
@OneToOne(table = DownloadGroupEntity.class, key = "groupName") public DownloadGroupEntity entity; @OneToOne(table = DownloadGroupEntity.class, key = "groupName") public DownloadGroupEntity entity;

@ -22,7 +22,7 @@ import com.arialyy.aria.core.inf.IDownloadListener;
* Created by Aria.Lao on 2017/7/20. * Created by Aria.Lao on 2017/7/20.
* 普通任务下载的事件监听器 * 普通任务下载的事件监听器
*/ */
class DownloadListener extends BaseDListener<DownloadEntity, DownloadTask> class DownloadListener extends BaseDListener<DownloadEntity, DownloadTaskEntity, DownloadTask>
implements IDownloadListener { implements IDownloadListener {
DownloadListener(DownloadTask task, Handler outHandler) { DownloadListener(DownloadTask task, Handler outHandler) {
super(task, outHandler); super(task, outHandler);

@ -18,6 +18,7 @@ package com.arialyy.aria.core.download;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.command.normal.CancelAllCmd; import com.arialyy.aria.core.command.normal.CancelAllCmd;
import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.common.ProxyHelper; import com.arialyy.aria.core.common.ProxyHelper;
@ -256,7 +257,8 @@ public class DownloadReceiver extends AbsReceiver {
@Override public void stopAllTask() { @Override public void stopAllTask() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(NormalCmdFactory.getInstance() .setCmd(NormalCmdFactory.getInstance()
.createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_STOP_ALL)) .createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_STOP_ALL,
ICmd.TASK_TYPE_DOWNLOAD))
.exe(); .exe();
} }
@ -268,7 +270,8 @@ public class DownloadReceiver extends AbsReceiver {
public void resumeAllTask() { public void resumeAllTask() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(NormalCmdFactory.getInstance() .setCmd(NormalCmdFactory.getInstance()
.createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_RESUME_ALL)) .createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_RESUME_ALL,
ICmd.TASK_TYPE_DOWNLOAD))
.exe(); .exe();
} }
@ -282,7 +285,7 @@ public class DownloadReceiver extends AbsReceiver {
final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP); final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP);
CancelAllCmd cancelCmd = CancelAllCmd cancelCmd =
(CancelAllCmd) CommonUtil.createNormalCmd(targetName, new DownloadTaskEntity(), (CancelAllCmd) CommonUtil.createNormalCmd(targetName, new DownloadTaskEntity(),
NormalCmdFactory.TASK_CANCEL_ALL); NormalCmdFactory.TASK_CANCEL_ALL, ICmd.TASK_TYPE_DOWNLOAD);
cancelCmd.removeFile = removeFile; cancelCmd.removeFile = removeFile;
ariaManager.setCmd(cancelCmd).exe(); ariaManager.setCmd(cancelCmd).exe();
Set<String> keys = ariaManager.getReceiver().keySet(); Set<String> keys = ariaManager.getReceiver().keySet();

@ -164,7 +164,7 @@ public class DownloadTarget
* 是否在下载 * 是否在下载
*/ */
public boolean isDownloading() { public boolean isDownloading() {
DownloadTask task = DownloadTaskQueue.getInstance().getTask(mEntity); DownloadTask task = DownloadTaskQueue.getInstance().getTask(mEntity.getKey());
return task != null && task.isRunning(); return task != null && task.isRunning();
} }
} }

@ -23,7 +23,6 @@ import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.IUtil; import com.arialyy.aria.core.common.IUtil;
import com.arialyy.aria.core.download.downloader.SimpleDownloadUtil; import com.arialyy.aria.core.download.downloader.SimpleDownloadUtil;
import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.AbsNormalTask;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
import java.io.File; import java.io.File;
@ -31,18 +30,20 @@ import java.io.File;
* Created by lyy on 2016/8/11. * Created by lyy on 2016/8/11.
* 下载任务类 * 下载任务类
*/ */
public class DownloadTask extends AbsNormalTask<DownloadEntity> { public class DownloadTask extends AbsNormalTask<DownloadTaskEntity> {
public static final String TAG = "DownloadTask"; public static final String TAG = "DownloadTask";
private DownloadListener mListener; private DownloadListener mListener;
private DownloadEntity mEntity;
private IUtil mUtil; private IUtil mUtil;
private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) { private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) {
mEntity = taskEntity.getEntity(); mTaskEntity = taskEntity;
mOutHandler = outHandler; mOutHandler = outHandler;
mContext = AriaManager.APP; mContext = AriaManager.APP;
mListener = new DownloadListener(this, mOutHandler); mListener = new DownloadListener(this, mOutHandler);
mUtil = new SimpleDownloadUtil(taskEntity, mListener); mUtil = new SimpleDownloadUtil(taskEntity, mListener);
mEntity = taskEntity.getEntity();
} }
/** /**
@ -58,6 +59,10 @@ public class DownloadTask extends AbsNormalTask<DownloadEntity> {
return mEntity.getDownloadPath(); return mEntity.getDownloadPath();
} }
public DownloadEntity getEntity() {
return mTaskEntity.getEntity();
}
/** /**
* 获取当前下载任务的下载地址 * 获取当前下载任务的下载地址
* *

@ -15,6 +15,7 @@
*/ */
package com.arialyy.aria.core.download; package com.arialyy.aria.core.download;
import com.arialyy.aria.core.inf.AbsNormalTaskEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.orm.Ignore; import com.arialyy.aria.orm.Ignore;
import com.arialyy.aria.orm.OneToOne; import com.arialyy.aria.orm.OneToOne;
@ -23,7 +24,7 @@ import com.arialyy.aria.orm.OneToOne;
* Created by lyy on 2017/1/23. * Created by lyy on 2017/1/23.
* 下载任务实体 * 下载任务实体
*/ */
public class DownloadTaskEntity extends AbsTaskEntity<DownloadEntity> { public class DownloadTaskEntity extends AbsNormalTaskEntity<DownloadEntity> {
@OneToOne(table = DownloadEntity.class, key = "downloadPath") public DownloadEntity entity; @OneToOne(table = DownloadEntity.class, key = "downloadPath") public DownloadEntity entity;

@ -97,8 +97,8 @@ public abstract class AbsDownloadTarget<TARGET extends AbsTarget, ENTITY extends
*/ */
protected void setHighestPriority() { protected void setHighestPriority() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd( .setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity,
CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_HIGHEST_PRIORITY)) NormalCmdFactory.TASK_HIGHEST_PRIORITY, checkTaskType()))
.exe(); .exe();
} }
@ -136,7 +136,8 @@ public abstract class AbsDownloadTarget<TARGET extends AbsTarget, ENTITY extends
*/ */
public void add() { public void add() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CREATE)) .setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CREATE,
checkTaskType()))
.exe(); .exe();
} }

@ -21,15 +21,13 @@ import com.arialyy.aria.core.download.downloader.AbsGroupUtil;
* Created by AriaL on 2017/6/29. * Created by AriaL on 2017/6/29.
* 任务组任务抽象类 * 任务组任务抽象类
*/ */
public abstract class AbsGroupTask<TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsGroupEntity> public abstract class AbsGroupTask<TASK_ENTITY extends AbsGroupTaskEntity>
extends AbsTask<ENTITY> { extends AbsTask<TASK_ENTITY> {
protected TASK_ENTITY mTaskEntity;
protected AbsGroupUtil mUtil; protected AbsGroupUtil mUtil;
@Override public String getKey() { @Override public String getKey() {
return mEntity.getGroupName(); return mTaskEntity.getEntity().getGroupName();
} }
/** /**

@ -19,7 +19,7 @@ package com.arialyy.aria.core.inf;
/** /**
* Created by lyy on 2017/9/5. * Created by lyy on 2017/9/5.
*/ */
public abstract class BaseGroupTaskEntity<ENTITY extends AbsGroupEntity> extends AbsTaskEntity<ENTITY>{ public abstract class AbsGroupTaskEntity<ENTITY extends AbsGroupEntity> extends AbsTaskEntity<ENTITY>{
@Override public ENTITY getEntity() { @Override public ENTITY getEntity() {
return null; return null;
} }

@ -18,7 +18,8 @@ package com.arialyy.aria.core.inf;
/** /**
* Created by lyy on 2017/6/3. * Created by lyy on 2017/6/3.
*/ */
public abstract class AbsNormalTask<ENTITY extends AbsEntity> extends AbsTask<ENTITY> { public abstract class AbsNormalTask<TASK_ENTITY extends AbsNormalTaskEntity>
extends AbsTask<TASK_ENTITY> {
/** /**
* 暂停任务并让任务处于等待状态 * 暂停任务并让任务处于等待状态
@ -39,6 +40,4 @@ public abstract class AbsNormalTask<ENTITY extends AbsEntity> extends AbsTask<EN
public void setHighestPriority(boolean isHighestPriority) { public void setHighestPriority(boolean isHighestPriority) {
isHeighestTask = isHighestPriority; isHeighestTask = isHighestPriority;
} }
} }

@ -0,0 +1,23 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.inf;
/**
* Created by Aria.Lao on 2017/10/12.
* 当任务实体
*/
public abstract class AbsNormalTaskEntity<ENTITY extends AbsEntity> extends AbsTaskEntity<ENTITY> {
}

@ -23,6 +23,9 @@ import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.command.normal.CancelCmd; import com.arialyy.aria.core.command.normal.CancelCmd;
import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -165,10 +168,23 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
*/ */
@Override public void start() { @Override public void start() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START)) .setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START,
checkTaskType()))
.exe(); .exe();
} }
protected int checkTaskType() {
int taskType = 0;
if (mTaskEntity instanceof DownloadTaskEntity) {
taskType = ICmd.TASK_TYPE_DOWNLOAD;
} else if (mTaskEntity instanceof DownloadGroupTaskEntity) {
taskType = ICmd.TASK_TYPE_DOWNLOAD_GROUP;
} else if (mTaskEntity instanceof UploadTaskEntity) {
taskType = ICmd.TASK_TYPE_UPLOAD;
}
return taskType;
}
/** /**
* 停止任务 * 停止任务
* *
@ -180,7 +196,8 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
@Override public void stop() { @Override public void stop() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_STOP)) .setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_STOP,
checkTaskType()))
.exe(); .exe();
} }
@ -189,7 +206,8 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
*/ */
@Override public void resume() { @Override public void resume() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START)) .setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START,
checkTaskType()))
.exe(); .exe();
} }
@ -198,7 +216,8 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
*/ */
@Override public void cancel() { @Override public void cancel() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CANCEL)) .setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CANCEL,
checkTaskType()))
.exe(); .exe();
} }
@ -207,8 +226,11 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
*/ */
public void reTry() { public void reTry() {
List<ICmd> cmds = new ArrayList<>(); List<ICmd> cmds = new ArrayList<>();
cmds.add(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_STOP)); int taskType = checkTaskType();
cmds.add(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START)); cmds.add(
CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_STOP, taskType));
cmds.add(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START,
taskType));
AriaManager.getInstance(AriaManager.APP).setCmds(cmds).exe(); AriaManager.getInstance(AriaManager.APP).setCmds(cmds).exe();
} }
@ -220,7 +242,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
*/ */
public void cancel(boolean removeFile) { public void cancel(boolean removeFile) {
CancelCmd cancelCmd = (CancelCmd) CommonUtil.createNormalCmd(mTargetName, mTaskEntity, CancelCmd cancelCmd = (CancelCmd) CommonUtil.createNormalCmd(mTargetName, mTaskEntity,
NormalCmdFactory.TASK_CANCEL); NormalCmdFactory.TASK_CANCEL, checkTaskType());
cancelCmd.removeFile = removeFile; cancelCmd.removeFile = removeFile;
AriaManager.getInstance(AriaManager.APP).setCmd(cancelCmd).exe(); AriaManager.getInstance(AriaManager.APP).setCmd(cancelCmd).exe();
} }

@ -22,13 +22,13 @@ import com.arialyy.aria.util.CommonUtil;
/** /**
* Created by AriaL on 2017/6/29. * Created by AriaL on 2017/6/29.
*/ */
public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY> { public abstract class AbsTask<TASK_ENTITY extends AbsTaskEntity> implements ITask<TASK_ENTITY> {
/** /**
* 是否需要重试默认为true * 是否需要重试默认为true
*/ */
public boolean needRetry = true; public boolean needRetry = true;
protected ENTITY mEntity; protected TASK_ENTITY mTaskEntity;
protected Handler mOutHandler; protected Handler mOutHandler;
/** /**
@ -44,14 +44,14 @@ public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY>
* @return {@code true} 已经完成{@code false} 未完成 * @return {@code true} 已经完成{@code false} 未完成
*/ */
public boolean isComplete() { public boolean isComplete() {
return mEntity.isComplete(); return mTaskEntity.getEntity().isComplete();
} }
/** /**
* 获取当前下载进度 * 获取当前下载进度
*/ */
@Override public long getCurrentProgress() { @Override public long getCurrentProgress() {
return mEntity.getCurrentProgress(); return mTaskEntity.getEntity().getCurrentProgress();
} }
/** /**
@ -60,10 +60,10 @@ public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY>
* @return 已经下载3mb的大小则返回{@code 3mb} * @return 已经下载3mb的大小则返回{@code 3mb}
*/ */
@Override public String getConvertCurrentProgress() { @Override public String getConvertCurrentProgress() {
if (mEntity.getCurrentProgress() == 0) { if (mTaskEntity.getEntity().getCurrentProgress() == 0) {
return "0b"; return "0b";
} }
return CommonUtil.formatFileSize(mEntity.getCurrentProgress()); return CommonUtil.formatFileSize(mTaskEntity.getEntity().getCurrentProgress());
} }
/** /**
@ -72,17 +72,17 @@ public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY>
* @return 如果文件长度为0则返回0m否则返回转换后的长度1b1kb1mb1gb1tb * @return 如果文件长度为0则返回0m否则返回转换后的长度1b1kb1mb1gb1tb
*/ */
@Override public String getConvertFileSize() { @Override public String getConvertFileSize() {
if (mEntity.getFileSize() == 0) { if (mTaskEntity.getEntity().getFileSize() == 0) {
return "0mb"; return "0mb";
} }
return CommonUtil.formatFileSize(mEntity.getFileSize()); return CommonUtil.formatFileSize(mTaskEntity.getEntity().getFileSize());
} }
/** /**
* 获取文件大小 * 获取文件大小
*/ */
@Override public long getFileSize() { @Override public long getFileSize() {
return mEntity.getFileSize(); return mTaskEntity.getEntity().getFileSize();
} }
/** /**
@ -91,10 +91,11 @@ public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY>
* @return 返回百分比进度如果文件长度为0返回0 * @return 返回百分比进度如果文件长度为0返回0
*/ */
@Override public int getPercent() { @Override public int getPercent() {
if (mEntity.getFileSize() == 0) { if (mTaskEntity.getEntity().getFileSize() == 0) {
return 0; return 0;
} }
return (int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize()); return (int) (mTaskEntity.getEntity().getCurrentProgress() * 100 / mTaskEntity.getEntity()
.getFileSize());
} }
/** /**
@ -103,7 +104,8 @@ public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY>
* @return {@link IEntity} * @return {@link IEntity}
*/ */
public int getState() { public int getState() {
return mEntity == null ? IEntity.STATE_OTHER : mEntity.getState(); return mTaskEntity.getEntity() == null ? IEntity.STATE_OTHER
: mTaskEntity.getEntity().getState();
} }
/** /**
@ -112,7 +114,7 @@ public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY>
* @return 如果实体不存在则返回null否则返回扩展字段 * @return 如果实体不存在则返回null否则返回扩展字段
*/ */
@Override public String getExtendField() { @Override public String getExtendField() {
return mEntity == null ? null : mEntity.getStr(); return mTaskEntity.getEntity() == null ? null : mTaskEntity.getEntity().getStr();
} }
/** /**
@ -133,7 +135,7 @@ public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY>
* 才能生效 * 才能生效
*/ */
@Override public long getSpeed() { @Override public long getSpeed() {
return mEntity.getSpeed(); return mTaskEntity.getEntity().getSpeed();
} }
/** /**
@ -154,11 +156,11 @@ public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY>
* 才能生效 * 才能生效
*/ */
@Override public String getConvertSpeed() { @Override public String getConvertSpeed() {
return mEntity.getConvertSpeed(); return mTaskEntity.getEntity().getConvertSpeed();
} }
@Override public ENTITY getEntity() { @Override public TASK_ENTITY getTaskEntity() {
return mEntity; return mTaskEntity;
} }
public String getTargetName() { public String getTargetName() {

@ -24,6 +24,7 @@ import java.util.Map;
/** /**
* Created by lyy on 2017/2/23. * Created by lyy on 2017/2/23.
* 所有任务实体的父类
*/ */
public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity { public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
/** /**
@ -60,6 +61,11 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
*/ */
@Ignore public boolean isNewTask = false; @Ignore public boolean isNewTask = false;
/**
* 任务状态和Entity的state同步
*/
public int state = IEntity.STATE_WAIT;
/** /**
* 请求类型 * 请求类型
* {@link AbsTaskEntity#HTTP}{@link AbsTaskEntity#FTP} * {@link AbsTaskEntity#HTTP}{@link AbsTaskEntity#FTP}

@ -76,7 +76,7 @@ public abstract class AbsUploadTarget<TARGET extends AbsUploadTarget, ENTITY ext
* 是否在下载 * 是否在下载
*/ */
public boolean isUploading() { public boolean isUploading() {
UploadTask task = UploadTaskQueue.getInstance().getTask(mEntity); UploadTask task = UploadTaskQueue.getInstance().getTask(mEntity.getKey());
return task != null && task.isRunning(); return task != null && task.isRunning();
} }
} }

@ -18,7 +18,7 @@ package com.arialyy.aria.core.inf;
/** /**
* Created by lyy on 2017/2/13. * Created by lyy on 2017/2/13.
*/ */
public interface ITask<ENTITY extends AbsEntity> { public interface ITask<TASK_ENTITY extends AbsTaskEntity> {
/** /**
* 获取下载状态 * 获取下载状态
@ -45,7 +45,7 @@ public interface ITask<ENTITY extends AbsEntity> {
/** /**
* 获取信息实体 * 获取信息实体
*/ */
ENTITY getEntity(); TASK_ENTITY getTaskEntity();
void start(); void start();
@ -91,5 +91,4 @@ public interface ITask<ENTITY extends AbsEntity> {
String getConvertCurrentProgress(); String getConvertCurrentProgress();
void setTargetName(String targetName); void setTargetName(String targetName);
} }

@ -18,7 +18,6 @@ package com.arialyy.aria.core.queue;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
@ -30,8 +29,8 @@ import com.arialyy.aria.util.NetUtils;
* Created by lyy on 2017/2/23. * Created by lyy on 2017/2/23.
* 任务队列 * 任务队列
*/ */
abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsEntity> abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity>
implements ITaskQueue<TASK, TASK_ENTITY, ENTITY> { implements ITaskQueue<TASK, TASK_ENTITY> {
private final String TAG = "AbsTaskQueue"; private final String TAG = "AbsTaskQueue";
BaseCachePool<TASK> mCachePool; BaseCachePool<TASK> mCachePool;
BaseExecutePool<TASK> mExecutePool; BaseExecutePool<TASK> mExecutePool;
@ -74,11 +73,6 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum(); return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
} }
/**
* 获取实体的索引
*/
public abstract String getKey(ENTITY entity);
/** /**
* 获取配置文件配置的最大可执行任务数 * 获取配置文件配置的最大可执行任务数
*/ */
@ -154,7 +148,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
@Override public void startTask(TASK task) { @Override public void startTask(TASK task) {
if (mExecutePool.putTask(task)) { if (mExecutePool.putTask(task)) {
mCachePool.removeTask(task); mCachePool.removeTask(task);
task.getEntity().setFailNum(0); task.getTaskEntity().getEntity().setFailNum(0);
task.start(); task.start();
} }
} }
@ -169,12 +163,12 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
} }
} }
@Override public void removeTask(ENTITY entity) { @Override public void removeTaskFormQueue(String key) {
TASK task = mExecutePool.getTask(getKey(entity)); TASK task = mExecutePool.getTask(key);
if (task != null) { if (task != null) {
Log.d(TAG, "从执行池删除任务,删除" + (mExecutePool.removeTask(task) ? "成功" : "失败")); Log.d(TAG, "从执行池删除任务,删除" + (mExecutePool.removeTask(task) ? "成功" : "失败"));
} }
task = mCachePool.getTask(getKey(entity)); task = mCachePool.getTask(key);
if (task != null) { if (task != null) {
Log.d(TAG, "从缓存池删除任务,删除" + (mCachePool.removeTask(task) ? "成功" : "失败")); Log.d(TAG, "从缓存池删除任务,删除" + (mCachePool.removeTask(task) ? "成功" : "失败"));
} }
@ -185,7 +179,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
Log.w(TAG, "重试失败,task 为null"); Log.w(TAG, "重试失败,task 为null");
return; return;
} }
if (!NetUtils.isConnected(AriaManager.APP)){ if (!NetUtils.isConnected(AriaManager.APP)) {
Log.w(TAG, "重试失败,网络未连接"); Log.w(TAG, "重试失败,网络未连接");
return; return;
} }
@ -196,11 +190,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
} }
} }
@Override public TASK getTask(ENTITY entity) { @Override public void cancelTask(TASK task) {
return getTask(getKey(entity));
}
@Override public void removeTask(TASK task) {
task.cancel(); task.cancel();
} }

@ -32,7 +32,7 @@ import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
* 任务组下载队列 * 任务组下载队列
*/ */
public class DownloadGroupTaskQueue public class DownloadGroupTaskQueue
extends AbsTaskQueue<DownloadGroupTask, DownloadGroupTaskEntity, DownloadGroupEntity> { extends AbsTaskQueue<DownloadGroupTask, DownloadGroupTaskEntity> {
private static volatile DownloadGroupTaskQueue INSTANCE = null; private static volatile DownloadGroupTaskQueue INSTANCE = null;
private final String TAG = "DownloadGroupTaskQueue"; private final String TAG = "DownloadGroupTaskQueue";
@ -70,10 +70,6 @@ public class DownloadGroupTaskQueue
return task; return task;
} }
@Override public String getKey(DownloadGroupEntity entity) {
return entity.getGroupName();
}
@Override public int getConfigMaxNum() { @Override public int getConfigMaxNum() {
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum; return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum;
} }

@ -35,7 +35,7 @@ import java.util.Set;
* 下载任务队列 * 下载任务队列
*/ */
public class DownloadTaskQueue public class DownloadTaskQueue
extends AbsTaskQueue<DownloadTask, DownloadTaskEntity, DownloadEntity> { extends AbsTaskQueue<DownloadTask, DownloadTaskEntity> {
private static final String TAG = "DownloadTaskQueue"; private static final String TAG = "DownloadTaskQueue";
private static volatile DownloadTaskQueue INSTANCE = null; private static volatile DownloadTaskQueue INSTANCE = null;
@ -59,10 +59,6 @@ public class DownloadTaskQueue
return DownloadSharePool.getInstance().executePool; return DownloadSharePool.getInstance().executePool;
} }
@Override public String getKey(DownloadEntity entity) {
return entity.getUrl();
}
@Override public int getConfigMaxNum() { @Override public int getConfigMaxNum() {
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum; return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum;
} }

@ -16,15 +16,11 @@
package com.arialyy.aria.core.queue; package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsNormalTask;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTask; import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.core.upload.UploadTaskEntity;
@ -32,7 +28,7 @@ import com.arialyy.aria.core.upload.UploadTaskEntity;
* Created by lyy on 2016/8/16. * Created by lyy on 2016/8/16.
* 任务功能接口 * 任务功能接口
*/ */
public interface ITaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsEntity> { public interface ITaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity> {
/** /**
* 通过key判断任务是否正在执行 * 通过key判断任务是否正在执行
@ -67,18 +63,18 @@ public interface ITaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
void stopTask(TASK task); void stopTask(TASK task);
/** /**
* 通过任务任务实体删除任务 * 取消下载任务
* *
* @param task {@link DownloadTask}{@link UploadTask} * @param task {@link DownloadTask}{@link UploadTask}
*/ */
void removeTask(TASK task); void cancelTask(TASK task);
/** /**
* 通过工作实体删除任务 * 通过key从队列中删除任务
* *
* @param entity 工作实体{@link DownloadEntity}{@link UploadEntity} * @param key 如果是下载则为下载链接如果是上传为文件保存路径如果是下载任务组则为任务组名
*/ */
void removeTask(ENTITY entity); void removeTaskFormQueue(String key);
/** /**
* 重试下载 * 重试下载
@ -121,18 +117,10 @@ public interface ITaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
/** /**
* 通过工作实体缓存池或任务池搜索下载任务如果缓存池或任务池都没有任务则创建新任务 * 通过工作实体缓存池或任务池搜索下载任务如果缓存池或任务池都没有任务则创建新任务
* *
* @param entity 工作实体{@link DownloadEntity}{@link UploadEntity} * @param key 如果是下载则为下载链接如果是上传为文件保存路径如果是下载任务组则为任务组名
* @return {@link DownloadTask}{@link UploadTask} * @return {@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}
*/
TASK getTask(ENTITY entity);
/**
* 通过工作实体缓存池或任务池搜索下载任务如果缓存池或任务池都没有任务则创建新任务
*
* @param url 链接地址如果是下载则为下载链接如果是上传为文件保存路径
* @return {@link DownloadTask}{@link UploadTask}
*/ */
TASK getTask(String url); TASK getTask(String key);
/** /**
* 获取缓存池的下一个任务 * 获取缓存池的下一个任务

@ -90,7 +90,8 @@ public class QueueControl implements Handler.Callback {
@Override public boolean handleMessage(Message msg) { @Override public boolean handleMessage(Message msg) {
switch (msg.what) { switch (msg.what) {
case CMD_GET_TASK: case CMD_GET_TASK:
outHandler.obtainMessage(CMD_GET_TASK, queue.getTask((AbsEntity) msg.obj)).sendToTarget(); outHandler.obtainMessage(CMD_GET_TASK, queue.getTask(((AbsEntity) msg.obj).getKey()))
.sendToTarget();
break; break;
case CMD_CREATE_TASK: case CMD_CREATE_TASK:
SparseArray params = (SparseArray) msg.obj; SparseArray params = (SparseArray) msg.obj;
@ -105,7 +106,7 @@ public class QueueControl implements Handler.Callback {
queue.stopTask((AbsTask) msg.obj); queue.stopTask((AbsTask) msg.obj);
break; break;
case CMD_CANCEL_TASK: case CMD_CANCEL_TASK:
queue.removeTask((AbsTask) msg.obj); queue.cancelTask((AbsTask) msg.obj);
break; break;
case CMD_STOP_ALL_TASK: case CMD_STOP_ALL_TASK:
queue.stopAllTask(); queue.stopAllTask();

@ -31,7 +31,7 @@ import com.arialyy.aria.core.upload.UploadTaskEntity;
* Created by lyy on 2017/2/27. * Created by lyy on 2017/2/27.
* 上传任务队列 * 上传任务队列
*/ */
public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity, UploadEntity> { public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity> {
private static final String TAG = "UploadTaskQueue"; private static final String TAG = "UploadTaskQueue";
private static volatile UploadTaskQueue INSTANCE = null; private static volatile UploadTaskQueue INSTANCE = null;
@ -55,10 +55,6 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity,
return UploadSharePool.getInstance().executePool; return UploadSharePool.getInstance().executePool;
} }
@Override public String getKey(UploadEntity entity) {
return entity.getFilePath();
}
@Override public int getConfigMaxNum() { @Override public int getConfigMaxNum() {
return AriaManager.getInstance(AriaManager.APP).getUploadConfig().oldMaxTaskNum; return AriaManager.getInstance(AriaManager.APP).getUploadConfig().oldMaxTaskNum;
} }

@ -159,14 +159,13 @@ public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
} }
} }
@Override public TASK getTask(String downloadUrl) { @Override public TASK getTask(String key) {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
if (TextUtils.isEmpty(downloadUrl)) { if (TextUtils.isEmpty(key)) {
Log.e(TAG, "请传入有效的任务key"); Log.e(TAG, "请传入有效的任务key");
return null; return null;
} }
String key = CommonUtil.keyToHashKey(downloadUrl); return mExecuteMap.get(CommonUtil.keyToHashKey(key));
return mExecuteMap.get(key);
} }
} }

@ -37,7 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
* Created by lyy on 2017/6/4. * Created by lyy on 2017/6/4.
* 事件调度器用于处理任务状态的调度 * 事件调度器用于处理任务状态的调度
*/ */
abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>, QUEUE extends ITaskQueue<TASK, TASK_ENTITY, ENTITY>> abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends AbsTask<TASK_ENTITY>, QUEUE extends ITaskQueue<TASK, TASK_ENTITY>>
implements ISchedulers<TASK> { implements ISchedulers<TASK> {
private final String TAG = "AbsSchedulers"; private final String TAG = "AbsSchedulers";
@ -148,15 +148,13 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
* 处理普通任务事件 * 处理普通任务事件
*/ */
private void handleNormalEvent(TASK task, int what) { private void handleNormalEvent(TASK task, int what) {
ENTITY entity = task.getEntity();
switch (what) { switch (what) {
case STOP: case STOP:
if (task.getEntity().getState() == IEntity.STATE_WAIT) { if (task.getState() == IEntity.STATE_WAIT) {
break; break;
} }
startNextTask();
case CANCEL: case CANCEL:
mQueue.removeTask(entity); mQueue.removeTaskFormQueue(task.getKey());
if (mQueue.getCurrentExePoolNum() < AriaManager.getInstance(AriaManager.APP) if (mQueue.getCurrentExePoolNum() < AriaManager.getInstance(AriaManager.APP)
.getUploadConfig() .getUploadConfig()
.getMaxTaskNum()) { .getMaxTaskNum()) {
@ -164,7 +162,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
} }
break; break;
case COMPLETE: case COMPLETE:
mQueue.removeTask(entity); mQueue.removeTaskFormQueue(task.getKey());
startNextTask(); startNextTask();
break; break;
case FAIL: case FAIL:
@ -237,7 +235,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
*/ */
private void handleFailTask(final TASK task) { private void handleFailTask(final TASK task) {
if (!task.needRetry) { if (!task.needRetry) {
mQueue.removeTask(task.getEntity()); mQueue.removeTaskFormQueue(task.getKey());
startNextTask(); startNextTask();
return; return;
} }
@ -258,12 +256,12 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
} }
@Override public void onFinish() { @Override public void onFinish() {
ENTITY entity = task.getEntity(); AbsEntity entity = task.getTaskEntity().getEntity();
if (entity.getFailNum() < reTryNum) { if (entity.getFailNum() < reTryNum) {
TASK task = mQueue.getTask(entity); TASK task = mQueue.getTask(entity.getKey());
mQueue.reTryStart(task); mQueue.reTryStart(task);
} else { } else {
mQueue.removeTask(entity); mQueue.removeTaskFormQueue(task.getKey());
startNextTask(); startNextTask();
} }
} }
@ -280,7 +278,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
Log.w(TAG, "没有下一任务"); Log.w(TAG, "没有下一任务");
return; return;
} }
if (newTask.getEntity().getState() == IEntity.STATE_WAIT) { if (newTask.getState() == IEntity.STATE_WAIT) {
mQueue.startTask(newTask); mQueue.startTask(newTask);
} }
} }

@ -26,7 +26,7 @@ import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
* 任务组调度器 * 任务组调度器
*/ */
public class DownloadGroupSchedulers extends public class DownloadGroupSchedulers extends
AbsSchedulers<DownloadGroupTaskEntity, DownloadGroupEntity, DownloadGroupTask, DownloadGroupTaskQueue> { AbsSchedulers<DownloadGroupTaskEntity, DownloadGroupTask, DownloadGroupTaskQueue> {
private final String TAG = "DownloadGroupSchedulers"; private final String TAG = "DownloadGroupSchedulers";
private static volatile DownloadGroupSchedulers INSTANCE = null; private static volatile DownloadGroupSchedulers INSTANCE = null;

@ -27,7 +27,7 @@ import com.arialyy.aria.core.download.DownloadTask;
* 任务下载器提供抽象的方法供具体的实现类操作 * 任务下载器提供抽象的方法供具体的实现类操作
*/ */
public class DownloadSchedulers public class DownloadSchedulers
extends AbsSchedulers<DownloadTaskEntity, DownloadEntity, DownloadTask, DownloadTaskQueue> { extends AbsSchedulers<DownloadTaskEntity, DownloadTask, DownloadTaskQueue> {
private final String TAG = "DownloadSchedulers"; private final String TAG = "DownloadSchedulers";
private static volatile DownloadSchedulers INSTANCE = null; private static volatile DownloadSchedulers INSTANCE = null;

@ -17,7 +17,6 @@ package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTask; import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.core.upload.UploadTaskEntity;
@ -25,8 +24,7 @@ import com.arialyy.aria.core.upload.UploadTaskEntity;
* Created by lyy on 2017/2/27. * Created by lyy on 2017/2/27.
* 上传任务调度器 * 上传任务调度器
*/ */
public class UploadSchedulers public class UploadSchedulers extends AbsSchedulers<UploadTaskEntity, UploadTask, UploadTaskQueue> {
extends AbsSchedulers<UploadTaskEntity, UploadEntity, UploadTask, UploadTaskQueue> {
private static final String TAG = "UploadSchedulers"; private static final String TAG = "UploadSchedulers";
private static volatile UploadSchedulers INSTANCE = null; private static volatile UploadSchedulers INSTANCE = null;

@ -19,6 +19,7 @@ import android.os.Handler;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask; 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.inf.IEntity;
import com.arialyy.aria.core.inf.IUploadListener; import com.arialyy.aria.core.inf.IUploadListener;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
@ -28,13 +29,14 @@ import java.lang.ref.WeakReference;
/** /**
* 下载监听类 * 下载监听类
*/ */
class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>> class BaseUListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>, TASK extends AbsTask<TASK_ENTITY>>
implements IUploadListener { implements IUploadListener {
private WeakReference<Handler> outHandler; private WeakReference<Handler> outHandler;
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度 private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
private long mLastLen = 0; //上一次发送长度 private long mLastLen = 0; //上一次发送长度
private boolean isFirst = true; private boolean isFirst = true;
protected ENTITY mEntity; protected ENTITY mEntity;
protected TASK_ENTITY mTaskEntity;
protected TASK mTask; protected TASK mTask;
private boolean isConvertSpeed = false; private boolean isConvertSpeed = false;
boolean isWait = false; boolean isWait = false;
@ -43,7 +45,8 @@ class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
BaseUListener(TASK task, Handler outHandler) { BaseUListener(TASK task, Handler outHandler) {
this.outHandler = new WeakReference<>(outHandler); this.outHandler = new WeakReference<>(outHandler);
this.mTask = new WeakReference<>(task).get(); this.mTask = new WeakReference<>(task).get();
this.mEntity = this.mTask.getEntity(); this.mEntity = this.mTask.getTaskEntity().getEntity();
this.mTaskEntity = this.mTask.getTaskEntity();
final AriaManager manager = AriaManager.getInstance(AriaManager.APP); final AriaManager manager = AriaManager.getInstance(AriaManager.APP);
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed(); isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
mLastLen = mEntity.getCurrentProgress(); mLastLen = mEntity.getCurrentProgress();
@ -129,6 +132,7 @@ class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
private void saveData(int state, long location) { private void saveData(int state, long location) {
mEntity.setComplete(state == IEntity.STATE_COMPLETE); mEntity.setComplete(state == IEntity.STATE_COMPLETE);
mTaskEntity.state = state;
if (state == IEntity.STATE_CANCEL) { if (state == IEntity.STATE_CANCEL) {
mEntity.deleteData(); mEntity.deleteData();
} else if (state == IEntity.STATE_COMPLETE) { } else if (state == IEntity.STATE_COMPLETE) {
@ -143,5 +147,6 @@ class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
} }
mEntity.update(); mEntity.update();
} }
mTaskEntity.update();
} }
} }

@ -17,6 +17,7 @@ package com.arialyy.aria.core.upload;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.common.ProxyHelper; import com.arialyy.aria.core.common.ProxyHelper;
import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
@ -79,7 +80,7 @@ public class UploadReceiver extends AbsReceiver<UploadEntity> {
@Override public void stopAllTask() { @Override public void stopAllTask() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(NormalCmdFactory.getInstance() .setCmd(NormalCmdFactory.getInstance()
.createCmd(targetName, new UploadTaskEntity(), NormalCmdFactory.TASK_STOP_ALL)) .createCmd(targetName, new UploadTaskEntity(), NormalCmdFactory.TASK_STOP_ALL, ICmd.TASK_TYPE_UPLOAD))
.exe(); .exe();
} }
@ -93,7 +94,7 @@ public class UploadReceiver extends AbsReceiver<UploadEntity> {
final AriaManager am = AriaManager.getInstance(AriaManager.APP); final AriaManager am = AriaManager.getInstance(AriaManager.APP);
am.setCmd(CommonUtil.createNormalCmd(targetName, new DownloadTaskEntity(), am.setCmd(CommonUtil.createNormalCmd(targetName, new DownloadTaskEntity(),
NormalCmdFactory.TASK_CANCEL_ALL)).exe(); NormalCmdFactory.TASK_CANCEL_ALL, ICmd.TASK_TYPE_UPLOAD)).exe();
Set<String> keys = am.getReceiver().keySet(); Set<String> keys = am.getReceiver().keySet();
for (String key : keys) { for (String key : keys) {

@ -33,7 +33,7 @@ import java.util.Map;
class DBConfig { class DBConfig {
static Map<String, Class> mapping = new HashMap<>(); static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME; static String DB_NAME;
static int VERSION = 15; static int VERSION = 16;
static { static {
if (TextUtils.isEmpty(DB_NAME)) { if (TextUtils.isEmpty(DB_NAME)) {

@ -24,6 +24,7 @@ import android.text.TextUtils;
import android.util.Base64; import android.util.Base64;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.command.group.AbsGroupCmd; import com.arialyy.aria.core.command.group.AbsGroupCmd;
import com.arialyy.aria.core.command.group.GroupCmdFactory; import com.arialyy.aria.core.command.group.GroupCmdFactory;
import com.arialyy.aria.core.command.normal.AbsNormalCmd; import com.arialyy.aria.core.command.normal.AbsNormalCmd;
@ -33,7 +34,7 @@ import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.BaseGroupTaskEntity; import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
@ -437,10 +438,13 @@ public class CommonUtil {
/** /**
* 创建任务命令 * 创建任务命令
*
* @param taskType {@link ICmd#TASK_TYPE_DOWNLOAD}{@link ICmd#TASK_TYPE_DOWNLOAD_GROUP}{@link
* ICmd#TASK_TYPE_UPLOAD}
*/ */
public static <T extends AbsTaskEntity> AbsNormalCmd createNormalCmd(String target, T entity, public static <T extends AbsTaskEntity> AbsNormalCmd createNormalCmd(String target, T entity,
int cmd) { int cmd, int taskType) {
return NormalCmdFactory.getInstance().createCmd(target, entity, cmd); return NormalCmdFactory.getInstance().createCmd(target, entity, cmd, taskType);
} }
/** /**
@ -448,7 +452,7 @@ public class CommonUtil {
* *
* @param childUrl 子任务url * @param childUrl 子任务url
*/ */
public static <T extends BaseGroupTaskEntity> AbsGroupCmd createGroupCmd(String target, T entity, public static <T extends AbsGroupTaskEntity> AbsGroupCmd createGroupCmd(String target, T entity,
int cmd, String childUrl) { int cmd, String childUrl) {
return GroupCmdFactory.getInstance().createCmd(target, entity, cmd, childUrl); return GroupCmdFactory.getInstance().createCmd(target, entity, cmd, childUrl);
} }

@ -1,4 +1,5 @@
## 开发日志 ## 开发日志
+ v_3.3.4 优化任务代码结构,修复上一个版本暂停后无法自动执行任务的问题
+ v_3.3.3 修复进度条错乱的问题,修复同一时间多次调用start导致重复下载的问题 + v_3.3.3 修复进度条错乱的问题,修复同一时间多次调用start导致重复下载的问题
+ v_3.3.2 新加reTry(),修复上一个版本不会回调失败事件的问题;增加running状态下5秒钟保存一次数据库的功能;修复FTP断点上传文件不完整的问题 + v_3.3.2 新加reTry(),修复上一个版本不会回调失败事件的问题;增加running状态下5秒钟保存一次数据库的功能;修复FTP断点上传文件不完整的问题
+ v_3.3.1 增加网络事件,网络未连接,将不会重试下载,修复删除未开始任务,状态回调错误 + v_3.3.1 增加网络事件,网络未连接,将不会重试下载,修复删除未开始任务,状态回调错误

@ -29,8 +29,8 @@ Aria有以下特点:
[![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion)
[![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion)
```java ```java
compile 'com.arialyy.aria:aria-core:3.3.3' compile 'com.arialyy.aria:aria-core:3.3.4'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.3' annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.4'
``` ```
*** ***

@ -8,7 +8,7 @@
<threadNum value="3"/> <threadNum value="3"/>
<!--设置下载队列最大任务数, 默认为2--> <!--设置下载队列最大任务数, 默认为2-->
<maxTaskNum value="2"/> <maxTaskNum value="1"/>
<!--设置下载失败,重试次数,默认为10--> <!--设置下载失败,重试次数,默认为10-->
<reTryNum value="10"/> <reTryNum value="10"/>

@ -18,8 +18,8 @@ package com.arialyy.aria.core.upload;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.AbsNormalTask;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.core.upload.uploader.SimpleUploadUtil; import com.arialyy.aria.core.upload.uploader.SimpleUploadUtil;
@ -27,27 +27,31 @@ import com.arialyy.aria.core.upload.uploader.SimpleUploadUtil;
* Created by lyy on 2017/2/23. * Created by lyy on 2017/2/23.
* 上传任务 * 上传任务
*/ */
public class UploadTask extends AbsNormalTask<UploadEntity> { public class UploadTask extends AbsNormalTask<UploadTaskEntity> {
private static final String TAG = "UploadTask"; private static final String TAG = "UploadTask";
private SimpleUploadUtil mUtil; private SimpleUploadUtil mUtil;
private BaseUListener<UploadEntity, UploadTask> mListener; private BaseUListener<UploadEntity, UploadTaskEntity, UploadTask> mListener;
private UploadTask(UploadTaskEntity taskEntity, Handler outHandler) { private UploadTask(UploadTaskEntity taskEntity, Handler outHandler) {
mTaskEntity = taskEntity;
mOutHandler = outHandler; mOutHandler = outHandler;
mEntity = taskEntity.getEntity();
mListener = new BaseUListener<>(this, mOutHandler); mListener = new BaseUListener<>(this, mOutHandler);
mUtil = new SimpleUploadUtil(taskEntity, mListener); mUtil = new SimpleUploadUtil(taskEntity, mListener);
} }
@Override public String getKey() { @Override public String getKey() {
return mEntity.getFilePath(); return mTaskEntity.getEntity().getFilePath();
} }
@Override public boolean isRunning() { @Override public boolean isRunning() {
return mUtil.isRunning(); return mUtil.isRunning();
} }
public UploadEntity getEntity() {
return mTaskEntity.getEntity();
}
@Override public void start() { @Override public void start() {
if (mUtil.isRunning()) { if (mUtil.isRunning()) {
Log.d(TAG, "任务正在下载"); Log.d(TAG, "任务正在下载");
@ -60,7 +64,7 @@ public class UploadTask extends AbsNormalTask<UploadEntity> {
if (mUtil.isRunning()) { if (mUtil.isRunning()) {
mUtil.stop(); mUtil.stop();
} else { } else {
mListener.onStop(mEntity.getCurrentProgress()); mListener.onStop(getCurrentProgress());
} }
} }

@ -15,7 +15,7 @@
*/ */
package com.arialyy.aria.core.upload; package com.arialyy.aria.core.upload;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsNormalTaskEntity;
import com.arialyy.aria.orm.OneToOne; import com.arialyy.aria.orm.OneToOne;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -24,7 +24,7 @@ import java.util.Map;
* Created by lyy on 2017/2/9. * Created by lyy on 2017/2/9.
* 上传任务实体 * 上传任务实体
*/ */
public class UploadTaskEntity extends AbsTaskEntity<UploadEntity> { public class UploadTaskEntity extends AbsNormalTaskEntity<UploadEntity> {
public String attachment; //文件上传需要的key public String attachment; //文件上传需要的key
public String contentType = "multipart/form-data"; //上传的文件类型 public String contentType = "multipart/form-data"; //上传的文件类型
public String userAgent = "User-Agent"; public String userAgent = "User-Agent";

@ -37,7 +37,7 @@ task clean(type: Delete) {
ext { ext {
userOrg = 'arialyy' userOrg = 'arialyy'
groupId = 'com.arialyy.aria' groupId = 'com.arialyy.aria'
publishVersion = '3.3.3' publishVersion = '3.3.4'
// publishVersion = '1.0.3' //FTP插件 // publishVersion = '1.0.3' //FTP插件
repoName='maven' repoName='maven'
desc = 'android 下载框架' desc = 'android 下载框架'

Loading…
Cancel
Save