From 56af75c35c70f9a97cc4d931cd1b23dfafa35d1e Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Mon, 21 Jan 2019 20:39:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E3=80=81=E5=A2=9E=E5=8A=A0=E7=BB=84=E5=90=88=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=BB=E5=8A=A1=E9=98=9F=E5=88=97=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria/jcenter.gradle | 2 +- .../com/arialyy/aria/core/AriaManager.java | 23 +- .../com/arialyy/aria/core/ConfigHelper.java | 365 +++++---------- .../arialyy/aria/core/ConfigHelper.java.back | 441 ++++++++++++++++++ .../com/arialyy/aria/core/ConfigType.java | 4 +- .../com/arialyy/aria/core/command/AbsCmd.java | 4 +- .../core/command/normal/AbsNormalCmd.java | 3 +- .../core/command/normal/ResumeAllCmd.java | 55 +-- .../aria/core/command/normal/StartCmd.java | 3 - .../arialyy/aria/core/common/AbsFileer.java | 87 ++-- .../arialyy/aria/core/common/TaskRecord.java | 6 +- .../aria/core/download/BaseGroupTarget.java | 5 +- .../aria/core/download/BaseNormalTarget.java | 2 - .../aria/core/download/DGEntityWrapper.java | 2 +- .../aria/core/download/DGTaskWrapper.java | 11 +- .../aria/core/download/DTaskWrapper.java | 37 +- .../aria/core/download/DownloadEntity.java | 20 +- .../core/download/DownloadGroupEntity.java | 4 +- .../core/download/DownloadGroupTarget.java | 12 +- .../aria/core/download/DownloadGroupTask.java | 2 +- .../aria/core/download/DownloadReceiver.java | 6 +- .../core/download/FtpDirDownloadTarget.java | 4 +- .../download/downloader/AbsGroupUtil.java | 20 +- .../downloader/DownloadGroupUtil.java | 4 +- .../core/download/downloader/Downloader.java | 10 +- .../download/downloader/FtpDirInfoThread.java | 16 +- .../download/downloader/FtpThreadTask.java | 2 +- .../downloader/HttpFileInfoThread.java | 1 - .../download/downloader/HttpThreadTask.java | 2 +- .../com/arialyy/aria/core/inf/AbsEntity.java | 4 + .../arialyy/aria/core/inf/AbsGroupEntity.java | 12 +- .../arialyy/aria/core/inf/AbsTaskWrapper.java | 3 +- .../core/manager/DGTaskWrapperFactory.java | 14 +- .../core/manager/DTaskWrapperFactory.java | 7 +- .../aria/core/manager/IGTEFactory.java | 4 +- .../aria/core/manager/TaskWrapperManager.java | 8 +- .../core/manager/UTaskWrapperFactory.java | 4 +- .../arialyy/aria/core/queue/AbsTaskQueue.java | 45 +- .../core/queue/DownloadGroupTaskQueue.java | 11 +- .../aria/core/queue/DownloadTaskQueue.java | 8 +- .../arialyy/aria/core/queue/ITaskQueue.java | 30 +- .../aria/core/queue/UploadTaskQueue.java | 11 +- .../aria/core/queue/pool/BaseCachePool.java | 11 +- .../aria/core/queue/pool/BaseExecutePool.java | 7 +- .../arialyy/aria/core/queue/pool/IPool.java | 20 +- .../aria/core/scheduler/AbsSchedulers.java | 24 +- .../aria/core/upload/BaseNormalTarget.java | 1 - .../aria/core/upload/UTaskWrapper.java | 21 +- .../core/upload/uploader/FtpThreadTask.java | 2 +- .../core/upload/uploader/HttpThreadTask.java | 2 +- .../aria/core/upload/uploader/Uploader.java | 6 +- .../java/com/arialyy/aria/orm/DBConfig.java | 5 +- .../com/arialyy/aria/orm/DelegateFind.java | 2 +- .../com/arialyy/aria/util/CommonUtil.java | 2 +- .../com/arialyy/aria/util/DbDataHelper.java | 24 +- .../arialyy/annotations/DownloadGroup.java | 8 +- DEV_LOG.md | 5 +- app/src/main/assets/aria_config.xml | 71 ++- .../com/arialyy/simple/DbTestActivity.java | 2 - .../simple/download/KotlinDownloadActivity.kt | 2 +- .../download/group/ChildHandleDialog.java | 7 +- .../multi_download/DownloadAdapter.java | 2 +- .../com/arialyy/aria/core/Configuration.java | 220 ++++++--- 63 files changed, 1104 insertions(+), 654 deletions(-) create mode 100644 Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java.back diff --git a/Aria/jcenter.gradle b/Aria/jcenter.gradle index 8ce3129a..5d0a7f24 100644 --- a/Aria/jcenter.gradle +++ b/Aria/jcenter.gradle @@ -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'] diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index f151c382..6c1eca6f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -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; } + /** + * 如果需要在代码中修改下载类型的组合任务的配置,请使用以下方法 + *
+   *   
+   *     //修改最大任务队列数
+   *     Aria.get(this).getDownloadConfig().setMaxTaskNum(3);
+   *   
+   * 
+ */ + 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"); diff --git a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java index e5feef66..ff5d851c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java @@ -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": // 是否转换速度 + setField("isConvertSpeed", !checkBoolean(value) || Boolean.parseBoolean(value), + getAllTaskType()); break; - case "convertSpeed": - loadConvertSpeed(value); + case "maxSpeed": // 最大速度 + int maxSpeed = checkInt(value) ? Integer.parseInt(value) : 0; + setField("maxSpeed", maxSpeed, getAllTaskType()); break; - case "maxSpeed": - loadMaxSpeed(value); + case "queueMod": // 队列类型 + String mod = "now"; + if (!TextUtils.isEmpty(value) && (value.equalsIgnoreCase("now") || value.equalsIgnoreCase( + "wait"))) { + mod = value; + } + setField("queueMod", mod, getAllTaskType()); break; - case "queueMod": - loadQueueMod(value); + case "updateInterval": // 进度更新时间 + setField("updateInterval", checkLong(value) ? Long.parseLong(value) : 1000, + getAllTaskType()); break; - case "updateInterval": - loadUpdateInterval(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 "notNetRetry": - loadNotNetRetry(value); + case "subReTryNum": // 子任务重试次数 + int subReTryNum = checkInt(value) ? Integer.parseInt(value) : 5; + setField("subReTryNum", subReTryNum, ConfigType.D_GROUP); break; - case "useBlock": - loadUseBlock(value); + 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": // 日记等级 + 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 "logLevel": - loadLogLevel(value); + case "netCheck": // 是否检查网络 + setField("netCheck", checkBoolean(value) ? Boolean.valueOf(value) : false, + ConfigType.APP); break; - case "netCheck": - loadNetCheck(value); + 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; - } - if (mType == ConfigType.UPLOAD) { - mUploadConfig.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); + } } } - 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(); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java.back b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java.back new file mode 100644 index 00000000..f076a411 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java.back @@ -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(); + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/ConfigType.java b/Aria/src/main/java/com/arialyy/aria/core/ConfigType.java index 3fc9ed35..c4fc5114 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/ConfigType.java +++ b/Aria/src/main/java/com/arialyy/aria/core/ConfigType.java @@ -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; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java index 609714f2..4867c87b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java @@ -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 implements ICmd { - protected ITaskQueue mQueue; + protected AbsTaskQueue mQueue; protected T mTaskWrapper; protected String TAG; diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java index 976ebf9a..88c55ab7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java @@ -92,7 +92,6 @@ public abstract class AbsNormalCmd extends AbsCmd { */ 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 extends AbsCmd { * @return 创建的任务 */ AbsTask createTask(AbsTaskWrapper taskEntity) { - TaskWrapperManager.getInstance().addTaskWrapper(taskEntity); + return mQueue.createTask(taskEntity); } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java index 590e2af5..c3a5cde4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java @@ -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 extends AbsNormalCmd { "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 extends AbsNormalCmd { 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 extends AbsNormalCmd { 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 extends AbsNormalCmd { } } } - - /** - * 恢复实体任务 - * - * @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); - } - } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java index 75220953..041484b4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java @@ -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 extends AbsNormalCmd { mQueue = DownloadGroupTaskQueue.getInstance(); } createTask(te); - sendWaitState(); } } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java index c8cca845..a254baa3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java @@ -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> +public abstract class AbsFileer> implements Runnable { private static final String STATE = "_state_"; private static final String RECORD = "_record_"; @@ -53,10 +54,12 @@ public abstract class AbsFileer 1 && manager.getDownloadConfig().isUseBlock(); // 线程数不等1并且没有使用块下载,则认为没有使用动态文件 @@ -153,13 +158,13 @@ public abstract class AbsFileer 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(); - 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(); } } - mTaskEntity.setNewTask(isNewTask); + mTaskWrapper.setNewTask(isNewTask); + } + + private String getFilePath() { + if (getType() == DOWNLOAD) { + return ((DownloadEntity) mTaskWrapper.getEntity()).getDownloadPath(); + } else { + return ((UploadEntity) mTaskWrapper.getEntity()).getFilePath(); + } } /** @@ -507,7 +520,7 @@ public abstract class AbsFileer config = new SubThreadConfig<>(); + SubThreadConfig 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 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 config = new SubThreadConfig<>(); + SubThreadConfig 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 config); + protected abstract AbsThreadTask selectThreadTask(SubThreadConfig config); /** * 任务是否已经中断 diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/TaskRecord.java b/Aria/src/main/java/com/arialyy/aria/core/common/TaskRecord.java index c8631486..3e64e8d8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/TaskRecord.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/TaskRecord.java @@ -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} 不是 diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java index 867f8f50..ad5fb332 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java @@ -35,7 +35,7 @@ abstract class BaseGroupTarget /** * 组任务名 */ - String mGroupName; + String mGroupHash; /** * 文件夹临时路径 */ @@ -71,7 +71,7 @@ abstract class 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 file.renameTo(new File(newPath)); } de.setDownloadPath(newPath); - dte.setKey(newPath); des.add(de); } AbsEntity.saveAll(des); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java index cef916c5..0b9c8a92 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java @@ -171,7 +171,6 @@ abstract class 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 } if (!TextUtils.isEmpty(newUrl)) { mEntity.setUrl(newUrl); - mTaskWrapper.setUrl(newUrl); } return true; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DGEntityWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/download/DGEntityWrapper.java index 143aabf9..f2d00f61 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DGEntityWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DGEntityWrapper.java @@ -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 subEntity; @Override protected void handleConvert() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DGTaskWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/download/DGTaskWrapper.java index 7832d539..b0aa750e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DGTaskWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DGTaskWrapper.java @@ -25,8 +25,6 @@ public class DGTaskWrapper extends AbsGroupTaskWrapper subTaskEntities; - private String key; - public DGTaskWrapper(DownloadGroupEntity entity) { super(entity); } @@ -36,12 +34,11 @@ public class DGTaskWrapper extends AbsGroupTaskWrapper getSubTaskWrapper() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java index fb83618f..99d8c9f2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java @@ -22,56 +22,37 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper; */ public class DTaskWrapper extends AbsTaskWrapper { - /** - * 任务的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) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java index 3186f389..a8adb2ce 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java @@ -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(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java index 7174120d..28e2bf6f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java @@ -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() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java index 635e2c92..f28f595d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java @@ -66,7 +66,7 @@ public class DownloadGroupTarget extends BaseGroupTarget 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 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 im } } - mEntity.setGroupName(CommonUtil.getMd5Code(mUrls)); + mEntity.setGroupHash(CommonUtil.getMd5Code(mUrls)); return true; } @@ -288,7 +287,6 @@ public class DownloadGroupTarget extends BaseGroupTarget im CommonUtil.modifyTaskRecord(oldFile.getPath(), newPath); entity.setDownloadPath(newPath); - taskEntity.setKey(newPath); entity.setFileName(newName); entity.update(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java index a0df1a07..841ff368 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java @@ -54,7 +54,7 @@ public class DownloadGroupTask extends AbsGroupTask" + (TextUtils.isEmpty(mTaskWrapper.getEntity().getAlias()) - ? mTaskWrapper.getEntity().getGroupName() : mTaskWrapper.getEntity().getAlias()); + ? mTaskWrapper.getEntity().getGroupHash() : mTaskWrapper.getEntity().getAlias()); } @Override public int getTaskType() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java index 18f17a9f..e8ce720e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java @@ -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); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java index ad8f3b00..c28393ae 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java @@ -40,7 +40,7 @@ public class FtpDirDownloadTarget extends BaseGroupTarget } 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 * @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; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java index efa7339e..1c46f8ba 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java @@ -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) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java index cd435aa3..ea9bcb6b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java @@ -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 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(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java index 3e1ac795..9b4dd781 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java @@ -48,8 +48,8 @@ class Downloader extends AbsFileer { 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 { 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 { } @Override protected AbsThreadTask selectThreadTask(SubThreadConfig config) { - switch (mTaskEntity.getRequestType()) { + switch (mTaskWrapper.getRequestType()) { case AbsTaskWrapper.D_FTP: case AbsTaskWrapper.D_FTP_DIR: return new FtpThreadTask(mConstance, (IDownloadListener) mListener, config); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java index 4163c825..d9918048 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java @@ -67,25 +67,23 @@ class FtpDirInfoThread extends AbsFtpInfoThread()); } mEntity.getSubEntities().add(entity); - mTaskWrapper.getSubTaskWrapper().add(taskEntity); + mTaskWrapper.getSubTaskWrapper().add(taskWrapper); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java index 2f67d1ea..ed6d0e29 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java @@ -50,7 +50,7 @@ class FtpThreadTask extends AbsFtpThreadTask { 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; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java index 5b498a1c..248c2448 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java @@ -251,7 +251,6 @@ class HttpFileInfoThread implements Runnable { } mEntity.setFileName(newName); mEntity.setDownloadPath(newPath); - mTaskWrapper.setKey(newPath); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java index 6229e906..6b35171f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java @@ -58,7 +58,7 @@ final class HttpThreadTask extends AbsThreadTask { 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; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java index abf828fe..58e2b0c9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java @@ -173,6 +173,10 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable, /** * 实体唯一标识符 + * 下载实体:下载url + * 上传实体:文件路径 + * 下载任务组:组名 + * ftp文件夹下载:下载url */ public abstract String getKey(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java index f61d3ec0..93be21f3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java @@ -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(); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java index b79cb897..52af70fd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java @@ -78,8 +78,6 @@ public abstract class AbsTaskWrapper public abstract String getKey(); - public abstract void setKey(String key); - @Override public ENTITY getEntity() { return entity; } @@ -131,6 +129,7 @@ public abstract class AbsTaskWrapper public void setState(int state) { this.state = state; + entity.setState(state); } public int getRequestType() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/DGTaskWrapperFactory.java b/Aria/src/main/java/com/arialyy/aria/core/manager/DGTaskWrapperFactory.java index 75b5c4a5..7655a08a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/DGTaskWrapperFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/DGTaskWrapperFactory.java @@ -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 urls) { - DownloadGroupEntity entity = DbDataHelper.getHttpDGEntity(groupName, urls); + @Override public DGTaskWrapper getGTE(String groupHash, List 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 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; diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/DTaskWrapperFactory.java b/Aria/src/main/java/com/arialyy/aria/core/manager/DTaskWrapperFactory.java index 60d9effb..d19c50ba 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/DTaskWrapperFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/DTaskWrapperFactory.java @@ -46,10 +46,7 @@ class DTaskWrapperFactory implements INormalTEFactory urls); + TASK_ENTITY getGTE(String groupHash, List urls); /** * 获取FTP文件夹的任务实体,该方法需要以下操作: diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/TaskWrapperManager.java b/Aria/src/main/java/com/arialyy/aria/core/manager/TaskWrapperManager.java index 08288e45..8eada0ef 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/TaskWrapperManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/TaskWrapperManager.java @@ -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 { diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/UTaskWrapperFactory.java b/Aria/src/main/java/com/arialyy/aria/core/manager/UTaskWrapperFactory.java index 0899b094..188bdbb6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/UTaskWrapperFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/UTaskWrapperFactory.java @@ -40,9 +40,7 @@ class UTaskWrapperFactory implements INormalTEFactory - implements ITaskQueue { +public abstract class AbsTaskQueue + implements ITaskQueue { 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 { @@ -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; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java index ba072b34..d1f0a6e1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java @@ -50,7 +50,7 @@ public class DownloadTaskQueue extends AbsTaskQueue 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 } @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, "任务已存在"); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java index 8b98aebc..bfa5f270 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java @@ -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 { + /** + * 通过key跑断任务是在存在 + * + * @param key 下载链接,或上传文件的路径 + * @return {@code true} 任务存在 + */ + boolean taskExists(String key); + /** * 通过key判断任务是否正在执行 * @@ -39,9 +47,7 @@ public interface ITaskQueue { private static final String TAG = "UploadTaskQueue"; @@ -46,7 +45,7 @@ public class UploadTaskQueue extends AbsTaskQueue { 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 { } @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, "任务已存在"); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java index ca656847..d2ea1c88 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java @@ -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 implements IPool { private static final String TAG = "BaseCachePool"; @@ -88,7 +87,7 @@ public class BaseCachePool implements IPool { 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 implements IPool { 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 implements IPool { } } + @Override public boolean taskExits(String key) { + return mCacheMap.containsKey(CommonUtil.keyToHashKey(key)); + } + @Override public boolean removeTask(TASK task) { synchronized (AriaManager.LOCK) { if (task == null) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java index 60e24552..8996248c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java @@ -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 implements IPool { private final String TAG = "BaseExecutePool"; @@ -168,6 +167,10 @@ public class BaseExecutePool implements IPool { } } + @Override public boolean taskExits(String key) { + return mExecuteMap.containsKey(CommonUtil.keyToHashKey(key)); + } + @Override public boolean removeTask(TASK task) { synchronized (AriaManager.LOCK) { if (task == null) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/IPool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/IPool.java index ae6ab6c7..313520cb 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/IPool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/IPool.java @@ -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 { /** @@ -36,17 +36,25 @@ interface IPool { 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); diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java index 66ba8b52..037ca9ce 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java @@ -164,7 +164,7 @@ abstract class AbsSchedulers ALog.e(TAG, "上传失败,文件【" + filePath + "】不能是文件夹"); return false; } - mTaskWrapper.setKey(mEntity.getFilePath()); return true; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java index 33881f8b..24b631e0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java @@ -22,27 +22,14 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper; */ public class UTaskWrapper extends AbsTaskWrapper { - 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(); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java index 60764c5a..e94de7d7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java @@ -44,7 +44,7 @@ class FtpThreadTask extends AbsFtpThreadTask { mConnectTimeOut = mAridManager.getUploadConfig().getConnectTimeOut(); mReadTimeOut = mAridManager.getUploadConfig().getIOTimeOut(); mBufSize = mAridManager.getUploadConfig().getBuffSize(); - isNotNetRetry = mAridManager.getUploadConfig().isNotNetRetry(); + isNotNetRetry = mAridManager.getAppConfig().isNotNetRetry(); } @Override public int getMaxSpeed() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java index 33cffe21..8eba6818 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java @@ -57,7 +57,7 @@ class HttpThreadTask extends AbsThreadTask { 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 { diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java index eade3ffa..076d5ed8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java @@ -42,12 +42,16 @@ class Uploader extends AbsFileer { return true; } + @Override protected int getType() { + return UPLOAD; + } + @Override protected int setNewTaskThreadNum() { return 1; } @Override protected AbsThreadTask selectThreadTask(SubThreadConfig config) { - switch (mTaskEntity.getRequestType()) { + switch (mTaskWrapper.getRequestType()) { case AbsTaskWrapper.U_FTP: return new FtpThreadTask(mConstance, mListener, config); case AbsTaskWrapper.U_HTTP: diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java index 03195266..0c8e6baf 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -35,7 +35,7 @@ class DBConfig { /*adb pull /mnt/sdcard/Android/data/com.arialyy.simple/files/DB/AriaLyyDb d:/db*/ static Map 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); diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java b/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java index f24a9752..b2ffad93 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java @@ -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(); diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index 44d7b8b3..5a67c6a6 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -586,7 +586,7 @@ public class CommonUtil { return; } List records = - DbEntity.findDatas(TaskRecord.class, "dGroupName=?", groupEntity.getGroupName()); + DbEntity.findDatas(TaskRecord.class, "dGroupHash=?", groupEntity.getGroupHash()); if (records == null || records.isEmpty()) { ALog.w(TAG, "组任务记录删除失败,记录为null"); diff --git a/Aria/src/main/java/com/arialyy/aria/util/DbDataHelper.java b/Aria/src/main/java/com/arialyy/aria/util/DbDataHelper.java index e0315eac..b736cda1 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/DbDataHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/util/DbDataHelper.java @@ -48,26 +48,26 @@ public class DbDataHelper { /** * 获取组合任务实体 如果数据库不存在该实体,则新创建一个新的任务组实体 * - * @param groupName 组合任务名称 + * @param groupHash 组合任务名称 * @param urls 子任务url列表 */ - public static DownloadGroupEntity getHttpDGEntity(String groupName, List urls) { + public static DownloadGroupEntity getHttpDGEntity(String groupHash, List urls) { List 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 createHttpSubTask(String groupName, List urls) { + private static List createHttpSubTask(String groupHash, List urls) { List 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 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; } } diff --git a/AriaAnnotations/src/main/java/com/arialyy/annotations/DownloadGroup.java b/AriaAnnotations/src/main/java/com/arialyy/annotations/DownloadGroup.java index b36529d6..7ee70587 100644 --- a/AriaAnnotations/src/main/java/com/arialyy/annotations/DownloadGroup.java +++ b/AriaAnnotations/src/main/java/com/arialyy/annotations/DownloadGroup.java @@ -25,19 +25,19 @@ import java.lang.annotation.Target; * Aria下载事件被注解的方法中,参数仅能有一个,参数类型为{@link com.arialyy.aria.core.download.DownloadGroupTask} *
  *   
