优化配置功能、增加组合任务的配置功能

优化任务队列代码
v3.6.6
laoyuyu 6 years ago
parent f6792b225a
commit 56af75c35c
  1. 2
      Aria/jcenter.gradle
  2. 23
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  3. 363
      Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java
  4. 441
      Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java.back
  5. 4
      Aria/src/main/java/com/arialyy/aria/core/ConfigType.java
  6. 4
      Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java
  7. 3
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java
  8. 55
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  9. 3
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  10. 87
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  11. 6
      Aria/src/main/java/com/arialyy/aria/core/common/TaskRecord.java
  12. 5
      Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java
  13. 2
      Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java
  14. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DGEntityWrapper.java
  15. 11
      Aria/src/main/java/com/arialyy/aria/core/download/DGTaskWrapper.java
  16. 37
      Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java
  17. 20
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  18. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java
  19. 12
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  20. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java
  21. 6
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  22. 4
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java
  23. 20
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  24. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  25. 10
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java
  26. 16
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java
  27. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java
  28. 1
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  29. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  30. 4
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java
  31. 12
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java
  32. 3
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java
  33. 14
      Aria/src/main/java/com/arialyy/aria/core/manager/DGTaskWrapperFactory.java
  34. 7
      Aria/src/main/java/com/arialyy/aria/core/manager/DTaskWrapperFactory.java
  35. 4
      Aria/src/main/java/com/arialyy/aria/core/manager/IGTEFactory.java
  36. 8
      Aria/src/main/java/com/arialyy/aria/core/manager/TaskWrapperManager.java
  37. 4
      Aria/src/main/java/com/arialyy/aria/core/manager/UTaskWrapperFactory.java
  38. 41
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  39. 11
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java
  40. 8
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  41. 30
      Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
  42. 11
      Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java
  43. 11
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java
  44. 7
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java
  45. 20
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/IPool.java
  46. 16
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  47. 1
      Aria/src/main/java/com/arialyy/aria/core/upload/BaseNormalTarget.java
  48. 21
      Aria/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java
  49. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java
  50. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java
  51. 6
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java
  52. 5
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  53. 2
      Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java
  54. 2
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  55. 24
      Aria/src/main/java/com/arialyy/aria/util/DbDataHelper.java
  56. 8
      AriaAnnotations/src/main/java/com/arialyy/annotations/DownloadGroup.java
  57. 5
      DEV_LOG.md
  58. 71
      app/src/main/assets/aria_config.xml
  59. 2
      app/src/main/java/com/arialyy/simple/DbTestActivity.java
  60. 2
      app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt
  61. 7
      app/src/main/java/com/arialyy/simple/download/group/ChildHandleDialog.java
  62. 2
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
  63. 220
      aria/src/main/java/com/arialyy/aria/core/Configuration.java

