Merge branch 'v_3.0'

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

@ -26,6 +26,5 @@ dependencies {
compile 'com.arialyy.aria:aria-ftp-plug:1.0.3'
// compile project(':AriaFtpPlug')
}
apply from: 'bintray-release.gradle'

@ -18,7 +18,7 @@ package com.arialyy.aria.core;
import android.text.TextUtils;
import android.util.Log;
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 java.util.List;
@ -28,10 +28,10 @@ import java.util.List;
*/
public class SubTaskManager {
private String TAG = "SubTaskManager";
private BaseGroupTaskEntity mEntity;
private AbsGroupTaskEntity mEntity;
private String mTargetName;
public SubTaskManager(String targetName, BaseGroupTaskEntity entity) {
public SubTaskManager(String targetName, AbsGroupTaskEntity entity) {
mTargetName = targetName;
mEntity = entity;
}

@ -26,6 +26,8 @@ public abstract class AbsCmdFactory<TASK_ENTITY extends AbsTaskEntity, CMD exten
/**
* @param target 创建任务的对象
* @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 {
/**
* 单任务下载任务
*/
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.download.DownloadGroupTaskEntity;
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.BaseGroupTaskEntity;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.util.CommonUtil;
@ -28,7 +28,7 @@ import com.arialyy.aria.util.CommonUtil;
* 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
*/
@ -60,7 +60,7 @@ public abstract class AbsGroupCmd<T extends BaseGroupTaskEntity> extends AbsCmd<
}
boolean checkTask() {
tempTask = (AbsGroupTask) mQueue.getTask(mTaskEntity.getEntity());
tempTask = (AbsGroupTask) mQueue.getTask(mTaskEntity.getEntity().getKey());
if (tempTask == null) {
createTask();
if (tempTask.isComplete()) {

@ -15,13 +15,13 @@
*/
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.
* 删除任务组
*/
class GroupCancelCmd<T extends BaseGroupTaskEntity> extends AbsGroupCmd<T> {
class GroupCancelCmd<T extends AbsGroupTaskEntity> extends AbsGroupCmd<T> {
/**
* @param targetName 创建任务的对象名
*/

@ -16,7 +16,7 @@
package com.arialyy.aria.core.command.group;
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.
@ -57,7 +57,7 @@ public class GroupCmdFactory {
* @param type 命令类型{@link #SUB_TASK_START}{@link #SUB_TASK_STOP}{@link #SUB_TASK_CANCEL}
* @param childUrl 需要控制的子任务url
*/
public AbsGroupCmd createCmd(String target, BaseGroupTaskEntity entity, int type,
public AbsGroupCmd createCmd(String target, AbsGroupTaskEntity entity, int type,
String childUrl) {
AbsGroupCmd cmd = null;
switch (type) {

@ -15,13 +15,13 @@
*/
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.
* 任务组开始命令该命令负责处理任务组子任务的开始\恢复等工作
*/
class GroupStartCmd<T extends BaseGroupTaskEntity> extends AbsGroupCmd<T> {
class GroupStartCmd<T extends AbsGroupTaskEntity> extends AbsGroupCmd<T> {
/**
* @param targetName 创建任务的对象名
*/

@ -15,13 +15,13 @@
*/
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.
* 停止任务组的命令
*/
class GroupStopCmd<T extends BaseGroupTaskEntity> extends AbsGroupCmd<T> {
class GroupStopCmd<T extends AbsGroupTaskEntity> extends AbsGroupCmd<T> {
/**
* @param targetName 创建任务的对象名
*/

@ -16,7 +16,9 @@
package com.arialyy.aria.core.command.normal;
import android.util.Log;
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.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsEntity;
@ -39,28 +41,44 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
boolean canExeCmd = true;
private AbsTask tempTask = null;
int taskType;
/**
* @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) {
//canExeCmd = CheckUtil.checkCmdEntity(entity,
// !(this instanceof CancelCmd) || !(this instanceof StopCmd));
AbsNormalCmd(String targetName, T entity, int taskType) {
this.taskType = taskType;
mTargetName = targetName;
mTaskEntity = entity;
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();
isDownloadCmd = true;
} else if (entity instanceof UploadTaskEntity) {
mQueue = UploadTaskQueue.getInstance();
isDownloadCmd = false;
} else if (entity instanceof DownloadGroupTaskEntity) {
} else if (taskType == ICmd.TASK_TYPE_DOWNLOAD_GROUP) {
if (!(entity instanceof DownloadGroupTaskEntity)) {
Log.w(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD_GROUP");
return;
}
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() {
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 执行任务
*/
AbsTask getTask() {
tempTask = mQueue.getTask(mTaskEntity.getEntity());
tempTask = mQueue.getTask(mTaskEntity.getEntity().getKey());
return tempTask;
}
@ -123,7 +141,7 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
* @return 执行任务
*/
AbsTask getTask(AbsEntity entity) {
tempTask = mQueue.getTask(entity);
tempTask = mQueue.getTask(entity.getKey());
return tempTask;
}

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

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

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

@ -40,8 +40,8 @@ final class HighestPriorityCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T>
/**
* @param targetName 产生任务的对象名
*/
HighestPriorityCmd(String targetName, T entity) {
super(targetName, entity);
HighestPriorityCmd(String targetName, T entity, int taskType) {
super(targetName, entity, taskType);
}
@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.command.AbsCmdFactory;
import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.inf.AbsTaskEntity;
/**
@ -81,29 +82,30 @@ public class NormalCmdFactory extends AbsCmdFactory<AbsTaskEntity, AbsNormalCmd>
* @param entity 下载实体
* @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}
* @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) {
case TASK_CREATE:
return new AddCmd<>(target, entity);
return new AddCmd<>(target, entity, taskType);
case TASK_RESUME:
case TASK_START:
return new StartCmd<>(target, entity);
return new StartCmd<>(target, entity, taskType);
case TASK_CANCEL:
return new CancelCmd<>(target, entity);
return new CancelCmd<>(target, entity, taskType);
case TASK_STOP:
return new StopCmd<>(target, entity);
return new StopCmd<>(target, entity, taskType);
case TASK_HIGHEST_PRIORITY:
return new HighestPriorityCmd<>(target, entity);
return new HighestPriorityCmd<>(target, entity, taskType);
case TASK_STOP_ALL:
return new StopAllCmd<>(target, entity);
return new StopAllCmd<>(target, entity, taskType);
case TASK_RESUME_ALL:
return new ResumeAllCmd<>(target, entity);
return new ResumeAllCmd<>(target, entity, taskType);
case TASK_CANCEL_ALL:
return new CancelAllCmd<>(target, entity);
return new CancelAllCmd<>(target, entity, taskType);
default:
return null;
}
}
}

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

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

@ -328,9 +328,11 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
//如果有记录,则恢复下载
if (!isNewTask && record != null && Long.parseLong(record + "") >= 0) {
Long r = Long.parseLong(record + "");
mConstance.CURRENT_LOCATION += r - startL;
if (r > startL) {
mConstance.CURRENT_LOCATION += r - startL;
startL = r;
}
Log.d(TAG, "任务【" + mEntity.getFileName() + "】线程__" + i + "__恢复下载");
startL = r;
recordL[rl] = i;
rl++;
} else {

@ -59,6 +59,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
private int mFailNum = 0;
private String mTaskType;
private Timer mFailTimer;
private long mLastSaveTime;
protected AbsThreadTask(StateConstance constance, IEventListener listener,
SubThreadConfig<TASK_ENTITY> info) {
@ -74,6 +75,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
mBufSize = manager.getDownloadConfig().getBuffSize();
setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed());
mTaskType = getTaskType();
mLastSaveTime = System.currentTimeMillis();
}
protected abstract String getTaskType();
@ -131,6 +133,19 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
synchronized (AriaManager.LOCK) {
mChildCurrentLocation += 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.inf.AbsEntity;
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.IEntity;
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 {
protected WeakReference<Handler> outHandler;
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
private long mLastLen = 0; //上一次发送长度
private boolean isFirst = true;
protected ENTITY mEntity;
protected TASK_ENTITY mTaskEntity;
protected TASK mTask;
private boolean isConvertSpeed = false;
boolean isWait = false;
@ -43,7 +45,8 @@ class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
BaseDListener(TASK task, Handler outHandler) {
this.outHandler = new WeakReference<>(outHandler);
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);
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
mLastLen = mEntity.getCurrentProgress();
@ -85,7 +88,7 @@ class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
}
handleSpeed(speed);
sendInState2Target(ISchedulers.RUNNING);
if (System.currentTimeMillis() - mLastSaveTime >= RUN_SAVE_INTERVAL){
if (System.currentTimeMillis() - mLastSaveTime >= RUN_SAVE_INTERVAL) {
saveData(IEntity.STATE_RUNNING, currentLocation);
mLastSaveTime = System.currentTimeMillis();
}
@ -141,6 +144,7 @@ class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
private void saveData(int state, long location) {
mEntity.setComplete(state == IEntity.STATE_COMPLETE);
mTaskEntity.state = state;
if (state == IEntity.STATE_CANCEL) {
mEntity.setState(state);
mEntity.deleteData();
@ -156,5 +160,6 @@ class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
}
mEntity.update();
}
mTaskEntity.update();
}
}

@ -19,7 +19,7 @@ import android.text.TextUtils;
import com.arialyy.aria.core.SubTaskManager;
import com.arialyy.aria.core.inf.AbsDownloadTarget;
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.util.CommonUtil;
import java.io.File;
@ -29,7 +29,7 @@ import java.util.List;
/**
* 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> {
List<String> mUrls = new ArrayList<>();

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

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

@ -15,13 +15,13 @@
*/
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;
/**
* 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;

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

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

@ -74,7 +74,6 @@ public class DownloadTarget
entity.save();
mTaskEntity.save();
}
mEntity = mTaskEntity.entity;
}
@ -165,7 +164,7 @@ public class DownloadTarget
* 是否在下载
*/
public boolean isDownloading() {
DownloadTask task = DownloadTaskQueue.getInstance().getTask(mEntity);
DownloadTask task = DownloadTaskQueue.getInstance().getTask(mEntity.getKey());
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.download.downloader.SimpleDownloadUtil;
import com.arialyy.aria.core.inf.AbsNormalTask;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.scheduler.ISchedulers;
import java.io.File;
@ -31,18 +30,20 @@ import java.io.File;
* 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";
private DownloadListener mListener;
private DownloadEntity mEntity;
private IUtil mUtil;
private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) {
mEntity = taskEntity.getEntity();
mTaskEntity = taskEntity;
mOutHandler = outHandler;
mContext = AriaManager.APP;
mListener = new DownloadListener(this, mOutHandler);
mUtil = new SimpleDownloadUtil(taskEntity, mListener);
mEntity = taskEntity.getEntity();
}
/**
@ -58,6 +59,10 @@ public class DownloadTask extends AbsNormalTask<DownloadEntity> {
return mEntity.getDownloadPath();
}
public DownloadEntity getEntity() {
return mTaskEntity.getEntity();
}
/**
* 获取当前下载任务的下载地址
*

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.download;
import com.arialyy.aria.core.inf.AbsNormalTaskEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.orm.Ignore;
import com.arialyy.aria.orm.OneToOne;
@ -23,7 +24,7 @@ import com.arialyy.aria.orm.OneToOne;
* 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;

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

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

@ -18,7 +18,8 @@ package com.arialyy.aria.core.inf;
/**
* 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) {
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.NormalCmdFactory;
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 java.util.ArrayList;
import java.util.List;
@ -165,10 +168,23 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
*/
@Override public void start() {
AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START))
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START,
checkTaskType()))
.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() {
AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_STOP))
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_STOP,
checkTaskType()))
.exe();
}
@ -189,7 +206,8 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
*/
@Override public void resume() {
AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START))
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START,
checkTaskType()))
.exe();
}
@ -198,7 +216,8 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
*/
@Override public void cancel() {
AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CANCEL))
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CANCEL,
checkTaskType()))
.exe();
}
@ -207,8 +226,11 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
*/
public void reTry() {
List<ICmd> cmds = new ArrayList<>();
cmds.add(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_STOP));
cmds.add(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START));
int taskType = checkTaskType();
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();
}
@ -220,7 +242,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
*/
public void cancel(boolean removeFile) {
CancelCmd cancelCmd = (CancelCmd) CommonUtil.createNormalCmd(mTargetName, mTaskEntity,
NormalCmdFactory.TASK_CANCEL);
NormalCmdFactory.TASK_CANCEL, checkTaskType());
cancelCmd.removeFile = removeFile;
AriaManager.getInstance(AriaManager.APP).setCmd(cancelCmd).exe();
}