- *      {@literal @}DownloadGroup.onPre(groupName)
+ *      {@literal @}DownloadGroup.onPre(groupHash)
  *       protected void onPre(DownloadGroupTask task) {
  *       }
  *   
  * 
- * {@literal @}Download.onPre("myGroupName"),如果你的注解中增加了url描述, - * 则表示,所有下载任务中,只有下载地址为"myGroupName"的任务才能回调该注解的方法。 + * {@literal @}Download.onPre("mGroupHash"),如果你的注解中增加了url描述, + * 则表示,所有下载任务中,只有下载地址为"myGroupHash"的任务才能回调该注解的方法。 * * * 如果希望获取子任务的状态,可以使用onSub..类的注解 *
  *   
- *      {@literal @}DownloadGroup.onSubPre(groupName)
+ *      {@literal @}DownloadGroup.onSubPre(groupHash)
  *        protected void onPre(DownloadGroupTask task, String url) {
  *      }
  *   
diff --git a/DEV_LOG.md b/DEV_LOG.md
index def36cf5..de5a7371 100644
--- a/DEV_LOG.md
+++ b/DEV_LOG.md
@@ -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)
diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml
index cc753665..349a3db7 100644
--- a/app/src/main/assets/aria_config.xml
+++ b/app/src/main/assets/aria_config.xml
@@ -1,6 +1,8 @@
 
 
+  
 