@ -76,7 +76,7 @@ artifacts {
//################################# jcenter start #########################################
bintray {
// user = hasProperty("bintrayUser") ? getProperty("bintrayUser") : getProperty("BINTRAY_USER")
// groupName = hasProperty("bintrayKey") ? getProperty("bintrayKey") : getProperty("BINTRAY_KEY")
// groupHash = hasProperty("bintrayKey") ? getProperty("bintrayKey") : getProperty("BINTRAY_KEY")
user = BINTRAY_USER
key = BINTRAY_KEY
configurations = ['archives']

@ -30,15 +30,12 @@ import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.common.QueueMod;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.IReceiver;
import com.arialyy.aria.core.inf.ReceiverType;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadReceiver;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.DelegateWrapper;
import com.arialyy.aria.util.ALog;
@ -78,6 +75,7 @@ import org.xml.sax.SAXException;
private Configuration.DownloadConfig mDConfig;
private Configuration.UploadConfig mUConfig;
private Configuration.AppConfig mAConfig;
private Configuration.DGroupConfig mDGConfig;
private AriaManager(Context context) {
APP = context.getApplicationContext();
@ -127,8 +125,7 @@ import org.xml.sax.SAXException;
*/
private void amendTaskState() {
Class[] clazzs = new Class[] {
DownloadEntity.class, UploadEntity.class, DownloadGroupEntity.class,
DTaskWrapper.class, UTaskWrapper.class, DGTaskWrapper.class
DownloadEntity.class, UploadEntity.class, DownloadGroupEntity.class
};
String sql = "UPDATE %s SET state=2 WHERE state IN (3,4,5,6)";
for (Class clazz : clazzs) {
@ -206,6 +203,19 @@ import org.xml.sax.SAXException;
return mAConfig;
}
/**
* 如果需要在代码中修改下载类型的组合任务的配置请使用以下方法
* <pre>
* <code>
* //修改最大任务队列数
* Aria.get(this).getDownloadConfig().setMaxTaskNum(3);
* </code>
* </pre>
*/
public Configuration.DGroupConfig getDGroupConfig(){
return mDGConfig;
}
/**
* 设置命令
*/
@ -268,7 +278,7 @@ import org.xml.sax.SAXException;
DbEntity.deleteData(DownloadEntity.class, "url=? and isGroupChild='false'", key);
break;
case 2:
DbEntity.deleteData(DownloadGroupEntity.class, "groupName=?", key);
DbEntity.deleteData(DownloadGroupEntity.class, "groupHash=?", key);
break;
case 3:
DbEntity.deleteData(UploadEntity.class, "filePath=?", key);
@ -379,6 +389,7 @@ import org.xml.sax.SAXException;
mDConfig = Configuration.getInstance().downloadCfg;
mUConfig = Configuration.getInstance().uploadCfg;
mAConfig = Configuration.getInstance().appCfg;
mDGConfig = Configuration.getInstance().dGroupCfg;
File xmlFile = new File(APP.getFilesDir().getPath() + Configuration.XML_FILE);
File tempDir = new File(APP.getFilesDir().getPath() + "/temp");

@ -17,6 +17,9 @@ package com.arialyy.aria.core;
import android.text.TextUtils;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.lang.reflect.Field;
import javax.xml.validation.Validator;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@ -30,6 +33,7 @@ class ConfigHelper extends DefaultHandler {
private Configuration.DownloadConfig mDownloadConfig = Configuration.getInstance().downloadCfg;
private Configuration.UploadConfig mUploadConfig = Configuration.getInstance().uploadCfg;
private Configuration.AppConfig mAppConfig = Configuration.getInstance().appCfg;
private Configuration.DGroupConfig mDGroupConfig = Configuration.getInstance().dGroupCfg;
private @ConfigType int mType;
@Override public void startDocument() throws SAXException {
@ -50,281 +54,165 @@ class ConfigHelper extends DefaultHandler {
case "app":
mType = ConfigType.APP;
break;
case "dGroup":
mType = ConfigType.D_GROUP;
break;
}
if (mType == ConfigType.DOWNLOAD || mType == ConfigType.UPLOAD) {
if (mType == ConfigType.DOWNLOAD || mType == ConfigType.UPLOAD || mType == ConfigType.D_GROUP) {
String value = attributes.getValue("value");
switch (qName) {
case "threadNum":
loadThreadNum(value);
break;
case "maxTaskNum":
loadMaxQueue(value);
case "threadNum": // 线程数
int threadNum = checkInt(value) ? Integer.parseInt(value) : 3;
if (threadNum < 1) {
ALog.w(TAG, "下载线程数不能小于 1");
threadNum = 1;
}
setField("threadNum", threadNum, ConfigType.DOWNLOAD);
break;
case "reTryNum":
loadReTry(value);
case "maxTaskNum": //最大任务书
int maxTaskNum = checkInt(value) ? Integer.parseInt(value) : 2;
if (maxTaskNum < 1) {
ALog.w(TAG, "任务队列数不能小于 1");
maxTaskNum = 2;
}
setField("maxTaskNum", maxTaskNum, getAllTaskType());
break;
case "connectTimeOut":
loadConnectTime(value);
case "reTryNum": //任务重试次数
setField("reTryNum", checkInt(value) ? Integer.parseInt(value) : 0, getAllTaskType());
break;
case "iOTimeOut":
loadIOTimeout(value);
case "connectTimeOut": // 连接超时时间
setField("connectTimeOut", checkInt(value) ? Integer.parseInt(value) : 5 * 1000,
getAllTaskType());
break;
case "reTryInterval":
loadReTryInterval(value);
case "iOTimeOut": //io流超时时间
int iOTimeOut = checkInt(value) ? Integer.parseInt(value) : 10 * 1000;
if (iOTimeOut < 10 * 1000) {
iOTimeOut = 10 * 1000;
}
setField("iOTimeOut", iOTimeOut, getAllTaskType());
break;
case "buffSize":
loadBuffSize(value);
case "reTryInterval": //失败重试间隔
int reTryInterval = checkInt(value) ? Integer.parseInt(value) : 2 * 1000;
if (reTryInterval < 2 * 1000) {
reTryInterval = 2 * 1000;
}
setField("reTryInterval", reTryInterval, getAllTaskType());
break;
case "useBroadcast":
loadUseBroadcast(value);
case "buffSize": //缓冲大小
int buffSize = checkInt(value) ? Integer.parseInt(value) : 8192;
if (buffSize < 2048) {
buffSize = 2048;
}
setField("buffSize", buffSize, getAllTaskType());
break;
case "ca":
case "ca": // ca证书
String caName = attributes.getValue("name");
String caPath = attributes.getValue("path");
loadCA(caName, caPath);
setField("caName", caName, getAllTaskType());
setField("caPath", caPath, getAllTaskType());
break;
case "convertSpeed":
loadConvertSpeed(value);
case "convertSpeed": // 是否转换速度
setField("isConvertSpeed", !checkBoolean(value) || Boolean.parseBoolean(value),
getAllTaskType());
break;
case "maxSpeed":
loadMaxSpeed(value);
case "maxSpeed": // 最大速度
int maxSpeed = checkInt(value) ? Integer.parseInt(value) : 0;
setField("maxSpeed", maxSpeed, getAllTaskType());
break;
case "queueMod":
loadQueueMod(value);
case "queueMod": // 队列类型
String mod = "now";
if (!TextUtils.isEmpty(value) && (value.equalsIgnoreCase("now") || value.equalsIgnoreCase(
"wait"))) {
mod = value;
}
setField("queueMod", mod, getAllTaskType());
break;
case "updateInterval":
loadUpdateInterval(value);
case "updateInterval": // 进度更新时间
setField("updateInterval", checkLong(value) ? Long.parseLong(value) : 1000,
getAllTaskType());
break;
case "notNetRetry":
loadNotNetRetry(value);
case "useBlock": // 是否使用分块任务
setField("useBlock", checkBoolean(value) ? Boolean.valueOf(value) : false,
ConfigType.DOWNLOAD);
break;
case "subMaxTaskNum": // 子任务最大任务数
int subMaxTaskNum = checkInt(value) ? Integer.parseInt(value) : 3;
setField("subMaxTaskNum", subMaxTaskNum, ConfigType.D_GROUP);
break;
case "useBlock":
loadUseBlock(value);
case "subReTryNum": // 子任务重试次数
int subReTryNum = checkInt(value) ? Integer.parseInt(value) : 5;
setField("subReTryNum", subReTryNum, ConfigType.D_GROUP);
break;
case "subReTryInterval": // 子任务重试间隔
int subReTryInterval = checkInt(value) ? Integer.parseInt(value) : 2000;
setField("subReTryInterval", subReTryInterval, ConfigType.D_GROUP);
break;
}
} else if (mType == ConfigType.APP) {
String value = attributes.getValue("value");
switch (qName) {
case "useAriaCrashHandler":
loadUseAriaCrashHandler(value);
case "useAriaCrashHandler": // 是否捕捉崩溃日志
setField("useAriaCrashHandler", checkBoolean(value) ? Boolean.valueOf(value) : true,
ConfigType.APP);
break;
case "logLevel":
loadLogLevel(value);
case "logLevel": // 日记等级
int level = checkInt(value) ? Integer.parseInt(value) : ALog.LOG_LEVEL_VERBOSE;
if (level < ALog.LOG_LEVEL_VERBOSE || level > ALog.LOG_CLOSE) {
ALog.w(TAG, "level【" + level + "】错误");
level = ALog.LOG_LEVEL_VERBOSE;
}
setField("level", level, ConfigType.APP);
break;
case "netCheck":
loadNetCheck(value);
case "netCheck": // 是否检查网络
setField("netCheck", checkBoolean(value) ? Boolean.valueOf(value) : false,
ConfigType.APP);
break;
case "useBroadcast": // 是否使用广播
setField("useBroadcast", checkBoolean(value) ? Boolean.valueOf(value) : false,
ConfigType.APP);
break;
case "notNetRetry": // 没有网络也重试
setField("notNetRetry", checkBoolean(value) ? Boolean.valueOf(value) : false,
ConfigType.APP);
break;
}
}
}
private void loadNetCheck(String value) {
boolean b = checkBoolean(value), temp = false;
if (b) {
temp = Boolean.valueOf(value);
}
mAppConfig.netCheck = temp;
}
private void loadUseBroadcast(String value) {
boolean b = checkBoolean(value), temp = false;
if (b) {
temp = Boolean.valueOf(value);
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.useBroadcast = temp;
}
if (mType == ConfigType.UPLOAD) {
mUploadConfig.useBroadcast = temp;
}
}
private void loadUseBlock(String value) {
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.useBlock = checkBoolean(value) ? Boolean.valueOf(value) : false;
}
/**
* 获取任务类型集合类型有 {@link ConfigType#DOWNLOAD}{@link ConfigType#UPLOAD}{@link ConfigType#D_GROUP}
*/
private int[] getAllTaskType() {
return new int[] {ConfigType.DOWNLOAD, ConfigType.UPLOAD,
ConfigType.D_GROUP};
}
private void loadNotNetRetry(String value) {
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.notNetRetry = checkBoolean(value) ? Boolean.valueOf(value) : false;
private void setField(String key, Object value, int... types) {
for (int type : types) {
if (type == ConfigType.DOWNLOAD) {
setField(Configuration.DownloadConfig.class, mDownloadConfig, key, value);
} else if (type == ConfigType.UPLOAD) {
setField(Configuration.UploadConfig.class, mUploadConfig, key, value);
} else if (type == ConfigType.APP) {
setField(Configuration.AppConfig.class, mAppConfig, key, value);
} else if (type == ConfigType.D_GROUP) {
setField(Configuration.DGroupConfig.class, mDGroupConfig, key, value);
}
if (mType == ConfigType.UPLOAD) {
mUploadConfig.notNetRetry = checkBoolean(value) ? Boolean.valueOf(value) : false;
}
}
private void loadLogLevel(String value) {
int level;
private void setField(Class clazz, Object target, String key, Object value) {
Field field = CommonUtil.getField(clazz, key);
try {
level = Integer.parseInt(value);
} catch (NumberFormatException e) {
field.set(target, value);
} catch (IllegalAccessException e) {
e.printStackTrace();
level = ALog.LOG_LEVEL_VERBOSE;
}
if (level < ALog.LOG_LEVEL_VERBOSE || level > ALog.LOG_CLOSE) {
ALog.w(TAG, "level【" + level + "】错误");
mAppConfig.logLevel = ALog.LOG_LEVEL_VERBOSE;
} else {
mAppConfig.logLevel = level;
}
}
private void loadUseAriaCrashHandler(String value) {
if (checkBoolean(value)) {
mAppConfig.useAriaCrashHandler = Boolean.parseBoolean(value);
} else {
ALog.w(TAG, "useAriaCrashHandler【" + value + "】错误");
mAppConfig.useAriaCrashHandler = true;
}
}
private void loadUpdateInterval(String value) {
long temp = checkLong(value) ? Long.parseLong(value) : 1000;
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.updateInterval = temp;
}
if (mType == ConfigType.UPLOAD) {
mUploadConfig.updateInterval = temp;
}
}
private void loadQueueMod(String value) {
String mod = "now";
if (!TextUtils.isEmpty(value) && (value.equalsIgnoreCase("now") || value.equalsIgnoreCase(
"wait"))) {
mod = value;
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.queueMod = mod;
}
if (mType == ConfigType.UPLOAD) {
mUploadConfig.queueMod = mod;
}
}
private void loadMaxSpeed(String value) {
int maxSpeed = checkInt(value) ? Integer.parseInt(value) : 0;
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.maxSpeed = maxSpeed;
}
if (mType == ConfigType.UPLOAD) {
mUploadConfig.maxSpeed = maxSpeed;
}
}
private void loadConvertSpeed(String value) {
boolean open = true;
if (checkBoolean(value)) {
open = Boolean.parseBoolean(value);
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.isConvertSpeed = open;
}
if (mType == ConfigType.UPLOAD) {
mUploadConfig.isConvertSpeed = open;
}
}
private void loadReTryInterval(String value) {
int time = checkInt(value) ? Integer.parseInt(value) : 2 * 1000;
if (time < 2 * 1000) {
time = 2 * 1000;
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.reTryInterval = time;
}
}
private void loadCA(String name, String path) {
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.caName = name;
mDownloadConfig.caPath = path;
}
}
private void loadBuffSize(String value) {
int buffSize = checkInt(value) ? Integer.parseInt(value) : 8192;
if (buffSize < 2048) {
buffSize = 2048;
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.buffSize = buffSize;
}
if (mType == ConfigType.UPLOAD) {
mUploadConfig.buffSize = buffSize;
}
}
private void loadIOTimeout(String value) {
int time = checkInt(value) ? Integer.parseInt(value) : 10 * 1000;
if (time < 10 * 1000) {
time = 10 * 1000;
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.iOTimeOut = time;
}
if (mType == ConfigType.UPLOAD) {
mUploadConfig.iOTimeOut = time;
}
}
private void loadConnectTime(String value) {
int time = checkInt(value) ? Integer.parseInt(value) : 5 * 1000;
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.connectTimeOut = time;
}
if (mType == ConfigType.UPLOAD) {
mUploadConfig.connectTimeOut = time;
}
}
private void loadReTry(String value) {
int num = checkInt(value) ? Integer.parseInt(value) : 0;
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.reTryNum = num;
}
if (mType == ConfigType.UPLOAD) {
mUploadConfig.reTryNum = num;
}
}
private void loadMaxQueue(String value) {
int num = checkInt(value) ? Integer.parseInt(value) : 2;
if (num < 1) {
ALog.w(TAG, "任务队列数不能小于 1");
num = 2;
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.maxTaskNum = num;
}
if (mType == ConfigType.UPLOAD) {
mUploadConfig.maxTaskNum = num;
}
}
private void loadThreadNum(String value) {
int num = checkInt(value) ? Integer.parseInt(value) : 3;
if (num < 1) {
ALog.e(TAG, "下载线程数不能小于 1");
num = 1;
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.threadNum = num;
}
}
@ -338,8 +226,8 @@ class ConfigHelper extends DefaultHandler {
return false;
}
try {
Integer l = Integer.parseInt(value);
return true;
int l = Integer.parseInt(value);
return l >= 0;
} catch (NumberFormatException e) {
e.printStackTrace();
return false;
@ -387,5 +275,6 @@ class ConfigHelper extends DefaultHandler {
mDownloadConfig.save();
mUploadConfig.save();
mAppConfig.save();
mDGroupConfig.save();
}
}

@ -0,0 +1,441 @@
/*
* 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;
import android.text.TextUtils;
import com.arialyy.aria.util.ALog;
import javax.xml.validation.Validator;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* Created by lyy on 2017/5/22. 读取配置文件
*/
class ConfigHelper extends DefaultHandler {
private final String TAG = "ConfigHelper";
private Configuration.DownloadConfig mDownloadConfig = Configuration.getInstance().downloadCfg;
private Configuration.UploadConfig mUploadConfig = Configuration.getInstance().uploadCfg;
private Configuration.AppConfig mAppConfig = Configuration.getInstance().appCfg;
private Configuration.DGroupConfig mDGroupConfig = Configuration.getInstance().dGroupCfg;
private @ConfigType int mType;
@Override public void startDocument() throws SAXException {
super.startDocument();
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
super.startElement(uri, localName, qName, attributes);
switch (qName) {
case "download":
mType = ConfigType.DOWNLOAD;
break;
case "upload":
mType = ConfigType.UPLOAD;
break;
case "app":
mType = ConfigType.APP;
break;
case "dGroup":
mType = ConfigType.D_GROUP;
break;
}
if (mType == ConfigType.DOWNLOAD || mType == ConfigType.UPLOAD || mType == ConfigType.D_GROUP) {
String value = attributes.getValue("value");
switch (qName) {
case "threadNum":
loadThreadNum(value);
break;
case "maxTaskNum":
loadMaxQueue(value);
break;
case "reTryNum":
loadReTry(value);
break;
case "connectTimeOut":
loadConnectTime(value);
break;
case "iOTimeOut":
loadIOTimeout(value);
break;
case "reTryInterval":
loadReTryInterval(value);
break;
case "buffSize":
loadBuffSize(value);
break;
case "ca":
String caName = attributes.getValue("name");
String caPath = attributes.getValue("path");
loadCA(caName, caPath);
break;
case "convertSpeed":
loadConvertSpeed(value);
break;
case "maxSpeed":
loadMaxSpeed(value);
break;
case "queueMod":
loadQueueMod(value);
break;
case "updateInterval":
loadUpdateInterval(value);
break;
case "notNetRetry":
loadNotNetRetry(value);
break;
case "useBlock":
loadUseBlock(value);
break;
case "subMaxTaskNum":
loadSubMaxTaskNum(value);
break;
case "subReTryNum":
loadSubReTryNum(value);
break;
case "subReTryInterval":
loadSubReTryInterval(value);
break;
}
} else if (mType == ConfigType.APP) {
String value = attributes.getValue("value");
switch (qName) {
case "useAriaCrashHandler":
loadUseAriaCrashHandler(value);
break;
case "logLevel":
loadLogLevel(value);
break;
case "netCheck":
loadNetCheck(value);
break;
case "useBroadcast":
loadUseBroadcast(value);
break;
}
}
}
private void loadSubReTryInterval(String value) {
int temp = checkInt(value) ? Integer.parseInt(value) : 2000;
if (mType == ConfigType.D_GROUP) {
mDGroupConfig.subReTryInterval = temp;
}
}
private void loadSubReTryNum(String value) {
int temp = checkInt(value) ? Integer.parseInt(value) : 5;
if (mType == ConfigType.D_GROUP) {
mDGroupConfig.subReTryNum = temp;
}
}
private void loadSubMaxTaskNum(String value) {
int temp = checkInt(value) ? Integer.parseInt(value) : 3;
if (mType == ConfigType.D_GROUP) {
mDGroupConfig.subMaxTaskNum = temp;
}
}
private void loadNetCheck(String value) {
boolean b = checkBoolean(value), temp = false;
if (b) {
temp = Boolean.valueOf(value);
}
mAppConfig.netCheck = temp;
}
private void loadUseBroadcast(String value) {
boolean b = checkBoolean(value), temp = false;
if (b) {
temp = Boolean.valueOf(value);
}
if (mType == ConfigType.APP) {
mAppConfig.useBroadcast = temp;
}
}
private void loadUseBlock(String value) {
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.useBlock = checkBoolean(value) ? Boolean.valueOf(value) : false;
}
}
private void loadNotNetRetry(String value) {
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.notNetRetry = checkBoolean(value) ? Boolean.valueOf(value) : false;
} else if (mType == ConfigType.UPLOAD) {
mUploadConfig.notNetRetry = checkBoolean(value) ? Boolean.valueOf(value) : false;
} else if (mType == ConfigType.D_GROUP) {
mDGroupConfig.notNetRetry = checkBoolean(value) ? Boolean.valueOf(value) : false;
}
}
private void loadLogLevel(String value) {
int level;
try {
level = Integer.parseInt(value);
} catch (NumberFormatException e) {
e.printStackTrace();
level = ALog.LOG_LEVEL_VERBOSE;
}
if (level < ALog.LOG_LEVEL_VERBOSE || level > ALog.LOG_CLOSE) {
ALog.w(TAG, "level【" + level + "】错误");
mAppConfig.logLevel = ALog.LOG_LEVEL_VERBOSE;
} else {
mAppConfig.logLevel = level;
}
}
private void loadUseAriaCrashHandler(String value) {
if (checkBoolean(value)) {
mAppConfig.useAriaCrashHandler = Boolean.parseBoolean(value);
} else {
ALog.w(TAG, "useAriaCrashHandler【" + value + "】错误");
mAppConfig.useAriaCrashHandler = true;
}
}
private void loadUpdateInterval(String value) {
long temp = checkLong(value) ? Long.parseLong(value) : 1000;
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.updateInterval = temp;
} else if (mType == ConfigType.UPLOAD) {
mUploadConfig.updateInterval = temp;
} else if (mType == ConfigType.D_GROUP) {
mDGroupConfig.updateInterval = temp;
}
}
private void loadQueueMod(String value) {
String mod = "now";
if (!TextUtils.isEmpty(value) && (value.equalsIgnoreCase("now") || value.equalsIgnoreCase(
"wait"))) {
mod = value;
} else if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.queueMod = mod;
} else if (mType == ConfigType.UPLOAD) {
mUploadConfig.queueMod = mod;
} else if (mType == ConfigType.D_GROUP) {
mDGroupConfig.queueMod = mod;
}
}
private void loadMaxSpeed(String value) {
int maxSpeed = checkInt(value) ? Integer.parseInt(value) : 0;
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.maxSpeed = maxSpeed;
} else if (mType == ConfigType.UPLOAD) {
mUploadConfig.maxSpeed = maxSpeed;
} else if (mType == ConfigType.D_GROUP) {
mDownloadConfig.maxSpeed = maxSpeed;
}
}
private void loadConvertSpeed(String value) {
boolean open = true;
if (checkBoolean(value)) {
open = Boolean.parseBoolean(value);
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.isConvertSpeed = open;
} else if (mType == ConfigType.UPLOAD) {
mUploadConfig.isConvertSpeed = open;
} else if (mType == ConfigType.D_GROUP) {
mUploadConfig.isConvertSpeed = open;
}
}
private void loadReTryInterval(String value) {
int time = checkInt(value) ? Integer.parseInt(value) : 2 * 1000;
if (time < 2 * 1000) {
time = 2 * 1000;
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.reTryInterval = time;
} else if (mType == ConfigType.UPLOAD) {
mUploadConfig.reTryInterval = time;
} else if (mType == ConfigType.D_GROUP) {
mDGroupConfig.reTryInterval = time;
}
}
private void loadCA(String name, String path) {
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.caName = name;
mDownloadConfig.caPath = path;
} else if (mType == ConfigType.UPLOAD) {
mUploadConfig.caName = name;
mUploadConfig.caPath = path;
} else if (mType == ConfigType.D_GROUP) {
mDGroupConfig.caName = name;
mDGroupConfig.caPath = path;
}
}
private void loadBuffSize(String value) {
int buffSize = checkInt(value) ? Integer.parseInt(value) : 8192;
if (buffSize < 2048) {
buffSize = 2048;
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.buffSize = buffSize;
}
if (mType == ConfigType.UPLOAD) {
mUploadConfig.buffSize = buffSize;
}
}
private void loadIOTimeout(String value) {
int time = checkInt(value) ? Integer.parseInt(value) : 10 * 1000;
if (time < 10 * 1000) {
time = 10 * 1000;
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.iOTimeOut = time;
} else if (mType == ConfigType.UPLOAD) {
mUploadConfig.iOTimeOut = time;
} else if (mType == ConfigType.D_GROUP) {
mDGroupConfig.iOTimeOut = time;
}
}
private void loadConnectTime(String value) {
int time = checkInt(value) ? Integer.parseInt(value) : 5 * 1000;
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.connectTimeOut = time;
} else if (mType == ConfigType.UPLOAD) {
mUploadConfig.connectTimeOut = time;
} else if (mType == ConfigType.D_GROUP) {
mDGroupConfig.connectTimeOut = time;
}
}
private void loadReTry(String value) {
int num = checkInt(value) ? Integer.parseInt(value) : 0;
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.reTryNum = num;
} else if (mType == ConfigType.UPLOAD) {
mUploadConfig.reTryNum = num;
} else if (mType == ConfigType.D_GROUP) {
mDGroupConfig.reTryNum = num;
}
}
private void loadMaxQueue(String value) {
int num = checkInt(value) ? Integer.parseInt(value) : 2;
if (num < 1) {
ALog.w(TAG, "任务队列数不能小于 1");
num = 2;
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.maxTaskNum = num;
} else if (mType == ConfigType.UPLOAD) {
mUploadConfig.maxTaskNum = num;
} else if (mType == ConfigType.D_GROUP) {
mDGroupConfig.maxTaskNum = num;
}
}
private void loadThreadNum(String value) {
int num = checkInt(value) ? Integer.parseInt(value) : 3;
if (num < 1) {
ALog.e(TAG, "下载线程数不能小于 1");
num = 1;
}
if (mType == ConfigType.DOWNLOAD) {
mDownloadConfig.threadNum = num;
}
}
/**
* 检查是否int值是否合法
*
* @return {@code true} 合法
*/
private boolean checkInt(String value) {
if (TextUtils.isEmpty(value)) {
return false;
}
try {
Integer l = Integer.parseInt(value);
return true;
} catch (NumberFormatException e) {
e.printStackTrace();
return false;
}
}
/**
* 检查是否long值是否合法
*
* @return {@code true} 合法
*/
private boolean checkLong(String value) {
if (TextUtils.isEmpty(value)) {
return false;
}
try {
Long l = Long.parseLong(value);
return true;
} catch (NumberFormatException e) {
e.printStackTrace();
return false;
}
}
/**
* 检查boolean值是否合法
*
* @return {@code true} 合法
*/
private boolean checkBoolean(String value) {
return !TextUtils.isEmpty(value) && (value.equalsIgnoreCase("true") || value.equalsIgnoreCase(
"false"));
}
@Override public void characters(char[] ch, int start, int length) throws SAXException {
super.characters(ch, start, length);
}
@Override public void endElement(String uri, String localName, String qName) throws SAXException {
super.endElement(uri, localName, qName);
}
@Override public void endDocument() throws SAXException {
super.endDocument();
mDownloadConfig.save();
mUploadConfig.save();
mAppConfig.save();
mDGroupConfig.save();
}
}