@ -22,13 +22,13 @@ import com.arialyy.aria.util.CommonUtil;
/**
* 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
*/
public boolean needRetry = true;
protected ENTITY mEntity;
protected TASK_ENTITY mTaskEntity;
protected Handler mOutHandler;
/**
@ -44,14 +44,14 @@ public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY>
* @return {@code true} 已经完成{@code false} 未完成
*/
public boolean isComplete() {
return mEntity.isComplete();
return mTaskEntity.getEntity().isComplete();
}
/**
* 获取当前下载进度
*/
@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}
*/
@Override public String getConvertCurrentProgress() {
if (mEntity.getCurrentProgress() == 0) {
if (mTaskEntity.getEntity().getCurrentProgress() == 0) {
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
*/
@Override public String getConvertFileSize() {
if (mEntity.getFileSize() == 0) {
if (mTaskEntity.getEntity().getFileSize() == 0) {
return "0mb";
}
return CommonUtil.formatFileSize(mEntity.getFileSize());
return CommonUtil.formatFileSize(mTaskEntity.getEntity().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
*/
@Override public int getPercent() {
if (mEntity.getFileSize() == 0) {
if (mTaskEntity.getEntity().getFileSize() == 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}
*/
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否则返回扩展字段
*/
@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() {
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() {
return mEntity.getConvertSpeed();
return mTaskEntity.getEntity().getConvertSpeed();
}
@Override public ENTITY getEntity() {
return mEntity;
@Override public TASK_ENTITY getTaskEntity() {
return mTaskEntity;
}
public String getTargetName() {

@ -24,6 +24,7 @@ import java.util.Map;
/**
* Created by lyy on 2017/2/23.
* 所有任务实体的父类
*/
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;
/**
* 任务状态和Entity的state同步
*/
public int state = IEntity.STATE_WAIT;
/**
* 请求类型
* {@link AbsTaskEntity#HTTP}{@link AbsTaskEntity#FTP}

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

@ -18,7 +18,7 @@ package com.arialyy.aria.core.inf;
/**
* 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();
@ -91,5 +91,4 @@ public interface ITask<ENTITY extends AbsEntity> {
String getConvertCurrentProgress();
void setTargetName(String targetName);
}

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

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

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

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

@ -90,7 +90,8 @@ public class QueueControl implements Handler.Callback {
@Override public boolean handleMessage(Message msg) {
switch (msg.what) {
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;
case CMD_CREATE_TASK:
SparseArray params = (SparseArray) msg.obj;
@ -105,7 +106,7 @@ public class QueueControl implements Handler.Callback {
queue.stopTask((AbsTask) msg.obj);
break;
case CMD_CANCEL_TASK:
queue.removeTask((AbsTask) msg.obj);
queue.cancelTask((AbsTask) msg.obj);
break;
case CMD_STOP_ALL_TASK:
queue.stopAllTask();

@ -31,7 +31,7 @@ import com.arialyy.aria.core.upload.UploadTaskEntity;
* 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 volatile UploadTaskQueue INSTANCE = null;
@ -55,10 +55,6 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity,
return UploadSharePool.getInstance().executePool;
}
@Override public String getKey(UploadEntity entity) {
return entity.getFilePath();
}
@Override public int getConfigMaxNum() {
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) {
if (TextUtils.isEmpty(downloadUrl)) {
if (TextUtils.isEmpty(key)) {
Log.e(TAG, "请传入有效的任务key");
return null;
}
String key = CommonUtil.keyToHashKey(downloadUrl);
return mExecuteMap.get(key);
return mExecuteMap.get(CommonUtil.keyToHashKey(key));
}
}

@ -37,7 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
* 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> {
private final String TAG = "AbsSchedulers";
@ -148,14 +148,13 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
* 处理普通任务事件
*/
private void handleNormalEvent(TASK task, int what) {
ENTITY entity = task.getEntity();
switch (what) {
case STOP:
if (task.getEntity().getState() == IEntity.STATE_WAIT) {
if (task.getState() == IEntity.STATE_WAIT) {
break;
}
case CANCEL:
mQueue.removeTask(entity);
mQueue.removeTaskFormQueue(task.getKey());
if (mQueue.getCurrentExePoolNum() < AriaManager.getInstance(AriaManager.APP)
.getUploadConfig()
.getMaxTaskNum()) {
@ -163,7 +162,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
}
break;
case COMPLETE:
mQueue.removeTask(entity);
mQueue.removeTaskFormQueue(task.getKey());
startNextTask();
break;
case FAIL:
@ -236,7 +235,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
*/
private void handleFailTask(final TASK task) {
if (!task.needRetry) {
mQueue.removeTask(task.getEntity());
mQueue.removeTaskFormQueue(task.getKey());
startNextTask();
return;
}
@ -257,12 +256,12 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
}
@Override public void onFinish() {
ENTITY entity = task.getEntity();
AbsEntity entity = task.getTaskEntity().getEntity();
if (entity.getFailNum() < reTryNum) {
TASK task = mQueue.getTask(entity);
TASK task = mQueue.getTask(entity.getKey());
mQueue.reTryStart(task);
} else {
mQueue.removeTask(entity);
mQueue.removeTaskFormQueue(task.getKey());
startNextTask();
}
}
@ -279,7 +278,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends A
Log.w(TAG, "没有下一任务");
return;
}
if (newTask.getEntity().getState() == IEntity.STATE_WAIT) {
if (newTask.getState() == IEntity.STATE_WAIT) {
mQueue.startTask(newTask);
}
}

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

@ -27,7 +27,7 @@ import com.arialyy.aria.core.download.DownloadTask;
* 任务下载器提供抽象的方法供具体的实现类操作
*/
public class DownloadSchedulers
extends AbsSchedulers<DownloadTaskEntity, DownloadEntity, DownloadTask, DownloadTaskQueue> {
extends AbsSchedulers<DownloadTaskEntity, DownloadTask, DownloadTaskQueue> {
private final String TAG = "DownloadSchedulers";
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.queue.UploadTaskQueue;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTask;
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.
* 上传任务调度器
*/
public class UploadSchedulers
extends AbsSchedulers<UploadTaskEntity, UploadEntity, UploadTask, UploadTaskQueue> {
public class UploadSchedulers extends AbsSchedulers<UploadTaskEntity, UploadTask, UploadTaskQueue> {
private static final String TAG = "UploadSchedulers";
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.inf.AbsEntity;
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.IUploadListener;
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 {
private WeakReference<Handler> outHandler;
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
private long mLastLen = 0; //上一次发送长度
private boolean isFirst = true;
protected ENTITY mEntity;
protected TASK_ENTITY mTaskEntity;
protected TASK mTask;
private boolean isConvertSpeed = false;
boolean isWait = false;
@ -43,7 +45,8 @@ class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
BaseUListener(TASK task, Handler outHandler) {
this.outHandler = new WeakReference<>(outHandler);
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);
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
mLastLen = mEntity.getCurrentProgress();
@ -129,6 +132,7 @@ class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
private void saveData(int state, long location) {
mEntity.setComplete(state == IEntity.STATE_COMPLETE);
mTaskEntity.state = state;
if (state == IEntity.STATE_CANCEL) {
mEntity.deleteData();
} else if (state == IEntity.STATE_COMPLETE) {
@ -143,5 +147,6 @@ class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
}
mEntity.update();
}
mTaskEntity.update();
}
}

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

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

@ -24,6 +24,7 @@ import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
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.GroupCmdFactory;
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.DownloadTaskEntity;
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.UploadTaskEntity;
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,
int cmd) {
return NormalCmdFactory.getInstance().createCmd(target, entity, cmd);
int cmd, int taskType) {
return NormalCmdFactory.getInstance().createCmd(target, entity, cmd, taskType);
}
/**
@ -448,7 +452,7 @@ public class CommonUtil {
*
* @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) {
return GroupCmdFactory.getInstance().createCmd(target, entity, cmd, childUrl);
}

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

@ -28,8 +28,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/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion)
```java
compile 'com.arialyy.aria:aria-core:3.3.3'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.3'
compile 'com.arialyy.aria:aria-core:3.3.4'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.4'
```
***

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

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

@ -15,7 +15,7 @@
*/
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 java.util.HashMap;
import java.util.Map;
@ -24,7 +24,7 @@ import java.util.Map;
* 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 contentType = "multipart/form-data"; //上传的文件类型
public String userAgent = "User-Agent";

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

Loading…
Cancel
Save