+  
   
     
     
@@ -8,10 +10,15 @@
     
     
     
+    
+    
+    
+    
+    
   
 
 
-  
+  
   
 
     
@@ -27,9 +34,6 @@
     -->
     
 
-    
-    
-
     
     
 
-    
-    
-    
-
   
 
+  
   
     
     
-    
-    
 
     
     
@@ -108,9 +107,55 @@
     
     
 
-    
-    
-    
   
 
+  
+  
+
+    
+    
+
+    
+    
+
+    
+    
+
+    
+    
+
+    
+    
+
+    
+    
+
+
+    
+
+    
+    
+
+    
+    
+
+    
+    
+
+    
+    
+
+    
+    
+
+    
+    
+
+    
+    
+
+    
+    
+
+  
 
\ No newline at end of file
diff --git a/app/src/main/java/com/arialyy/simple/DbTestActivity.java b/app/src/main/java/com/arialyy/simple/DbTestActivity.java
index b38ce61e..b1dbe3d4 100644
--- a/app/src/main/java/com/arialyy/simple/DbTestActivity.java
+++ b/app/src/main/java/com/arialyy/simple/DbTestActivity.java
@@ -59,8 +59,6 @@ public class DbTestActivity extends BaseActivity {
       entity.setDownloadPath(key);
 
       DTaskWrapper dte = new DTaskWrapper(entity);
-      dte.setUrl(url);
-      dte.setKey(key);
 
       datas.add(entity);
     }
diff --git a/app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt b/app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt
index ef873639..0587f32e 100644
--- a/app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt
+++ b/app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt
@@ -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()
 //  }
diff --git a/app/src/main/java/com/arialyy/simple/download/group/ChildHandleDialog.java b/app/src/main/java/com/arialyy/simple/download/group/ChildHandleDialog.java
index 0b013adb..3506178a 100644
--- a/app/src/main/java/com/arialyy/simple/download/group/ChildHandleDialog.java
+++ b/app/src/main/java/com/arialyy/simple/download/group/ChildHandleDialog.java
@@ -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 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()));
 
diff --git a/app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java b/app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
index c2009ccf..d0af5e6a 100644
--- a/app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
+++ b/app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
@@ -62,7 +62,7 @@ public class DownloadAdapter extends AbsRVAdapter