@ -22,10 +22,12 @@ import java.lang.annotation.RetentionPolicy;
@IntDef({
ConfigType.DOWNLOAD,
ConfigType.UPLOAD,
ConfigType.APP
ConfigType.APP,
ConfigType.D_GROUP
})
@Retention(RetentionPolicy.SOURCE) @interface ConfigType {
int DOWNLOAD = 1;
int UPLOAD = 2;
int APP = 3;
int D_GROUP = 4;
}

@ -17,13 +17,13 @@
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.queue.ITaskQueue;
import com.arialyy.aria.core.queue.AbsTaskQueue;
/**
* Created by AriaL on 2017/6/29.
*/
public abstract class AbsCmd<T extends AbsTaskWrapper> implements ICmd {
protected ITaskQueue mQueue;
protected AbsTaskQueue mQueue;
protected T mTaskWrapper;
protected String TAG;

@ -92,7 +92,6 @@ public abstract class AbsNormalCmd<T extends AbsTaskWrapper> extends AbsCmd<T> {
*/
void sendWaitState(AbsTask task) {
if (task != null) {
task.getTaskWrapper().getEntity().setState(IEntity.STATE_WAIT);
task.getTaskWrapper().setState(IEntity.STATE_WAIT);
task.getOutHandler().obtainMessage(ISchedulers.WAIT, task).sendToTarget();
}
@ -192,7 +191,7 @@ public abstract class AbsNormalCmd<T extends AbsTaskWrapper> extends AbsCmd<T> {
* @return 创建的任务
*/
AbsTask createTask(AbsTaskWrapper taskEntity) {
TaskWrapperManager.getInstance().addTaskWrapper(taskEntity);
return mQueue.createTask(taskEntity);
}
}

@ -16,7 +16,6 @@ import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.NetUtils;
import java.util.ArrayList;
import java.util.List;
@ -62,10 +61,8 @@ final class ResumeAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
"isGroupChild=? AND state!=? ORDER BY stopTime DESC", "false", "1");
if (entities != null && !entities.isEmpty()) {
for (DownloadEntity entity : entities) {
//if (TextUtils.isEmpty(entity.getDownloadPath())){
// continue;
//}
resumeTask(TaskWrapperManager.getInstance().getHttpTaskWrapper(DTaskWrapper.class, entity.getKey()));
addResumeEntity(TaskWrapperManager.getInstance()
.getHttpTaskWrapper(DTaskWrapper.class, entity.getKey()));
}
}
} else if (type == 2) {
@ -73,8 +70,9 @@ final class ResumeAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
DbEntity.findDatas(DownloadGroupEntity.class, "state!=? ORDER BY stopTime DESC", "1");
if (entities != null && !entities.isEmpty()) {
for (DownloadGroupEntity entity : entities) {
resumeTask(
TaskWrapperManager.getInstance().getDGTaskWrapper(DGTaskWrapper.class, entity.getUrls()));
addResumeEntity(
TaskWrapperManager.getInstance()
.getDGTaskWrapper(DGTaskWrapper.class, entity.getUrls()));
}
}
} else if (type == 3) {
@ -82,26 +80,20 @@ final class ResumeAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
DbEntity.findDatas(UploadEntity.class, "state!=? ORDER BY stopTime DESC", "1");
if (entities != null && !entities.isEmpty()) {
for (UploadEntity entity : entities) {
resumeTask(TaskWrapperManager.getInstance().getHttpTaskWrapper(UTaskWrapper.class, entity.getKey()));
addResumeEntity(TaskWrapperManager.getInstance()
.getHttpTaskWrapper(UTaskWrapper.class, entity.getKey()));
}
}
}
}
/**
* 恢复任务
* 添加恢复实体
*/
private void resumeTask(AbsTaskWrapper te) {
private void addResumeEntity(AbsTaskWrapper te) {
if (te == null || te.getEntity() == null) return;
int state = te.getState();
if (state == IEntity.STATE_STOP || state == IEntity.STATE_OTHER) {
resumeEntity(te);
} else if (state == IEntity.STATE_WAIT || state == IEntity.STATE_FAIL) {
if (!mQueue.taskExists(te.getKey())) {
mWaitList.add(te);
} else {
if (!mQueue.taskIsRunning(te.getEntity().getKey())) {
mWaitList.add(te);
}
}
}
@ -128,31 +120,4 @@ final class ResumeAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
}
}
}
/**
* 恢复实体任务
*
* @param te 任务实体
*/
private void resumeEntity(AbsTaskWrapper te) {
if (te instanceof DTaskWrapper) {
if (te.getRequestType() == AbsTaskWrapper.D_FTP
|| te.getRequestType() == AbsTaskWrapper.U_FTP) {
te.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey()));
}
mQueue = DownloadTaskQueue.getInstance();
} else if (te instanceof UTaskWrapper) {
mQueue = UploadTaskQueue.getInstance();
} else if (te instanceof DGTaskWrapper) {
mQueue = DownloadGroupTaskQueue.getInstance();
}
int exeNum = mQueue.getCurrentExePoolNum();
if (exeNum == 0 || exeNum < mQueue.getMaxTaskNum()) {
startTask(createTask(te));
} else {
te.getEntity().setState(IEntity.STATE_WAIT);
AbsTask task = createTask(te);
sendWaitState(task);
}
}
}

@ -31,11 +31,9 @@ import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.orm.AbsWrapper;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.DbDataHelper;
import com.arialyy.aria.util.NetUtils;
import java.util.ArrayList;
import java.util.List;
@ -178,7 +176,6 @@ class StartCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
mQueue = DownloadGroupTaskQueue.getInstance();
}
createTask(te);
sendWaitState();
}
}
}

@ -25,6 +25,7 @@ import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEventListener;
import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
@ -41,7 +42,7 @@ import java.util.concurrent.TimeUnit;
/**
* Created by AriaL on 2017/7/1. 任务处理器
*/
public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskWrapper<ENTITY>>
public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_WRAPPER extends AbsTaskWrapper<ENTITY>>
implements Runnable {
private static final String STATE = "_state_";
private static final String RECORD = "_record_";
@ -53,10 +54,12 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
* 小于1m的文件不启用多线程
*/
protected static final long SUB_LEN = 1024 * 1024;
protected static final int DOWNLOAD = 0x1;
protected static final int UPLOAD = 0x2;
private final String TAG = "AbsFileer";
protected IEventListener mListener;
protected TASK_ENTITY mTaskEntity;
protected TASK_WRAPPER mTaskWrapper;
protected ENTITY mEntity;
protected Context mContext;
protected File mTempFile; //文件
@ -75,16 +78,18 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
private long mUpdateInterval = 1000;
protected TaskRecord mRecord;
protected AbsFileer(IEventListener listener, TASK_ENTITY taskEntity) {
protected AbsFileer(IEventListener listener, TASK_WRAPPER taskEntity) {
mListener = listener;
mTaskEntity = taskEntity;
mEntity = mTaskEntity.getEntity();
mTaskWrapper = taskEntity;
mEntity = mTaskWrapper.getEntity();
mContext = AriaManager.APP;
mConstance = new StateConstance();
}
protected abstract int getType();
public void setNewTask(boolean newTask) {
mTaskEntity.setNewTask(newTask);
mTaskWrapper.setNewTask(newTask);
}
/**
@ -131,16 +136,16 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
checkRecord();
mConstance.isRunning = true;
mConstance.TASK_RECORD = mRecord;
if (!mTaskEntity.isSupportBP()) {
if (!mTaskWrapper.isSupportBP()) {
mTotalThreadNum = 1;
} else {
mTotalThreadNum =
mTaskEntity.isNewTask() ? setNewTaskThreadNum() : mTotalThreadNum;
mTaskWrapper.isNewTask() ? setNewTaskThreadNum() : mTotalThreadNum;
}
mConstance.START_THREAD_NUM = mTotalThreadNum;
// 处理分块和动态文件参数
if (mTaskEntity.isNewTask() && mTaskEntity instanceof DTaskWrapper) {
if (mTaskWrapper.isNewTask() && mTaskWrapper instanceof DTaskWrapper) {
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
mRecord.isBlock = mTotalThreadNum > 1 && manager.getDownloadConfig().isUseBlock();
// 线程数不等1并且没有使用块下载,则认为没有使用动态文件
@ -153,13 +158,13 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
* 1总线程数为1并且是新任务
* 2总线程数为1不是新任务但是长度不是文件全长度
*/
if (mTotalThreadNum == 1 && (mTaskEntity.getEntity().getFileSize() != mTempFile.length())) {
if (mTotalThreadNum == 1 && (mTaskWrapper.getEntity().getFileSize() != mTempFile.length())) {
mRecord.isOpenDynamicFile = true;
}
onPostPre();
if (!mTaskEntity.isSupportBP()) {
if (!mTaskWrapper.isSupportBP()) {
handleNoSupportBP();
} else {
handleBreakpoint();
@ -256,7 +261,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
task.cancel();
}
}
ThreadTaskManager.getInstance().stopTaskThread(mTaskEntity.getKey());
ThreadTaskManager.getInstance().stopTaskThread(mTaskWrapper.getKey());
}
}).start();
}
@ -278,7 +283,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
task.stop();
}
}
ThreadTaskManager.getInstance().stopTaskThread(mTaskEntity.getKey());
ThreadTaskManager.getInstance().stopTaskThread(mTaskWrapper.getKey());
}
}).start();
}
@ -305,7 +310,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
if (mConfigFile.exists()) {
convertDb();
} else {
mRecord = DbDataHelper.getTaskRecord(mTaskEntity.getKey());
mRecord = DbDataHelper.getTaskRecord(getFilePath());
if (mRecord == null) {
initRecord(true);
} else {
@ -335,7 +340,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
if (mRecord.isOpenDynamicFile) {
ThreadRecord tr = mRecord.threadRecords.get(0);
if (tr == null) {
mTaskEntity.setNewTask(true);
mTaskWrapper.setNewTask(true);
mTotalThreadNum = 1;
return;
}
@ -363,7 +368,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
}
}
mTotalThreadNum = mRecord.threadRecords.size();
mTaskEntity.setNewTask(false);
mTaskWrapper.setNewTask(false);
}
/**
@ -412,7 +417,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
i++;
}
mTotalThreadNum = mRecord.threadRecords.size();
mTaskEntity.setNewTask(false);
mTaskWrapper.setNewTask(false);
}
/**
@ -421,11 +426,11 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
private void convertDb() {
List<RecordWrapper> records =
DbEntity.findRelationData(RecordWrapper.class, "TaskRecord.filePath=?",
mTaskEntity.getKey());
getFilePath());
if (records == null || records.size() == 0) {
Properties pro = CommonUtil.loadConfig(mConfigFile);
if (pro.isEmpty()) {
mTaskEntity.setNewTask(true);
mTaskWrapper.setNewTask(true);
return;
}
initRecord(false);
@ -440,7 +445,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
}
int threadNum = set.size();
if (threadNum == 0) {
mTaskEntity.setNewTask(true);
mTaskWrapper.setNewTask(true);
return;
}
mRecord.threadNum = threadNum;
@ -474,15 +479,23 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
private void initRecord(boolean isNewTask) {
mRecord = new TaskRecord();
mRecord.fileName = mEntity.getFileName();
mRecord.filePath = mTaskEntity.getKey();
mRecord.filePath = getFilePath();
mRecord.threadRecords = new ArrayList<>();
mRecord.isGroupRecord = mTaskEntity.getEntity().isGroupChild();
mRecord.isGroupRecord = mTaskWrapper.getEntity().isGroupChild();
if (mRecord.isGroupRecord) {
if (mTaskEntity.getEntity() instanceof DownloadEntity) {
mRecord.dGroupName = ((DownloadEntity) mTaskEntity.getEntity()).getGroupName();
if (mTaskWrapper.getEntity() instanceof DownloadEntity) {
mRecord.dGroupHash = ((DownloadEntity) mTaskWrapper.getEntity()).getGroupHash();
}
}
mTaskWrapper.setNewTask(isNewTask);
}
private String getFilePath() {
if (getType() == DOWNLOAD) {
return ((DownloadEntity) mTaskWrapper.getEntity()).getDownloadPath();
} else {
return ((UploadEntity) mTaskWrapper.getEntity()).getFilePath();
}
mTaskEntity.setNewTask(isNewTask);
}
/**
@ -507,7 +520,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
*/
private boolean resumeRecordLocation(int i, long startL, long endL) {
mConstance.CURRENT_LOCATION += endL - startL;
ALog.d(TAG, String.format("任务【%s】线程__%s__已完成", mTaskEntity.getEntity().getFileName(), i));
ALog.d(TAG, String.format("任务【%s】线程__%s__已完成", mTaskWrapper.getEntity().getFileName(), i));
mConstance.COMPLETE_THREAD_NUM = mCompleteThreadNum;
mConstance.STOP_NUM++;
mConstance.CANCEL_NUM++;
@ -530,7 +543,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
*/
private AbsThreadTask createSingThreadTask(int i, long startL, long endL, long fileLength,
ThreadRecord record) {
SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>();
SubThreadConfig<TASK_WRAPPER> config = new SubThreadConfig<>();
config.TOTAL_FILE_SIZE = fileLength;
config.URL = mEntity.isRedirect() ? mEntity.getRedirectUrl() : mEntity.getUrl();
config.TEMP_FILE =
@ -538,8 +551,8 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
config.THREAD_ID = i;
config.START_LOCATION = startL;
config.END_LOCATION = endL;
config.SUPPORT_BP = mTaskEntity.isSupportBP();
config.TASK_ENTITY = mTaskEntity;
config.SUPPORT_BP = mTaskWrapper.isSupportBP();
config.TASK_ENTITY = mTaskWrapper;
config.THREAD_RECORD = record;
return selectThreadTask(config);
}
@ -550,14 +563,14 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
Set<Integer> threads = new HashSet<>();
mRecord.fileLength = fileLength;
if (mTaskEntity.isNewTask() && !handleNewTask()) {
if (mTaskWrapper.isNewTask() && !handleNewTask()) {
return;
}
for (int i = 0; i < mTotalThreadNum; i++) {
long startL = i * blockSize, endL = (i + 1) * blockSize;
ThreadRecord tr;
boolean isNewTr = false; // 是否是新的线程记录
if (mTaskEntity.isNewTask()) {
if (mTaskWrapper.isNewTask()) {
tr = new ThreadRecord();
tr.key = mRecord.filePath;
tr.threadId = i;
@ -625,7 +638,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
}
for (int l : recordL) {
if (l == -1) continue;
ThreadTaskManager.getInstance().startThread(mTaskEntity.getKey(), mTask.get(l));
ThreadTaskManager.getInstance().startThread(mTaskWrapper.getKey(), mTask.get(l));
}
}
@ -651,15 +664,15 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
if (mListener instanceof BaseDListener) {
((BaseDListener) mListener).supportBreakpoint(false);
}
SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>();
SubThreadConfig<TASK_WRAPPER> config = new SubThreadConfig<>();
config.TOTAL_FILE_SIZE = mEntity.getFileSize();
config.URL = mEntity.isRedirect() ? mEntity.getRedirectUrl() : mEntity.getUrl();
config.TEMP_FILE = mTempFile;
config.THREAD_ID = 0;
config.START_LOCATION = 0;
config.END_LOCATION = config.TOTAL_FILE_SIZE;
config.SUPPORT_BP = mTaskEntity.isSupportBP();
config.TASK_ENTITY = mTaskEntity;
config.SUPPORT_BP = mTaskWrapper.isSupportBP();
config.TASK_ENTITY = mTaskWrapper;
ThreadRecord record = DbEntity.findFirst(ThreadRecord.class, "key=?", mRecord.filePath);
if (record != null) {
record.deleteData();
@ -674,14 +687,14 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
if (task == null) return;
mTask.put(0, task);
saveRecord();
ThreadTaskManager.getInstance().startThread(mTaskEntity.getKey(), task);
ThreadTaskManager.getInstance().startThread(mTaskWrapper.getKey(), task);
mListener.onStart(0);
}
/**
* 选择单任务线程的类型
*/
protected abstract AbsThreadTask selectThreadTask(SubThreadConfig<TASK_ENTITY> config);
protected abstract AbsThreadTask selectThreadTask(SubThreadConfig<TASK_WRAPPER> config);
/**
* 任务是否已经中断

@ -64,15 +64,15 @@ public class TaskRecord extends DbEntity {
/**
* 下载任务组名
*/
@Foreign(parent = DownloadGroupEntity.class, column = "groupName", onUpdate = ActionPolicy.CASCADE, onDelete = ActionPolicy.CASCADE)
public String dGroupName;
@Foreign(parent = DownloadGroupEntity.class, column = "groupHash", onUpdate = ActionPolicy.CASCADE, onDelete = ActionPolicy.CASCADE)
public String dGroupHash;
/**
* 上传组任务名暂时没有用
*/
@Ignore
@Deprecated
public String uGroupName;
public String uGroupHash;
/**
* 是否是分块{@code true}{@code false} 不是

@ -35,7 +35,7 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
/**
* 组任务名
*/
String mGroupName;
String mGroupHash;
/**
* 文件夹临时路径
*/
@ -71,7 +71,7 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
}
@Override public boolean taskExists() {
return DownloadGroupTaskQueue.getInstance().getTask(mEntity.getGroupName()) != null;
return DownloadGroupTaskQueue.getInstance().getTask(mEntity.getGroupHash()) != null;
}
/**
@ -134,7 +134,6 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
file.renameTo(new File(newPath));
}
de.setDownloadPath(newPath);
dte.setKey(newPath);
des.add(de);
}
AbsEntity.saveAll(des);

@ -171,7 +171,6 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
File newFile = new File(filePath);
mEntity.setDownloadPath(filePath);
mEntity.setFileName(newFile.getName());
mTaskWrapper.setKey(filePath);
if (oldFile.exists()) {
oldFile.renameTo(newFile);
CommonUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath());
@ -201,7 +200,6 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
}
if (!TextUtils.isEmpty(newUrl)) {
mEntity.setUrl(newUrl);
mTaskWrapper.setUrl(newUrl);
}
return true;
}

@ -31,7 +31,7 @@ public class DGEntityWrapper extends AbsWrapper {
@One
public DownloadGroupEntity groupEntity;
@Many(parentColumn = "groupName", entityColumn = "groupName")
@Many(parentColumn = "groupHash", entityColumn = "groupHash")
public List<DownloadEntity> subEntity;
@Override protected void handleConvert() {

@ -25,8 +25,6 @@ public class DGTaskWrapper extends AbsGroupTaskWrapper<DownloadGroupEntity, DTas
private List<DTaskWrapper> subTaskEntities;
private String key;
public DGTaskWrapper(DownloadGroupEntity entity) {
super(entity);
}
@ -36,12 +34,11 @@ public class DGTaskWrapper extends AbsGroupTaskWrapper<DownloadGroupEntity, DTas
this.subTaskEntities = subTaskEntities;
}
/**
* 组名
*/
@Override public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
return getEntity().getKey();
}
@Override public List<DTaskWrapper> getSubTaskWrapper() {

@ -22,56 +22,37 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper;
*/
public class DTaskWrapper extends AbsTaskWrapper<DownloadEntity> {
/**
* 任务的url
*/
private String url;
/**
* 所属的任务组组名如果不属于任务组则为null
*/
private String groupName;
private String groupHash;
/**
* 该任务是否属于任务组
*/
private boolean isGroupTask = false;
/**
* Task实体对应的key
*/
private String key;
public DTaskWrapper(DownloadEntity entity) {
super(entity);
}
/**
* Task实体对应的key下载url
*/
@Override public String getKey() {
return key;
}
@Override public void setKey(String key) {
this.key = key;
return getEntity().getKey();
}
public String getUrl() {
return url;
}
public String getGroupName() {
return groupName;
public String getGroupHash() {
return groupHash;
}
public boolean isGroupTask() {
return isGroupTask;
}
public void setUrl(String url) {
this.url = url;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
public void setGroupHash(String groupHash) {
this.groupHash = groupHash;
}
public void setGroupTask(boolean groupTask) {

@ -36,9 +36,9 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
/**
* 所属任务组
*/
@Foreign(parent = DownloadGroupEntity.class, column = "groupName",
@Foreign(parent = DownloadGroupEntity.class, column = "groupHash",
onUpdate = ActionPolicy.CASCADE, onDelete = ActionPolicy.CASCADE)
private String groupName;
private String groupHash;
/**
* 从服务器的返回信息中获取的文件md5信息如果服务器没有返回则不会设置该信息
@ -91,12 +91,12 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
this.serverFileName = serverFileName;
}
public String getGroupName() {
return groupName;
public String getGroupHash() {
return groupHash;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
public void setGroupHash(String groupHash) {
this.groupHash = groupHash;
}
public String getDownloadPath() {
@ -119,7 +119,7 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
@Override public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeString(this.downloadPath);
dest.writeString(this.groupName);
dest.writeString(this.groupHash);
dest.writeString(this.md5Code);
dest.writeString(this.disposition);
dest.writeString(this.serverFileName);
@ -130,8 +130,8 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
+ "downloadPath='"
+ downloadPath
+ '\''
+ ", groupName='"
+ groupName
+ ", groupHash='"
+ groupHash
+ '\''
+ ", md5Code='"
+ md5Code
@ -148,7 +148,7 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
protected DownloadEntity(Parcel in) {
super(in);
this.downloadPath = in.readString();
this.groupName = in.readString();
this.groupHash = in.readString();
this.md5Code = in.readString();
this.disposition = in.readString();
this.serverFileName = in.readString();

@ -39,8 +39,8 @@ public class DownloadGroupEntity extends AbsGroupEntity {
this.subEntities = subTasks;
}
public void setGroupName(String key) {
this.groupName = key;
public void setGroupHash(String key) {
this.groupHash = key;
}
@Override public int getTaskType() {

@ -66,7 +66,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
}
private void init() {
mGroupName = CommonUtil.getMd5Code(mUrls);
mGroupHash = CommonUtil.getMd5Code(mUrls);
mTaskWrapper = TaskWrapperManager.getInstance().getDGTaskWrapper(DGTaskWrapper.class, mUrls);
mEntity = mTaskWrapper.getEntity();
if (mEntity != null) {
@ -97,13 +97,12 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
}
mUrls.clear();
mUrls.addAll(urls);
mGroupName = CommonUtil.getMd5Code(urls);
mEntity.setGroupName(mGroupName);
mTaskWrapper.setKey(mGroupName);
mGroupHash = CommonUtil.getMd5Code(urls);
mEntity.setGroupHash(mGroupHash);
mEntity.update();
if (mEntity.getSubEntities() != null && !mEntity.getSubEntities().isEmpty()) {
for (DownloadEntity de : mEntity.getSubEntities()) {
de.setGroupName(mGroupName);
de.setGroupHash(mGroupHash);
de.update();
}
}
@ -262,7 +261,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
}
}
mEntity.setGroupName(CommonUtil.getMd5Code(mUrls));
mEntity.setGroupHash(CommonUtil.getMd5Code(mUrls));
return true;
}
@ -288,7 +287,6 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
CommonUtil.modifyTaskRecord(oldFile.getPath(), newPath);
entity.setDownloadPath(newPath);
taskEntity.setKey(newPath);
entity.setFileName(newName);
entity.update();
}

@ -54,7 +54,7 @@ public class DownloadGroupTask extends AbsGroupTask<DownloadGroupEntity, DGTaskW
@Override public String getTaskName() {
return "任务组->" + (TextUtils.isEmpty(mTaskWrapper.getEntity().getAlias())
? mTaskWrapper.getEntity().getGroupName() : mTaskWrapper.getEntity().getAlias());
? mTaskWrapper.getEntity().getGroupHash() : mTaskWrapper.getEntity().getAlias());
}
@Override public int getTaskType() {

@ -274,7 +274,7 @@ public class DownloadReceiver extends AbsReceiver {
return null;
}
boolean b =
DownloadGroupEntity.findFirst(DownloadGroupEntity.class, "groupName=?", dirUrl) != null;
DownloadGroupEntity.findFirst(DownloadGroupEntity.class, "groupHash=?", dirUrl) != null;
if (!b) {
return null;
}
@ -299,8 +299,8 @@ public class DownloadReceiver extends AbsReceiver {
if (urls == null || urls.isEmpty()) {
return false;
}
String groupName = CommonUtil.getMd5Code(urls);
return DbEntity.checkDataExist(DownloadGroupEntity.class, "groupName=?", groupName);
String groupHash = CommonUtil.getMd5Code(urls);
return DbEntity.checkDataExist(DownloadGroupEntity.class, "groupHash=?", groupHash);
}
/**

@ -40,7 +40,7 @@ public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget>
}
private void init(String key) {
mGroupName = key;
mGroupHash = key;
mTaskWrapper = TaskWrapperManager.getInstance().getFtpTaskWrapper(DGTaskWrapper.class, key);
mTaskWrapper.setRequestType(AbsTaskWrapper.D_FTP_DIR);
mEntity = mTaskWrapper.getEntity();
@ -97,7 +97,7 @@ public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget>
* @return {@code true}地址合法
*/
private boolean checkUrl() {
final String url = mGroupName;
final String url = mGroupHash;
if (TextUtils.isEmpty(url)) {
ALog.e(TAG, "下载失败,url为null");
return false;

@ -89,7 +89,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
private int mStopNum = 0;
//任务组大小
int mGroupSize = 0;
private long mUpdateInterval = 1000;
private long mUpdateInterval;
private boolean isStop = false, isCancel = false;
AbsGroupUtil(IDownloadGroupListener listener, DGTaskWrapper groupEntity) {
@ -275,13 +275,13 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
mCompleteNum++;
mCurrentLocation += te.getEntity().getFileSize();
} else {
mExeMap.put(te.getUrl(), te);
mExeMap.put(te.getKey(), te);
mCurrentLocation += file.exists() ? te.getEntity().getCurrentProgress() : 0;
}
if (isNeedLoadFileSize) {
mTotalLen += te.getEntity().getFileSize();
}
mTasksMap.put(te.getUrl(), te);
mTasksMap.put(te.getGroupHash(), te);
}
}
@ -390,7 +390,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
* 子任务事件监听
*/
private class ChildDownloadListener implements IDownloadListener {
private DTaskWrapper subTaskEntity;
private DTaskWrapper subTaskWrapper;
private DownloadEntity subEntity;
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
private long lastSaveTime;
@ -399,12 +399,12 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
private boolean isNotNetRetry;
ChildDownloadListener(DTaskWrapper entity) {
subTaskEntity = entity;
subEntity = subTaskEntity.getEntity();
subTaskWrapper = entity;
subEntity = subTaskWrapper.getEntity();
subEntity.setFailNum(0);
lastLen = subEntity.getCurrentProgress();
lastSaveTime = System.currentTimeMillis();
isNotNetRetry = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().isNotNetRetry();
isNotNetRetry = AriaManager.getInstance(AriaManager.APP).getAppConfig().isNotNetRetry();
}
@Override public void onPre() {
@ -504,7 +504,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
ALog.d(TAG, "downloader retry");
reStartTask(dt);
} else {
mFailMap.put(subTaskEntity.getUrl(), subTaskEntity);
mFailMap.put(subTaskWrapper.getKey(), subTaskWrapper);
mListener.onSubFail(subEntity, new TaskException(TAG,
String.format("任务组子任务【%s】下载失败,下载地址【%s】", subEntity.getFileName(),
subEntity.getUrl())));
@ -513,7 +513,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
}
if (mFailMap.size() == mGroupSize) {
mListener.onFail(true, new TaskException(TAG,
String.format("任务组【%s】下载失败", mGTWrapper.getEntity().getGroupName())));
String.format("任务组【%s】下载失败", mGTWrapper.getEntity().getGroupHash())));
} else if (mFailMap.size() + mCompleteNum >= mExeMap.size()) {
mListener.onStop(mCurrentLocation);
}
@ -543,7 +543,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
}
private void saveData(int state, long location) {
subTaskEntity.setState(state);
subTaskWrapper.setState(state);
subEntity.setState(state);
subEntity.setComplete(state == IEntity.STATE_COMPLETE);
if (state == IEntity.STATE_CANCEL) {

@ -88,7 +88,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
if (mExeMap.size() == 0) {
mListener.onFail(false, new TaskException(TAG,
String.format("任务组【%s】无可执行任务", mGTWrapper.getEntity().getGroupName())));
String.format("任务组【%s】无可执行任务", mGTWrapper.getEntity().getGroupHash())));
return;
}
Set<String> keys = mExeMap.keySet();
@ -172,7 +172,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
if (mInitFailNum == mExeNum) {
closeTimer();
mListener.onFail(true, new TaskException(TAG,
String.format("任务组【%s】初始化失败", mGTWrapper.getEntity().getGroupName())));
String.format("任务组【%s】初始化失败", mGTWrapper.getEntity().getGroupHash())));
}
if (!isStart && mInitCompleteNum + mInitFailNum == mExeNum || !isNeedLoadFileSize) {
startRunningFlow();

@ -48,8 +48,8 @@ class Downloader extends AbsFileer<DownloadEntity, DTaskWrapper> {
return
// 小于1m的文件或是任务组的子任务、使用虚拟文件,线程数都是1
mEntity.getFileSize() <= SUB_LEN
|| mTaskEntity.getRequestType() == AbsTaskWrapper.D_FTP_DIR
|| mTaskEntity.getRequestType() == AbsTaskWrapper.DG_HTTP
|| mTaskWrapper.getRequestType() == AbsTaskWrapper.D_FTP_DIR
|| mTaskWrapper.getRequestType() == AbsTaskWrapper.DG_HTTP
|| threadNum == 1
? 1
: threadNum;
@ -86,6 +86,10 @@ class Downloader extends AbsFileer<DownloadEntity, DTaskWrapper> {
return false;
}
@Override protected int getType() {
return DOWNLOAD;
}
@Override protected void onPostPre() {
super.onPostPre();
((IDownloadListener) mListener).onPostPre(mEntity.getFileSize());
@ -96,7 +100,7 @@ class Downloader extends AbsFileer<DownloadEntity, DTaskWrapper> {
}
@Override protected AbsThreadTask selectThreadTask(SubThreadConfig<DTaskWrapper> config) {
switch (mTaskEntity.getRequestType()) {
switch (mTaskWrapper.getRequestType()) {
case AbsTaskWrapper.D_FTP:
case AbsTaskWrapper.D_FTP_DIR:
return new FtpThreadTask(mConstance, (IDownloadListener) mListener, config);

@ -67,25 +67,23 @@ class FtpDirInfoThread extends AbsFtpInfoThread<DownloadGroupEntity, DGTaskWrapp
: remotePath.substring(lastIndex + 1);
entity.setFileName(
new String(fileName.getBytes(), Charset.forName(mTaskWrapper.asHttp().getCharSet())));
entity.setGroupName(mEntity.getGroupName());
entity.setGroupHash(mEntity.getGroupHash());
entity.setGroupChild(true);
entity.setFileSize(ftpFile.getSize());
entity.insert();
DTaskWrapper taskEntity = new DTaskWrapper(entity);
taskEntity.setKey(entity.getDownloadPath());
taskEntity.setUrl(entity.getUrl());
taskEntity.setGroupTask(true);
taskEntity.setGroupName(mEntity.getGroupName());
taskEntity.setRequestType(AbsTaskWrapper.D_FTP);
DTaskWrapper taskWrapper = new DTaskWrapper(entity);
taskWrapper.setGroupTask(true);
taskWrapper.setGroupHash(mEntity.getGroupHash());
taskWrapper.setRequestType(AbsTaskWrapper.D_FTP);
urlEntity.url = entity.getUrl();
urlEntity.remotePath = remotePath;
taskEntity.asFtp().setUrlEntity(urlEntity);
taskWrapper.asFtp().setUrlEntity(urlEntity);
if (mEntity.getUrls() == null) {
mEntity.setUrls(new ArrayList<String>());
}
mEntity.getSubEntities().add(entity);
mTaskWrapper.getSubTaskWrapper().add(taskEntity);
mTaskWrapper.getSubTaskWrapper().add(taskWrapper);
}
}

@ -50,7 +50,7 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DTaskWrapper> {
mConnectTimeOut = mAridManager.getDownloadConfig().getConnectTimeOut();
mReadTimeOut = mAridManager.getDownloadConfig().getIOTimeOut();
mBufSize = mAridManager.getDownloadConfig().getBuffSize();
isNotNetRetry = mAridManager.getDownloadConfig().isNotNetRetry();
isNotNetRetry = mAridManager.getAppConfig().isNotNetRetry();
isOpenDynamicFile = STATE.TASK_RECORD.isOpenDynamicFile;
isBlock = STATE.TASK_RECORD.isBlock;
}

@ -251,7 +251,6 @@ class HttpFileInfoThread implements Runnable {
}
mEntity.setFileName(newName);
mEntity.setDownloadPath(newPath);
mTaskWrapper.setKey(newPath);
}
/**

@ -58,7 +58,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DTaskWrapper> {
mConnectTimeOut = mAridManager.getDownloadConfig().getConnectTimeOut();
mReadTimeOut = mAridManager.getDownloadConfig().getIOTimeOut();
mBufSize = mAridManager.getDownloadConfig().getBuffSize();
isNotNetRetry = mAridManager.getDownloadConfig().isNotNetRetry();
isNotNetRetry = mAridManager.getAppConfig().isNotNetRetry();
isOpenDynamicFile = STATE.TASK_RECORD.isOpenDynamicFile;
isBlock = STATE.TASK_RECORD.isBlock;
}

@ -173,6 +173,10 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable,
/**
* 实体唯一标识符
* 下载实体下载url
* 上传实体文件路径
* 下载任务组组名
* ftp文件夹下载下载url
*/
public abstract String getKey();

@ -28,7 +28,7 @@ public abstract class AbsGroupEntity extends AbsEntity implements Parcelable {
/**
* 组名组名为任务地址相加的url的Md5
*/
@Primary protected String groupName;
@Primary protected String groupHash;
/**
* 任务组别名
@ -61,8 +61,8 @@ public abstract class AbsGroupEntity extends AbsEntity implements Parcelable {
this.urls = urls;
}
public String getGroupName() {
return groupName;
public String getGroupHash() {
return groupHash;
}
public String getAlias() {
@ -70,7 +70,7 @@ public abstract class AbsGroupEntity extends AbsEntity implements Parcelable {
}
@Override public String getKey() {
return groupName;
return groupHash;
}
public void setAlias(String alias) {
@ -86,13 +86,13 @@ public abstract class AbsGroupEntity extends AbsEntity implements Parcelable {
@Override public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeString(this.groupName);
dest.writeString(this.groupHash);
dest.writeString(this.alias);
}
protected AbsGroupEntity(Parcel in) {
super(in);
this.groupName = in.readString();
this.groupHash = in.readString();
this.alias = in.readString();
}
}

@ -78,8 +78,6 @@ public abstract class AbsTaskWrapper<ENTITY extends AbsEntity>
public abstract String getKey();
public abstract void setKey(String key);
@Override public ENTITY getEntity() {
return entity;
}
@ -131,6 +129,7 @@ public abstract class AbsTaskWrapper<ENTITY extends AbsEntity>
public void setState(int state) {
this.state = state;
entity.setState(state);
}
public int getRequestType() {

@ -19,11 +19,8 @@ import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DGEntityWrapper;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.DbDataHelper;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -46,19 +43,16 @@ class DGTaskWrapperFactory implements IGTEFactory<DownloadGroupEntity, DGTaskWra
return INSTANCE;
}
@Override public DGTaskWrapper getGTE(String groupName, List<String> urls) {
DownloadGroupEntity entity = DbDataHelper.getHttpDGEntity(groupName, urls);
@Override public DGTaskWrapper getGTE(String groupHash, List<String> urls) {
DownloadGroupEntity entity = DbDataHelper.getHttpDGEntity(groupHash, urls);
DGTaskWrapper wrapper = new DGTaskWrapper(entity);
wrapper.setSubTaskWrapper(createDGSubTaskWrapper(entity));
wrapper.setKey(entity.getGroupName());
return wrapper;
}
@Override public DGTaskWrapper getFTE(String ftpUrl) {
DownloadGroupEntity entity = DbDataHelper.getFtpDGEntity(ftpUrl);
DGTaskWrapper fte = new DGTaskWrapper(entity);
fte.setKey(ftpUrl);
fte.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(ftpUrl));
if (fte.getEntity().getSubEntities() == null) {
@ -77,10 +71,8 @@ class DGTaskWrapperFactory implements IGTEFactory<DownloadGroupEntity, DGTaskWra
List<DTaskWrapper> list = new ArrayList<>();
for (DownloadEntity entity : dge.getSubEntities()) {
DTaskWrapper taskEntity = new DTaskWrapper(entity);
taskEntity.setKey(entity.getDownloadPath());
taskEntity.setGroupName(dge.getKey());
taskEntity.setGroupHash(dge.getKey());
taskEntity.setGroupTask(true);
taskEntity.setUrl(entity.getUrl());
list.add(taskEntity);
}
return list;

@ -46,10 +46,7 @@ class DTaskWrapperFactory implements INormalTEFactory<DownloadEntity, DTaskWrapp
* 通过下载实体创建任务实体
*/
private DTaskWrapper create(DownloadEntity entity) {
DTaskWrapper wrapper = new DTaskWrapper(entity);
wrapper.setKey(entity.getDownloadPath());
wrapper.setUrl(entity.getUrl());
return wrapper;
return new DTaskWrapper(entity);
}
/**
@ -72,7 +69,7 @@ class DTaskWrapperFactory implements INormalTEFactory<DownloadEntity, DTaskWrapp
entity = new DownloadEntity();
entity.setUrl(downloadUrl);
entity.setGroupChild(false);
entity.setGroupName(null);
entity.setGroupHash(null);
entity.setDownloadPath(UUID.randomUUID().toString().replace("-", "")); //设置临时路径
}
File file = new File(entity.getDownloadPath());

@ -30,10 +30,10 @@ interface IGTEFactory<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskWrapp
* 1创建实体和任务实体之间的关联
* 2如果在数据库中查找不到对应的数据则新创建任务实体
*
* @param groupName 任务组名
* @param groupHash 任务组名
* @param urls 子任务的下载地址
*/
TASK_ENTITY getGTE(String groupName, List<String> urls);
TASK_ENTITY getGTE(String groupHash, List<String> urls);
/**
* 获取FTP文件夹的任务实体该方法需要以下操作

@ -130,16 +130,16 @@ public class TaskWrapperManager {
final Lock lock = this.lock;
lock.lock();
try {
String groupName = CommonUtil.getMd5Code(urls);
AbsTaskWrapper tWrapper = cache.get(convertKey(groupName));
String groupHash = CommonUtil.getMd5Code(urls);
AbsTaskWrapper tWrapper = cache.get(convertKey(groupHash));
if (tWrapper == null || tWrapper.getClass() != clazz) {
IGTEFactory factory = chooseGroupFactory(clazz);
if (factory == null) {
ALog.e(TAG, "任务实体创建失败");
return null;
}
tWrapper = factory.getGTE(groupName, urls);
cache.put(convertKey(groupName), tWrapper);
tWrapper = factory.getGTE(groupHash, urls);
cache.put(convertKey(groupHash), tWrapper);
}
return (TE) tWrapper;
} finally {

@ -40,9 +40,7 @@ class UTaskWrapperFactory implements INormalTEFactory<UploadEntity, UTaskWrapper
}
private UTaskWrapper create(UploadEntity entity) {
UTaskWrapper wrapper = new UTaskWrapper(entity);
wrapper.setKey(entity.getFilePath());
return wrapper;
return new UTaskWrapper(entity);
}
@Override public UTaskWrapper create(String key) {

@ -16,14 +16,18 @@
package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.TaskSchedulerType;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.pool.BaseCachePool;
import com.arialyy.aria.core.queue.pool.BaseExecutePool;
import com.arialyy.aria.core.queue.pool.DownloadSharePool;
import com.arialyy.aria.core.queue.pool.UploadSharePool;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.util.ALog;
import java.util.Map;
import java.util.Set;
@ -31,8 +35,8 @@ import java.util.Set;
/**
* Created by lyy on 2017/2/23. 任务队列
*/
abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskWrapper>
implements ITaskQueue<TASK, TASK_ENTITY> {
public abstract class AbsTaskQueue<TASK extends AbsTask, TASK_WRAPPER extends AbsTaskWrapper>
implements ITaskQueue<TASK, TASK_WRAPPER> {
final int TYPE_D_QUEUE = 1;
final int TYPE_DG_QUEUE = 2;
final int TYPE_U_QUEUE = 3;
@ -114,9 +118,9 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskWra
}
/**
* 获取配置文件配置的最大可执行任务数
* 获取配置文件旧的最大任务数
*/
public abstract int getConfigMaxNum();
public abstract int getOldMaxNum();
/**
* 获取任务执行池
@ -151,7 +155,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskWra
}
@Override public void setMaxTaskNum(int downloadNum) {
int oldMaxSize = getConfigMaxNum();
int oldMaxSize = getOldMaxNum();
int diff = downloadNum - oldMaxSize;
if (oldMaxSize == downloadNum) {
ALog.w(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过");
@ -177,6 +181,15 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskWra
}
}
@Override public TASK createTask(TASK_WRAPPER wrapper) {
TaskWrapperManager.getInstance().addTaskWrapper(wrapper);
return null;
}
@Override public boolean taskExists(String key) {
return getTask(key) != null;
}
@Override public TASK getTask(String key) {
TASK task = mExecutePool.getTask(key);
if (task == null) {
@ -185,13 +198,27 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskWra
return task;
}
/**
* 添加等待中的任务
*
* @param task {@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}
*/
void addTask(TASK task) {
if (!mCachePool.taskExits(task.getKey())) {
mCachePool.putTask(task);
}
}
@Override public void startTask(TASK task) {
if (mExecutePool.putTask(task)) {
if (mExecutePool.taskExits(task.getKey())) {
ALog.w(TAG, String.format("任务【%s】执行中", task.getKey()));
return;
}
mCachePool.removeTask(task);
mExecutePool.putTask(task);
task.getTaskWrapper().getEntity().setFailNum(0);
task.start();
}
}
@Override public void stopTask(TASK task) {
int state = task.getState();

@ -23,8 +23,7 @@ import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
import com.arialyy.aria.util.ALog;
/**
* Created by AriaL on 2017/6/29.
* 任务组下载队列
* Created by AriaL on 2017/6/29. 任务组下载队列
*/
public class DownloadGroupTaskQueue
extends AbsTaskQueue<DownloadGroupTask, DGTaskWrapper> {
@ -53,19 +52,19 @@ public class DownloadGroupTaskQueue
}
@Override public DownloadGroupTask createTask(DGTaskWrapper wrapper) {
super.createTask(wrapper);
DownloadGroupTask task = null;
if (mCachePool.getTask(wrapper.getEntity().getKey()) == null
&& mExecutePool.getTask(wrapper.getEntity().getKey()) == null) {
if (!mCachePool.taskExits(wrapper.getKey()) && !mExecutePool.taskExits(wrapper.getKey())) {
task = (DownloadGroupTask) TaskFactory.getInstance()
.createTask(wrapper, DownloadGroupSchedulers.getInstance());
mCachePool.putTask(task);
addTask(task);
} else {
ALog.w(TAG, "任务已存在");
}
return task;
}
@Override public int getConfigMaxNum() {
@Override public int getOldMaxNum() {
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum;
}
}

@ -50,7 +50,7 @@ public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DTaskWrapper>
return TYPE_D_QUEUE;
}
@Override public int getConfigMaxNum() {
@Override public int getOldMaxNum() {
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum;
}
@ -98,12 +98,12 @@ public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DTaskWrapper>
}
@Override public DownloadTask createTask(DTaskWrapper wrapper) {
super.createTask(wrapper);
DownloadTask task = null;
if (mCachePool.getTask(wrapper.getEntity().getKey()) == null
&& mExecutePool.getTask(wrapper.getEntity().getKey()) == null) {
if (!mCachePool.taskExits(wrapper.getKey()) && !mExecutePool.taskExits(wrapper.getKey())) {
task = (DownloadTask) TaskFactory.getInstance()
.createTask(wrapper, DownloadSchedulers.getInstance());
mCachePool.putTask(task);
addTask(task);
} else {
ALog.w(TAG, "任务已存在");
}

@ -16,6 +16,7 @@
package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.download.DTaskWrapper;
@ -25,11 +26,18 @@ import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.core.upload.UTaskWrapper;
/**
* Created by lyy on 2016/8/16.
* 任务功能接口
* Created by lyy on 2016/8/16. 任务功能接口
*/
public interface ITaskQueue<TASK extends AbsTask, TASK_WRAPPER extends AbsTaskWrapper> {
/**
* 通过key跑断任务是在存在
*
* @param key 下载链接或上传文件的路径
* @return {@code true} 任务存在
*/
boolean taskExists(String key);
/**
* 通过key判断任务是否正在执行
*
@ -39,9 +47,7 @@ public interface ITaskQueue<TASK extends AbsTask, TASK_WRAPPER extends AbsTaskWr
boolean taskIsRunning(String key);
/**
* 恢复任务
* 如果执行队列任务未满则直接启动任务
* 如果执行队列已经满了则暂停执行队列队首任务并恢复指定任务
* 恢复任务 如果执行队列任务未满则直接启动任务 如果执行队列已经满了则暂停执行队列队首任务并恢复指定任务
*
* @param task 需要恢复飞任务
*/
@ -55,21 +61,21 @@ public interface ITaskQueue<TASK extends AbsTask, TASK_WRAPPER extends AbsTaskWr
/**
* 开始任务
*
* @param task {@link DownloadTask}{@link UploadTask}
* @param task {@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}
*/
void startTask(TASK task);
/**
* 停止任务
*
* @param task {@link DownloadTask}{@link UploadTask}
* @param task {@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}
*/
void stopTask(TASK task);
/**
* 取消下载任务
*
* @param task {@link DownloadTask}{@link UploadTask}
* @param task {@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}
*/
void cancelTask(TASK task);
@ -83,7 +89,7 @@ public interface ITaskQueue<TASK extends AbsTask, TASK_WRAPPER extends AbsTaskWr
/**
* 重试下载
*
* @param task {@link DownloadTask}{@link UploadTask}
* @param task {@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}
*/
void reTryStart(TASK task);
@ -110,10 +116,10 @@ public interface ITaskQueue<TASK extends AbsTask, TASK_WRAPPER extends AbsTaskWr
int getMaxTaskNum();
/**
* 创建一个新的任务创建时只是将新任务存储到缓存池
* 创建一个缓存任务创建时只是将新任务存储到缓存池
*
* @param wrapper 任务实体{@link DTaskWrapper}{@link UTaskWrapper}
* @return {@link DownloadTask}{@link UploadTask}
* @param wrapper 任务实体{@link DTaskWrapper}{@link UTaskWrapper}{@link DGTaskWrapper}
* @return {@link DownloadTask}{@link UploadTask}{@link DGTaskWrapper}
*/
TASK createTask(TASK_WRAPPER wrapper);

@ -23,8 +23,7 @@ import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.util.ALog;
/**
* Created by lyy on 2017/2/27.
* 上传任务队列
* Created by lyy on 2017/2/27. 上传任务队列
*/
public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UTaskWrapper> {
private static final String TAG = "UploadTaskQueue";
@ -46,7 +45,7 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UTaskWrapper> {
return TYPE_U_QUEUE;
}
@Override public int getConfigMaxNum() {
@Override public int getOldMaxNum() {
return AriaManager.getInstance(AriaManager.APP).getUploadConfig().oldMaxTaskNum;
}
@ -55,12 +54,12 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UTaskWrapper> {
}
@Override public UploadTask createTask(UTaskWrapper wrapper) {
super.createTask(wrapper);
UploadTask task = null;
if (mCachePool.getTask(wrapper.getEntity().getKey()) == null
&& mExecutePool.getTask(wrapper.getEntity().getKey()) == null) {
if (!mCachePool.taskExits(wrapper.getKey()) && !mExecutePool.taskExits(wrapper.getKey())) {
task = (UploadTask) TaskFactory.getInstance()
.createTask(wrapper, UploadSchedulers.getInstance());
mCachePool.putTask(task);
addTask(task);
} else {
ALog.w(TAG, "任务已存在");
}

@ -29,8 +29,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
/**
* Created by lyy on 2016/8/14.
* 任务缓存池所有下载任务最先缓存在这个池中
* Created by lyy on 2016/8/14. 任务缓存池所有下载任务最先缓存在这个池中
*/
public class BaseCachePool<TASK extends AbsTask> implements IPool<TASK> {
private static final String TAG = "BaseCachePool";
@ -88,7 +87,7 @@ public class BaseCachePool<TASK extends AbsTask> implements IPool<TASK> {
ALog.e(TAG, "任务不能为空!!");
return false;
}
String url = task.getKey();
String key = task.getKey();
if (mCacheQueue.contains(task)) {
ALog.w(TAG, "任务【" + task.getTaskName() + "】进入缓存队列失败,原因:已经在缓存队列中");
return false;
@ -96,7 +95,7 @@ public class BaseCachePool<TASK extends AbsTask> implements IPool<TASK> {
boolean s = mCacheQueue.offer(task);
ALog.d(TAG, "任务【" + task.getTaskName() + "】进入缓存队列" + (s ? "成功" : "失败"));
if (s) {
mCacheMap.put(CommonUtil.keyToHashKey(url), task);
mCacheMap.put(CommonUtil.keyToHashKey(key), task);
}
return s;
}
@ -130,6 +129,10 @@ public class BaseCachePool<TASK extends AbsTask> implements IPool<TASK> {
}
}
@Override public boolean taskExits(String key) {
return mCacheMap.containsKey(CommonUtil.keyToHashKey(key));
}
@Override public boolean removeTask(TASK task) {
synchronized (AriaManager.LOCK) {
if (task == null) {

@ -27,8 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
/**
* Created by lyy on 2016/8/15.
* 任务执行池所有当前下载任务都该任务池中默认下载大小为2
* Created by lyy on 2016/8/15. 任务执行池所有当前下载任务都该任务池中默认下载大小为2
*/
public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
private final String TAG = "BaseExecutePool";
@ -168,6 +167,10 @@ public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
}
}
@Override public boolean taskExits(String key) {
return mExecuteMap.containsKey(CommonUtil.keyToHashKey(key));
}
@Override public boolean removeTask(TASK task) {
synchronized (AriaManager.LOCK) {
if (task == null) {

@ -16,11 +16,11 @@
package com.arialyy.aria.core.queue.pool;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask;
/**
* Created by lyy on 2016/8/14.
* 任务池
* Created by lyy on 2016/8/14. 任务池
*/
interface IPool<T extends AbsTask> {
/**
@ -36,17 +36,25 @@ interface IPool<T extends AbsTask> {
T pollTask();
/**
* 通过下载链接获取下载任务当任务不为空时队列将删除该下载任务
* 通过key获取任务当任务不为空时队列将删除该下载任务
*
* @param downloadUrl 下载链接
* @param key {@link AbsEntity#getKey()}
* @return 返回null或者下载任务
*/
T getTask(String downloadUrl);
T getTask(String key);
/**
* 任务是在存在
*
* @param key {@link AbsEntity#getKey()}
* @return {@code true} 任务存在
*/
boolean taskExits(String key);
/**
* 删除任务池中的下载任务
*
* @param task 下载任务
* @param task {@link AbsTask}
* @return true:移除成功
*/
boolean removeTask(T task);

@ -164,7 +164,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends Ab
}
}
boolean canSend = manager.getDownloadConfig().isUseBroadcast();
boolean canSend = manager.getAppConfig().isUseBroadcast();
if (canSend) {
AriaManager.APP.sendBroadcast(
createData(msg.what, ITask.DOWNLOAD_GROUP_SUB, params.entity));
@ -274,18 +274,16 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends Ab
* 发送普通任务的广播
*/
private void sendNormalBroadcast(int state, TASK task) {
boolean canSend = manager.getAppConfig().isUseBroadcast();
if (!canSend) {
return;
}
if (task.getTaskType() == ITask.DOWNLOAD || task.getTaskType() == ITask.DOWNLOAD_GROUP) {
boolean canSend = manager.getDownloadConfig().isUseBroadcast();
if (canSend) {
AriaManager.APP.sendBroadcast(
createData(state, task.getTaskType(), task.getTaskWrapper().getEntity()));
}
} else if (task.getTaskType() == ITask.UPLOAD) {
boolean canSend = manager.getUploadConfig().isUseBroadcast();
if (canSend) {
AriaManager.APP.sendBroadcast(
createData(state, task.getTaskType(), task.getTaskWrapper().getEntity()));
}
} else {
ALog.w(TAG, "发送广播失败,没有对应的任务");
}
@ -324,15 +322,13 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends Ab
}
long interval = 2000;
int num = 10;
boolean isNotNetRetry = false;
boolean isNotNetRetry = manager.getAppConfig().isNotNetRetry();;
if (task instanceof DownloadTask || task instanceof DownloadGroupTask) {
interval = manager.getDownloadConfig().getReTryInterval();
num = manager.getDownloadConfig().getReTryNum();
isNotNetRetry = manager.getDownloadConfig().isNotNetRetry();
} else if (task instanceof UploadTask) {
interval = manager.getUploadConfig().getReTryInterval();
num = manager.getUploadConfig().getReTryNum();
isNotNetRetry = manager.getUploadConfig().isNotNetRetry();
}
final int reTryNum = num;

@ -116,7 +116,6 @@ abstract class BaseNormalTarget<TARGET extends AbsUploadTarget>
ALog.e(TAG, "上传失败,文件【" + filePath + "】不能是文件夹");
return false;
}
mTaskWrapper.setKey(mEntity.getFilePath());
return true;
}

@ -22,27 +22,14 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper;
*/
public class UTaskWrapper extends AbsTaskWrapper<UploadEntity> {
private String filePath;
private String key;
public UTaskWrapper(UploadEntity entity) {
super(entity);
}
/**
* 文件保存路径
*/
@Override public String getKey() {
return key;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public void setKey(String key) {
this.key = key;
return getEntity().getKey();
}
}

@ -44,7 +44,7 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UTaskWrapper> {
mConnectTimeOut = mAridManager.getUploadConfig().getConnectTimeOut();
mReadTimeOut = mAridManager.getUploadConfig().getIOTimeOut();
mBufSize = mAridManager.getUploadConfig().getBuffSize();
isNotNetRetry = mAridManager.getUploadConfig().isNotNetRetry();
isNotNetRetry = mAridManager.getAppConfig().isNotNetRetry();
}
@Override public int getMaxSpeed() {

@ -57,7 +57,7 @@ class HttpThreadTask extends AbsThreadTask<UploadEntity, UTaskWrapper> {
mConnectTimeOut = mAridManager.getUploadConfig().getConnectTimeOut();
mReadTimeOut = mAridManager.getUploadConfig().getIOTimeOut();
mBufSize = mAridManager.getUploadConfig().getBuffSize();
isNotNetRetry = mAridManager.getUploadConfig().isNotNetRetry();
isNotNetRetry = mAridManager.getAppConfig().isNotNetRetry();
}
@Override public HttpThreadTask call() throws Exception {

@ -42,12 +42,16 @@ class Uploader extends AbsFileer<UploadEntity, UTaskWrapper> {
return true;
}
@Override protected int getType() {
return UPLOAD;
}
@Override protected int setNewTaskThreadNum() {
return 1;
}
@Override protected AbsThreadTask selectThreadTask(SubThreadConfig<UTaskWrapper> config) {
switch (mTaskEntity.getRequestType()) {
switch (mTaskWrapper.getRequestType()) {
case AbsTaskWrapper.U_FTP:
return new FtpThreadTask(mConstance, mListener, config);
case AbsTaskWrapper.U_HTTP:

@ -35,7 +35,7 @@ class DBConfig {
/*adb pull /mnt/sdcard/Android/data/com.arialyy.simple/files/DB/AriaLyyDb d:/db*/
static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME;
static int VERSION = 43;
static int VERSION = 44;
/**
* 是否将数据库保存在Sd卡{@code true}
@ -52,10 +52,7 @@ class DBConfig {
}
static {
mapping.put("DGTaskWrapper", DGTaskWrapper.class);
mapping.put("DownloadGroupEntity", DownloadGroupEntity.class);
mapping.put("DTaskWrapper", DTaskWrapper.class);
mapping.put("UTaskWrapper", UTaskWrapper.class);
mapping.put("DownloadEntity", DownloadEntity.class);
mapping.put("UploadEntity", UploadEntity.class);
mapping.put("TaskRecord", TaskRecord.class);

@ -507,7 +507,7 @@ class DelegateFind extends AbsDelegate {
ALog.e(TAG, "请输入删除条件");
return -1;
} else if (wheres.length != values.length) {
ALog.e(TAG, "groupName 和 vaule 长度不相等");
ALog.e(TAG, "groupHash 和 vaule 长度不相等");
return -1;
}
StringBuilder sb = new StringBuilder();

@ -586,7 +586,7 @@ public class CommonUtil {
return;
}
List<TaskRecord> records =
DbEntity.findDatas(TaskRecord.class, "dGroupName=?", groupEntity.getGroupName());
DbEntity.findDatas(TaskRecord.class, "dGroupHash=?", groupEntity.getGroupHash());
if (records == null || records.isEmpty()) {
ALog.w(TAG, "组任务记录删除失败,记录为null");

@ -48,26 +48,26 @@ public class DbDataHelper {
/**
* 获取组合任务实体 如果数据库不存在该实体则新创建一个新的任务组实体
*
* @param groupName 组合任务名称
* @param groupHash 组合任务名称
* @param urls 子任务url列表
*/
public static DownloadGroupEntity getHttpDGEntity(String groupName, List<String> urls) {
public static DownloadGroupEntity getHttpDGEntity(String groupHash, List<String> urls) {
List<DGEntityWrapper> wrapper =
DbEntity.findRelationData(DGEntityWrapper.class, "DownloadGroupEntity.groupName=?",
groupName);
DbEntity.findRelationData(DGEntityWrapper.class, "DownloadGroupEntity.groupHash=?",
groupHash);
DownloadGroupEntity groupEntity;
if (wrapper != null && !wrapper.isEmpty()) {
groupEntity = wrapper.get(0).groupEntity;
if (groupEntity == null) {
groupEntity = new DownloadGroupEntity();
groupEntity.setSubEntities(createHttpSubTask(groupName, urls));
groupEntity.setSubEntities(createHttpSubTask(groupHash, urls));
}
} else {
groupEntity = new DownloadGroupEntity();
groupEntity.setSubEntities(createHttpSubTask(groupName, urls));
groupEntity.setSubEntities(createHttpSubTask(groupHash, urls));
}
groupEntity.setGroupName(groupName);
groupEntity.setGroupHash(groupHash);
groupEntity.setUrls(urls);
return groupEntity;
}
@ -75,16 +75,16 @@ public class DbDataHelper {
/**
* 创建HTTP子任务实体
*/
private static List<DownloadEntity> createHttpSubTask(String groupName, List<String> urls) {
private static List<DownloadEntity> createHttpSubTask(String groupHash, List<String> urls) {
List<DownloadEntity> list = new ArrayList<>();
for (int i = 0, len = urls.size(); i < len; i++) {
String url = urls.get(i);
DownloadEntity entity = new DownloadEntity();
entity.setUrl(url);
entity.setDownloadPath(groupName + "_" + i);
entity.setDownloadPath(groupHash + "_" + i);
int lastIndex = url.lastIndexOf(File.separator);
entity.setFileName(url.substring(lastIndex + 1));
entity.setGroupName(groupName);
entity.setGroupHash(groupHash);
entity.setGroupChild(true);
list.add(entity);
}
@ -98,7 +98,7 @@ public class DbDataHelper {
*/
public static DownloadGroupEntity getFtpDGEntity(String ftpUrl) {
List<DGEntityWrapper> wrapper =
DbEntity.findRelationData(DGEntityWrapper.class, "DownloadGroupEntity.groupName=?",
DbEntity.findRelationData(DGEntityWrapper.class, "DownloadGroupEntity.groupHash=?",
ftpUrl);
DownloadGroupEntity groupEntity;
if (wrapper != null && !wrapper.isEmpty()) {
@ -109,7 +109,7 @@ public class DbDataHelper {
} else {
groupEntity = new DownloadGroupEntity();
}
groupEntity.setGroupName(ftpUrl);
groupEntity.setGroupHash(ftpUrl);
return groupEntity;
}
}

@ -25,19 +25,19 @@ import java.lang.annotation.Target;
* Aria下载事件被注解的方法中参数仅能有一个参数类型为{@link com.arialyy.aria.core.download.DownloadGroupTask}
* <pre>
* <code>
* {@literal @}DownloadGroup.onPre(groupName)
* {@literal @}DownloadGroup.onPre(groupHash)
* protected void onPre(DownloadGroupTask task) {
* }
* </code>
* </pre>
* {@literal @}Download.onPre("myGroupName")如果你的注解中增加了url描述
* 则表示所有下载任务中只有下载地址为"myGroupName"的任务才能回调该注解的方法
* {@literal @}Download.onPre("mGroupHash")如果你的注解中增加了url描述
* 则表示所有下载任务中只有下载地址为"myGroupHash"的任务才能回调该注解的方法
*
*
* 如果希望获取子任务的状态可以使用onSub..类的注解
* <pre>
* <code>
* {@literal @}DownloadGroup.onSubPre(groupName)
* {@literal @}DownloadGroup.onSubPre(groupHash)
* protected void onPre(DownloadGroupTask task, String url) {
* }
* </code>

@ -1,6 +1,9 @@
## 开发日志
+ v_3.5.5
+ v_3.6
- 优化数据库写入\修改的速度
- 精减任务实体的存储
- 增加下载组合任务的配置
- useBroadcast\notNetRetry这两个配置,统一在AppConfig中
+ v_3.5.4 (2019/1/8)
- 修复不支持断点的下载地址,重复下载出现的数据库主键冲突问题
+ v_3.5.3 (2018/12/23)

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<aria>
<!--注意,修改该配置文件中的属性会覆盖代码中所设置的属性-->
<!--Aria框架配置-->
<app>
<!--是否使用AriaCrashHandler来捕获异常,异常日志保存在:/mnt/sdcard/Android/data/{package_name}/files/log/-->
<useAriaCrashHandler value="true"/>
@ -8,10 +10,15 @@
<logLevel value="2"/>
<!-- 是否检查网络 true: 检查网络,false: 不检查网络-->
<netCheck value="false"/>
<!--除非无法使用注解,否则不建议使用广播来接受任务状态,true:使用广播接收任务状态,false:不适用广播接收状态 -->
<!-- http://aria.laoyuyu.me/aria_doc/api/use_broadcast.html -->
<useBroadcast value="true"/>
<!--断网的时候是否重试,true:断网也重试;false:断网不重试,直接走失败的回调-->
<notNetRetry value="true"/>
</app>
<!--注意,修改该配置文件中的属性会覆盖代码中所设置的属性-->
<!--普通下载任务-->
<download>
<!--设置任务最大下载速度,0表示不限速,单位为:kb-->
@ -27,9 +34,6 @@
-->
<useBlock value="true"/>
<!--断网的时候是否重试,true:断网也重试;false:断网不重试,直接走失败的回调-->
<notNetRetry value="true"/>
<!--设置下载线程数,下载线程数不能小于1
注意:
1、线程下载数改变后,新的下载任务才会生效;
@ -69,17 +73,12 @@
<!--进度更新更新间隔,默认1000毫秒-->
<updateInterval value="1000"/>
<!--除非无法使用注解,否则不建议使用广播来接受任务状态,true:使用广播接收任务状态,false:不适用广播接收状态 -->
<!-- http://aria.laoyuyu.me/aria_doc/api/use_broadcast.html -->
<useBroadcast value="true"/>
</download>
<!--普通上传任务-->
<upload>
<!--设置任务最大上传速度,0表示不限速,单位为:kb-->
<maxSpeed value="0"/>
<!--断网的时候是否重试,true:断网也重试;false:断网不重试,直接走失败的回调-->
<notNetRetry value="false"/>
<!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒-->
<iOTimeOut value="10000"/>
@ -108,9 +107,55 @@
<!--进度更新更新间隔,默认1000毫秒-->
<updateInterval value="1000"/>
<!--除非无法使用注解,否则不建议使用广播来接受任务状态,true:使用广播接收任务状态,false:不适用广播接收状态 -->
<!-- http://aria.laoyuyu.me/aria_doc/api/use_broadcast.html -->
<useBroadcast value="false"/>
</upload>
<!-- 下载类组合任务 -->
<dGroup>
<!--设置任务最大下载速度,0表示不限速,单位为:kb-->
<maxSpeed value="128"/>
<!--组合任务下载队列最大任务数, 默认为2-->
<maxTaskNum value="1"/>
<!--设置下载失败,重试次数,默认为10-->
<reTryNum value="1"/>
<!--设置重试间隔,单位为毫秒,默认2000毫秒-->
<reTryInterval value="5000"/>
<!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait-->
<queueMod value="wait"/>
<!--进度更新更新间隔,默认1000毫秒-->
<updateInterval value="1000"/>
<!-- =============================以下为子任务的配置====================================-->
<!--能同时下载的子任务最大任务数,默认3-->
<subMaxTaskNum value="3"/>
<!--子任务下载失败时的重试次数,默认为5-->
<subReTryNum value="5"/>
<!--子任务下载失败时的重试间隔,单位为毫秒,默认2000毫秒-->
<subReTryInterval value="5000"/>
<!--子任务url连接超时时间,单位为毫秒,默认5000毫秒-->
<connectTimeOut value="5000"/>
<!--子任务IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒-->
<iOTimeOut value="10000"/>
<!--子任务写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢-->
<buffSize value="8192"/>
<!--子任务 https ca 证书信息;path 为assets目录下的CA证书完整路径,name 为CA证书名-->
<ca name="" path=""/>
<!--子任务是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度-->
<convertSpeed value="true"/>
</dGroup>
</aria>

@ -59,8 +59,6 @@ public class DbTestActivity extends BaseActivity<ActivityDbTestBinding> {
entity.setDownloadPath(key);
DTaskWrapper dte = new DTaskWrapper(entity);
dte.setUrl(url);
dte.setKey(key);
datas.add(entity);
}

@ -68,7 +68,7 @@
// private fun startD() {
// Aria.download(this)
// .load(DOWNLOAD_URL)
// .addHeader("groupName", "value")
// .addHeader("groupHash", "value")
// .setDownloadPath(Environment.getExternalStorageDirectory().path + "/hhhhhhhh.apk")
// .start()
// }

@ -18,7 +18,6 @@ package com.arialyy.simple.download.group;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
@ -46,7 +45,7 @@ import java.util.List;
@Bind(R.id.sub_task) TextView mSub;
@Bind(R.id.task_group) TextView mGroup;
@Bind(R.id.pb) HorizontalProgressBarWithNumber mPb;
private String mGroupName;
private String mGroupHash;
private String mChildName;
private List<String> mUrls;
private DownloadEntity mChildEntity;
@ -55,7 +54,7 @@ import java.util.List;
super(context);
setStyle(STYLE_NO_TITLE, R.style.Theme_Light_Dialog);
mChildEntity = childEntity;
mGroupName = "任务组测试";
mGroupHash = "任务组测试";
mUrls = urls;
mChildName = childEntity.getFileName();
}
@ -72,7 +71,7 @@ import java.util.List;
}
private void initWidget() {
mGroup.setText("任务组:" + mGroupName);
mGroup.setText("任务组:" + mGroupHash);
mSub.setText("子任务:" + mChildName);
mPb.setProgress((int) (mChildEntity.getCurrentProgress() * 100 / mChildEntity.getFileSize()));

@ -62,7 +62,7 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
if (entity instanceof DownloadEntity) {
return ((DownloadEntity) entity).getUrl();
} else if (entity instanceof DownloadGroupEntity) {
return ((DownloadGroupEntity) entity).getGroupName();
return ((DownloadGroupEntity) entity).getGroupHash();
}
return "";
}

@ -34,14 +34,17 @@ public final class Configuration {
private static final String DOWNLOAD_CONFIG_FILE = "/Aria/AriaDownload.cfg";
private static final String UPLOAD_CONFIG_FILE = "/Aria/AriaUpload.cfg";
private static final String APP_CONFIG_FILE = "/Aria/AriaApp.cfg";
private static final String DGROUP_CONFIG_FILE = "/Aria/AriaDGroup.cfg";
private static final int TYPE_DOWNLOAD = 1;
private static final int TYPE_UPLOAD = 2;
private static final int TYPE_APP = 3;
private static final int TYPE_DGROUP = 4;
private static volatile Configuration INSTANCE = null;
static final String XML_FILE = "/Aria/aria_config.xml";
DownloadConfig downloadCfg;
UploadConfig uploadCfg;
AppConfig appCfg;
DGroupConfig dGroupCfg;
private Configuration() {
//删除老版本的配置文件
@ -62,6 +65,7 @@ public final class Configuration {
File newDCfg = new File(String.format("%s%s", basePath, DOWNLOAD_CONFIG_FILE));
File newUCfg = new File(String.format("%s%s", basePath, UPLOAD_CONFIG_FILE));
File newACfg = new File(String.format("%s%s", basePath, APP_CONFIG_FILE));
File dgCfg = new File(String.format("%s%s", basePath, DGROUP_CONFIG_FILE));
// 加载下载配置
if (newDCfg.exists()) {
downloadCfg = (DownloadConfig) CommonUtil.readObjFromFile(newDCfg.getPath());
@ -83,6 +87,13 @@ public final class Configuration {
if (appCfg == null) {
appCfg = new AppConfig();
}
// 加载下载类型组合任务的配置
if (dgCfg.exists()) {
dGroupCfg = (DGroupConfig) CommonUtil.readObjFromFile(dgCfg.getPath());
}
if (dGroupCfg == null) {
dGroupCfg = new DGroupConfig();
}
}
static Configuration getInstance() {
@ -95,7 +106,8 @@ public final class Configuration {
}
/**
* 检查配置文件是否存在只要{@link DownloadConfig}{@link UploadConfig}{@link AppConfig}其中一个不存在 则任务配置文件不存在
* 检查配置文件是否存在只要{@link DownloadConfig}{@link UploadConfig}{@link AppConfig}{@link
* DGroupConfig}其中一个不存在 则任务配置文件不存在
*
* @return {@code true}配置存在{@code false}配置不存在
*/
@ -103,7 +115,8 @@ public final class Configuration {
String basePath = AriaManager.APP.getFilesDir().getPath();
return (new File(String.format("%s%s", basePath, DOWNLOAD_CONFIG_FILE))).exists()
&& (new File(String.format("%s%s", basePath, UPLOAD_CONFIG_FILE))).exists()
&& (new File(String.format("%s%s", basePath, APP_CONFIG_FILE))).exists();
&& (new File(String.format("%s%s", basePath, APP_CONFIG_FILE))).exists()
&& (new File(String.format("%s%s", basePath, DGROUP_CONFIG_FILE))).exists();
}
abstract static class BaseConfig implements Serializable {
@ -111,7 +124,7 @@ public final class Configuration {
/**
* 类型
*
* @return {@link #TYPE_DOWNLOAD}{@link #TYPE_UPLOAD}{@link #TYPE_APP}
* @return {@link #TYPE_DOWNLOAD}{@link #TYPE_UPLOAD}{@link #TYPE_APP}{@link #TYPE_DGROUP}
*/
abstract int getType();
@ -191,11 +204,6 @@ public final class Configuration {
*/
String queueMod = "wait";
/**
* 断网的时候是否重试{@code true}断网也重试{@code false}断网不重试直接走失败的回调
*/
boolean notNetRetry = false;
/**
* 设置IO流读取时间单位为毫秒默认20000毫秒该时间不能少于10000毫秒
*/
@ -207,16 +215,37 @@ public final class Configuration {
int maxSpeed = 0;
/**
* 是否使用广播 除非无法使用注解否则不建议使用广播来接受任务 {@code true} 使用广播{@code false} 不适用广播
* 设置https ca 证书信息path 为assets目录下的CA证书完整路径
*/
boolean useBroadcast = false;
String caPath;
/**
* name 为CA证书名
*/
String caName;
public boolean isUseBroadcast() {
return useBroadcast;
public String getCaPath() {
return caPath;
}
public BaseTaskConfig setUseBroadcast(boolean useBroadcast) {
this.useBroadcast = useBroadcast;
public BaseConfig setCaPath(String caPath) {
this.caPath = caPath;
save();
return this;
}
public String getCaName() {
return caName;
}
public BaseConfig setCaName(String caName) {
this.caName = caName;
save();
return this;
}
public BaseTaskConfig setMaxTaskNum(int maxTaskNum) {
oldMaxTaskNum = this.maxTaskNum;
this.maxTaskNum = maxTaskNum;
save();
return this;
}
@ -304,16 +333,6 @@ public final class Configuration {
return this;
}
public boolean isNotNetRetry() {
return notNetRetry;
}
public BaseTaskConfig setNotNetRetry(boolean notNetRetry) {
this.notNetRetry = notNetRetry;
save();
return this;
}
public int getIOTimeOut() {
return iOTimeOut;
}
@ -339,15 +358,6 @@ public final class Configuration {
* 下载配置
*/
public static class DownloadConfig extends BaseTaskConfig implements Serializable {
/**
* 设置https ca 证书信息path 为assets目录下的CA证书完整路径
*/
String caPath;
/**
* name 为CA证书名
*/
String caName;
/**
* 下载线程数下载线程数不能小于1 注意 1线程下载数改变后新的下载任务才会生效 2如果任务大小小于1m该设置不会生效
* 3从3.4.1开始如果线程数为1文件初始化时将不再预占用对应长度的空间下载多少byte则占多大的空间 对于采用多线程的任务或旧任务依然采用原来的文件空间占用方式
@ -367,7 +377,6 @@ public final class Configuration {
@Override public DownloadConfig setMaxSpeed(int maxSpeed) {
super.setMaxSpeed(maxSpeed);
DownloadTaskQueue.getInstance().setMaxSpeed(maxSpeed);
DownloadGroupTaskQueue.getInstance().setMaxSpeed(maxSpeed);
return this;
}
@ -378,10 +387,8 @@ public final class Configuration {
}
public DownloadConfig setMaxTaskNum(int maxTaskNum) {
oldMaxTaskNum = this.maxTaskNum;
this.maxTaskNum = maxTaskNum;
super.setMaxTaskNum(maxTaskNum);
DownloadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum);
save();
return this;
}
@ -391,26 +398,6 @@ public final class Configuration {
return this;
}
public String getCaPath() {
return caPath;
}
public DownloadConfig setCaPath(String caPath) {
this.caPath = caPath;
save();
return this;
}
public String getCaName() {
return caName;
}
public DownloadConfig setCaName(String caName) {
this.caName = caName;
save();
return this;
}
public int getThreadNum() {
return threadNum;
}
@ -440,16 +427,14 @@ public final class Configuration {
}
public UploadConfig setMaxTaskNum(int maxTaskNum) {
oldMaxTaskNum = this.maxTaskNum;
this.maxTaskNum = maxTaskNum;
super.setMaxTaskNum(maxTaskNum);
UploadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum);
save();
return this;
}
static UploadConfig getInstance() {
if (INSTANCE == null) {
synchronized (DownloadConfig.class) {
synchronized (UploadConfig.class) {
INSTANCE = new UploadConfig();
}
}
@ -461,10 +446,91 @@ public final class Configuration {
}
}
/**
* 下载类型的组合任务
*/
public static class DGroupConfig extends BaseTaskConfig implements Serializable {
private static DGroupConfig INSTANCE = null;
/**
* 能同时下载的子任务最大任务数默认3
*/
int subMaxTaskNum = 3;
/**
* 子任务重试次数默认为5
*/
int subReTryNum = 5;
/**
* 子任务下载失败时的重试间隔单位为毫秒默认2000毫秒-
*/
int subReTryInterval = 2000;
private DGroupConfig() {
}
static DGroupConfig getInstance() {
if (INSTANCE == null) {
synchronized (DGroupConfig.class) {
INSTANCE = new DGroupConfig();
}
}
return INSTANCE;
}
@Override int getType() {
return TYPE_DGROUP;
}
@Override public DGroupConfig setMaxSpeed(int maxSpeed) {
super.setMaxSpeed(maxSpeed);
DownloadGroupTaskQueue.getInstance().setMaxSpeed(maxSpeed);
return this;
}
public DGroupConfig setMaxTaskNum(int maxTaskNum) {
super.setMaxTaskNum(maxTaskNum);
DownloadGroupTaskQueue.getInstance().setMaxTaskNum(maxSpeed);
return this;
}
public int getSubMaxTaskNum() {
return subMaxTaskNum;
}
public DGroupConfig setSubMaxTaskNum(int subMaxTaskNum) {
this.subMaxTaskNum = subMaxTaskNum;
save();
return this;
}
public int getSubReTryNum() {
return subReTryNum;
}
public DGroupConfig setSubReTryNum(int subReTryNum) {
this.subReTryNum = subReTryNum;
save();
return this;
}
public int getSubReTryInterval() {
return subReTryInterval;
}
public DGroupConfig setSubReTryInterval(int subReTryInterval) {
this.subReTryInterval = subReTryInterval;
save();
return this;
}
}
/**
* 应用配置
*/
public static class AppConfig extends BaseConfig {
public static class AppConfig extends BaseConfig implements Serializable {
/**
* 是否使用{@link AriaCrashHandler}来捕获异常 {@code true} 使用{@code false} 不使用
*/
@ -482,6 +548,36 @@ public final class Configuration {
*/
boolean netCheck = true;
/**
* 是否使用广播 除非无法使用注解否则不建议使用广播来接受任务 {@code true} 使用广播{@code false} 不适用广播
*/
boolean useBroadcast = false;
/**
* 断网的时候是否重试{@code true}断网也重试{@code false}断网不重试直接走失败的回调
*/
boolean notNetRetry = false;
public boolean isNotNetRetry() {
return notNetRetry;
}
public AppConfig setNotNetRetry(boolean notNetRetry) {
this.notNetRetry = notNetRetry;
save();
return this;
}
public boolean isUseBroadcast() {
return useBroadcast;
}
public AppConfig setUseBroadcast(boolean useBroadcast) {
this.useBroadcast = useBroadcast;
save();
return this;
}
public boolean isNetCheck() {
return netCheck;
}

Loading…
Cancel
Save