From 1a8361704589cabd3fedabc6976d1a1e794067cd Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Tue, 22 Jan 2019 21:13:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=BB=E5=8A=A1=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/Custom.md | 7 +- .../com/arialyy/aria/core/AriaManager.java | 28 +- .../arialyy/aria/core/ConfigHelper.java.back | 441 ------------- .../arialyy/aria/core/common/AbsFileer.java | 4 +- .../aria/core/common/AbsThreadTask.java | 41 +- .../aria/core/common/BaseListener.java | 24 +- .../aria/core/common/RecordWrapper.java | 4 +- .../aria/core/common/SubThreadConfig.java | 4 +- .../core/common/ftp/AbsFtpThreadTask.java | 7 +- .../arialyy/aria/core/config/AppConfig.java | 112 ++++ .../arialyy/aria/core/config/BaseConfig.java | 51 ++ .../aria/core/config/BaseTaskConfig.java | 221 +++++++ .../aria/core/{ => config}/ConfigType.java | 2 +- .../aria/core/config/Configuration.java | 117 ++++ .../aria/core/config/DGroupConfig.java | 114 ++++ .../aria/core/config/DownloadConfig.java | 75 +++ .../aria/core/config/TTaskConfigAdapeter.java | 5 + .../aria/core/config/UploadConfig.java | 44 ++ .../XMLReader.java} | 25 +- .../aria/core/download/BaseDListener.java | 6 +- .../aria/core/download/DGEntityWrapper.java | 4 +- .../aria/core/download/DGTaskWrapper.java | 8 +- .../aria/core/download/DTaskWrapper.java | 10 + .../core/download/DownloadGroupListener.java | 6 +- .../aria/core/download/DownloadGroupTask.java | 6 +- .../aria/core/download/DownloadTask.java | 8 +- .../download/downloader/FtpThreadTask.java | 24 +- .../downloader/HttpFileInfoThread.java | 2 +- .../download/downloader/HttpThreadTask.java | 26 +- .../arialyy/aria/core/inf/AbsTaskWrapper.java | 14 + .../core/queue/DownloadGroupTaskQueue.java | 4 +- .../aria/core/scheduler/AbsSchedulers.java | 13 +- .../aria/core/upload/BaseUListener.java | 9 +- .../aria/core/upload/UTaskWrapper.java | 6 + .../core/upload/uploader/FtpThreadTask.java | 15 +- .../core/upload/uploader/HttpThreadTask.java | 21 +- .../{AbsWrapper.java => AbsDbWrapper.java} | 2 +- .../java/com/arialyy/aria/orm/DbEntity.java | 4 +- .../com/arialyy/aria/orm/DelegateFind.java | 4 +- .../com/arialyy/aria/orm/DelegateUpdate.java | 2 +- .../com/arialyy/aria/orm/DelegateWrapper.java | 2 +- app/src/main/assets/aria_config.xml | 6 +- .../com/arialyy/aria/core/Configuration.java | 621 ------------------ .../arialyy/aria/core/upload/UploadTask.java | 6 +- 44 files changed, 931 insertions(+), 1224 deletions(-) delete mode 100644 Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java.back create mode 100644 Aria/src/main/java/com/arialyy/aria/core/config/AppConfig.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/config/BaseConfig.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/config/BaseTaskConfig.java rename Aria/src/main/java/com/arialyy/aria/core/{ => config}/ConfigType.java (96%) create mode 100644 Aria/src/main/java/com/arialyy/aria/core/config/Configuration.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/config/DGroupConfig.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/config/DownloadConfig.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/config/TTaskConfigAdapeter.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/config/UploadConfig.java rename Aria/src/main/java/com/arialyy/aria/core/{ConfigHelper.java => config/XMLReader.java} (91%) rename Aria/src/main/java/com/arialyy/aria/orm/{AbsWrapper.java => AbsDbWrapper.java} (95%) delete mode 100644 aria/src/main/java/com/arialyy/aria/core/Configuration.java diff --git a/.github/ISSUE_TEMPLATE/Custom.md b/.github/ISSUE_TEMPLATE/Custom.md index d7cd735b..4e0df831 100644 --- a/.github/ISSUE_TEMPLATE/Custom.md +++ b/.github/ISSUE_TEMPLATE/Custom.md @@ -4,7 +4,7 @@ about: 描述你遇到的问题或bug --- -## 版本号 +## Aria版本 ## 什么问题 @@ -13,8 +13,5 @@ about: 描述你遇到的问题或bug ## 如何复现此问题 -## 手机型号 - - -## 控制台日志(越完整越好) +## 控制台日志 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 6c1eca6f..9d26dd06 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -28,6 +28,12 @@ import android.support.v4.app.Fragment; import android.widget.PopupWindow; import com.arialyy.aria.core.command.ICmd; import com.arialyy.aria.core.common.QueueMod; +import com.arialyy.aria.core.config.AppConfig; +import com.arialyy.aria.core.config.DGroupConfig; +import com.arialyy.aria.core.config.DownloadConfig; +import com.arialyy.aria.core.config.UploadConfig; +import com.arialyy.aria.core.config.XMLReader; +import com.arialyy.aria.core.config.Configuration; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadReceiver; @@ -54,9 +60,7 @@ import javax.xml.parsers.SAXParserFactory; import org.xml.sax.SAXException; /** - * Created by lyy on 2016/12/1. - * https://github.com/AriaLyy/Aria - * Aria管理器,任务操作在这里执行 + * Created by lyy on 2016/12/1. https://github.com/AriaLyy/Aria Aria管理器,任务操作在这里执行 */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class AriaManager { private static final String TAG = "AriaManager"; @@ -72,10 +76,10 @@ import org.xml.sax.SAXException; private Map> mSubClass = new ConcurrentHashMap<>(); public static Context APP; private List mCommands = new ArrayList<>(); - private Configuration.DownloadConfig mDConfig; - private Configuration.UploadConfig mUConfig; - private Configuration.AppConfig mAConfig; - private Configuration.DGroupConfig mDGConfig; + private DownloadConfig mDConfig; + private UploadConfig mUConfig; + private AppConfig mAConfig; + private DGroupConfig mDGConfig; private AriaManager(Context context) { APP = context.getApplicationContext(); @@ -179,7 +183,7 @@ import org.xml.sax.SAXException; * * */ - public Configuration.DownloadConfig getDownloadConfig() { + public DownloadConfig getDownloadConfig() { return mDConfig; } @@ -192,14 +196,14 @@ import org.xml.sax.SAXException; * * */ - public Configuration.UploadConfig getUploadConfig() { + public UploadConfig getUploadConfig() { return mUConfig; } /** * 获取APP配置 */ - public Configuration.AppConfig getAppConfig() { + public AppConfig getAppConfig() { return mAConfig; } @@ -212,7 +216,7 @@ import org.xml.sax.SAXException; * * */ - public Configuration.DGroupConfig getDGroupConfig(){ + public DGroupConfig getDGroupConfig() { return mDGConfig; } @@ -423,7 +427,7 @@ import org.xml.sax.SAXException; */ private void loadConfig() { try { - ConfigHelper helper = new ConfigHelper(); + XMLReader helper = new XMLReader(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.parse(APP.getAssets().open("aria_config.xml"), helper); 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 deleted file mode 100644 index f076a411..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java.back +++ /dev/null @@ -1,441 +0,0 @@ -/* - * 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/common/AbsFileer.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java index a254baa3..f9eb80f5 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 @@ -552,7 +552,7 @@ public abstract class AbsFileer> implements Callable { @@ -52,7 +55,6 @@ public abstract class AbsThreadTask mConfig; @@ -61,9 +63,7 @@ public abstract class AbsThreadTask 0) { mSpeedBandUtil = new BandwidthLimiter(getMaxSpeed(), mThreadNum); } + isNotNetRetry = mAridManager.getAppConfig().isNotNetRetry(); } /** @@ -117,24 +118,23 @@ public abstract class AbsThreadTask, TASK extends AbsTask> +public abstract class BaseListener, + TASK extends AbsTask> implements IEventListener { private static final String TAG = "BaseListener"; + private static final int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度 protected WeakReference outHandler; - private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度 private long mLastLen; //上一次发送长度 private boolean isFirst = true; private TASK mTask; private long mLastSaveTime; protected ENTITY mEntity; - protected TASK_ENTITY mTaskEntity; - protected boolean isConvertSpeed; - protected long mUpdateInterval; - protected AriaManager manager; + protected TASK_WRAPPER mTaskWrapper; + private boolean isConvertSpeed; + private long mUpdateInterval; protected BaseListener(TASK task, Handler outHandler) { this.outHandler = new WeakReference<>(outHandler); - this.mTask = new WeakReference<>(task).get(); - this.mEntity = mTask.getTaskWrapper().getEntity(); - this.mTaskEntity = mTask.getTaskWrapper(); - manager = AriaManager.getInstance(AriaManager.APP); + mTask = new WeakReference<>(task).get(); + mEntity = mTask.getTaskWrapper().getEntity(); + mTaskWrapper = mTask.getTaskWrapper(); + isConvertSpeed = mTaskWrapper.getConfig().isConvertSpeed(); + mUpdateInterval = mTaskWrapper.getConfig().getUpdateInterval(); mLastLen = mEntity.getCurrentProgress(); mLastSaveTime = System.currentTimeMillis(); } @@ -130,7 +130,7 @@ public abstract class BaseListener { +public class SubThreadConfig { //线程Id public int THREAD_ID; //文件总长度 @@ -19,7 +19,7 @@ public class SubThreadConfig { public File TEMP_FILE; //服务器地址 public String URL; - public TASK_ENTITY TASK_ENTITY; + public TASK_WRAPPER TASK_WRAPPER; public boolean SUPPORT_BP = true; public ThreadRecord THREAD_RECORD; } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpThreadTask.java index 653c8ff2..9e949f95 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpThreadTask.java @@ -36,8 +36,7 @@ import java.net.UnknownHostException; import javax.net.ssl.SSLContext; /** - * Created by lyy on 2017/9/26. - * FTP单任务父类 + * Created by lyy on 2017/9/26. FTP单任务父类 */ public abstract class AbsFtpThreadTask> extends AbsThreadTask { @@ -112,8 +111,8 @@ public abstract class AbsFtpThreadTask { @@ -41,6 +43,10 @@ public class DGTaskWrapper extends AbsGroupTaskWrapper getSubTaskWrapper() { return subTaskEntities; } 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 99d8c9f2..1d2949f0 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 @@ -15,6 +15,8 @@ */ package com.arialyy.aria.core.download; +import com.arialyy.aria.core.config.Configuration; +import com.arialyy.aria.core.config.DownloadConfig; import com.arialyy.aria.core.inf.AbsTaskWrapper; /** @@ -43,6 +45,14 @@ public class DTaskWrapper extends AbsTaskWrapper { return getEntity().getKey(); } + @Override public DownloadConfig getConfig() { + if (isGroupTask) { + return Configuration.getInstance().dGroupCfg.getSubConfig(); + } else { + return Configuration.getInstance().downloadCfg; + } + } + public String getGroupHash() { return groupHash; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java index 866d2732..64e69269 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java @@ -39,8 +39,6 @@ class DownloadGroupListener super(task, outHandler); mSeedEntity = new GroupSendParams<>(); mSeedEntity.groupTask = task; - isConvertSpeed = manager.getDownloadConfig().isConvertSpeed(); - mUpdateInterval = manager.getDownloadConfig().getUpdateInterval(); } @Override public void onSubPre(DownloadEntity subEntity) { @@ -121,11 +119,11 @@ class DownloadGroupListener } @Override protected void saveData(int state, long location) { - mTaskEntity.setState(state); + mTaskWrapper.setState(state); mEntity.setState(state); if (state == IEntity.STATE_CANCEL) { if (mEntity instanceof DownloadGroupEntity) { - CommonUtil.delGroupTaskRecord(mTaskEntity.isRemoveFile(), mEntity); + CommonUtil.delGroupTaskRecord(mTaskWrapper.isRemoveFile(), mEntity); } return; } else if (state == IEntity.STATE_STOP) { 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 841ff368..3a6d80f2 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 @@ -33,12 +33,12 @@ import com.arialyy.aria.util.CheckUtil; */ public class DownloadGroupTask extends AbsGroupTask { - private DownloadGroupTask(DGTaskWrapper taskEntity, Handler outHandler) { - mTaskWrapper = taskEntity; + private DownloadGroupTask(DGTaskWrapper taskWrapper, Handler outHandler) { + mTaskWrapper = taskWrapper; mOutHandler = outHandler; mContext = AriaManager.APP; mListener = new DownloadGroupListener(this, mOutHandler); - switch (taskEntity.getRequestType()) { + switch (taskWrapper.getRequestType()) { case AbsTaskWrapper.D_HTTP: mUtil = new DownloadGroupUtil((IDownloadGroupListener) mListener, mTaskWrapper); break; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java index a999e121..77e445a8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java @@ -32,13 +32,13 @@ import java.io.File; public class DownloadTask extends AbsNormalTask { public static final String TAG = "DownloadTask"; - private DownloadTask(DTaskWrapper taskEntity, Handler outHandler) { - mTaskWrapper = taskEntity; + private DownloadTask(DTaskWrapper taskWrapper, Handler outHandler) { + mTaskWrapper = taskWrapper; mOutHandler = outHandler; mContext = AriaManager.APP; mListener = new BaseDListener(this, mOutHandler); - mUtil = new SimpleDownloadUtil(taskEntity, (IDownloadListener) mListener); - mEntity = taskEntity.getEntity(); + mUtil = new SimpleDownloadUtil(taskWrapper, (IDownloadListener) mListener); + mEntity = taskWrapper.getEntity(); } /** 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 ed6d0e29..ecc33f3b 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 @@ -20,6 +20,8 @@ import aria.apache.commons.net.ftp.FTPReply; import com.arialyy.aria.core.common.StateConstance; import com.arialyy.aria.core.common.SubThreadConfig; import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask; +import com.arialyy.aria.core.config.BaseTaskConfig; +import com.arialyy.aria.core.config.DownloadConfig; import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.inf.IDownloadListener; @@ -36,8 +38,7 @@ import java.nio.channels.FileChannel; import java.nio.channels.ReadableByteChannel; /** - * Created by Aria.Lao on 2017/7/24. - * Ftp下载任务 + * Created by Aria.Lao on 2017/7/24. Ftp下载任务 */ class FtpThreadTask extends AbsFtpThreadTask { private final String TAG = "FtpThreadTask"; @@ -47,10 +48,6 @@ class FtpThreadTask extends AbsFtpThreadTask { FtpThreadTask(StateConstance constance, IDownloadListener listener, SubThreadConfig downloadInfo) { super(constance, listener, downloadInfo); - mConnectTimeOut = mAridManager.getDownloadConfig().getConnectTimeOut(); - mReadTimeOut = mAridManager.getDownloadConfig().getIOTimeOut(); - mBufSize = mAridManager.getDownloadConfig().getBuffSize(); - isNotNetRetry = mAridManager.getAppConfig().isNotNetRetry(); isOpenDynamicFile = STATE.TASK_RECORD.isOpenDynamicFile; isBlock = STATE.TASK_RECORD.isBlock; } @@ -87,7 +84,8 @@ class FtpThreadTask extends AbsFtpThreadTask { return this; } String remotePath = - new String(mTaskWrapper.asFtp().getUrlEntity().remotePath.getBytes(charSet), SERVER_CHARSET); + new String(mTaskWrapper.asFtp().getUrlEntity().remotePath.getBytes(charSet), + SERVER_CHARSET); ALog.i(TAG, String.format("remotePath【%s】", remotePath)); is = client.retrieveFileStream(remotePath); reply = client.getReplyCode(); @@ -174,7 +172,7 @@ class FtpThreadTask extends AbsFtpThreadTask { fos = new FileOutputStream(mConfig.TEMP_FILE, true); foc = fos.getChannel(); fic = Channels.newChannel(is); - ByteBuffer bf = ByteBuffer.allocate(mBufSize); + ByteBuffer bf = ByteBuffer.allocate(getTaskConfig().getBuffSize()); while (isLive() && (len = fic.read(bf)) != -1) { if (isBreak()) { break; @@ -223,9 +221,9 @@ class FtpThreadTask extends AbsFtpThreadTask { private void readNormal(InputStream is) { BufferedRandomAccessFile file = null; try { - file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize); + file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", getTaskConfig().getBuffSize()); file.seek(mConfig.START_LOCATION); - byte[] buffer = new byte[mBufSize]; + byte[] buffer = new byte[getTaskConfig().getBuffSize()]; int len; while (isLive() && (len = is.read(buffer)) != -1) { if (isBreak()) { @@ -259,6 +257,10 @@ class FtpThreadTask extends AbsFtpThreadTask { } @Override public int getMaxSpeed() { - return mAridManager.getDownloadConfig().getMaxSpeed(); + return getTaskConfig().getMaxSpeed(); + } + + @Override protected DownloadConfig getTaskConfig() { + return mTaskWrapper.getConfig(); } } 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 248c2448..ed10ecfa 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 @@ -118,7 +118,7 @@ class HttpFileInfoThread implements Runnable { len = -1; } else { int start = temp.indexOf("/"); - len = Long.parseLong(temp.substring(start + 1, temp.length())); + len = Long.parseLong(temp.substring(start + 1)); } } } 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 6b35171f..3945c8d7 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 @@ -19,6 +19,8 @@ import com.arialyy.aria.core.common.AbsThreadTask; import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.common.StateConstance; import com.arialyy.aria.core.common.SubThreadConfig; +import com.arialyy.aria.core.config.BaseTaskConfig; +import com.arialyy.aria.core.config.DownloadConfig; import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.common.http.HttpTaskDelegate; @@ -44,8 +46,7 @@ import java.util.Map; import java.util.Set; /** - * Created by lyy on 2017/1/18. - * 下载线程 + * Created by lyy on 2017/1/18. 下载线程 */ final class HttpThreadTask extends AbsThreadTask { private final String TAG = "HttpThreadTask"; @@ -55,10 +56,6 @@ final class HttpThreadTask extends AbsThreadTask { HttpThreadTask(StateConstance constance, IDownloadListener listener, SubThreadConfig downloadInfo) { super(constance, listener, downloadInfo); - mConnectTimeOut = mAridManager.getDownloadConfig().getConnectTimeOut(); - mReadTimeOut = mAridManager.getDownloadConfig().getIOTimeOut(); - mBufSize = mAridManager.getDownloadConfig().getBuffSize(); - isNotNetRetry = mAridManager.getAppConfig().isNotNetRetry(); isOpenDynamicFile = STATE.TASK_RECORD.isOpenDynamicFile; isBlock = STATE.TASK_RECORD.isBlock; } @@ -88,8 +85,8 @@ final class HttpThreadTask extends AbsThreadTask { ALog.w(TAG, "该下载不支持断点"); } ConnectionHelp.setConnectParam(taskDelegate, conn); - conn.setConnectTimeout(mConnectTimeOut); - conn.setReadTimeout(mReadTimeOut); //设置读取流的等待时间,必须设置该参数 + conn.setConnectTimeout(getTaskConfig().getConnectTimeOut()); + conn.setReadTimeout(getTaskConfig().getIOTimeOut()); //设置读取流的等待时间,必须设置该参数 conn.connect(); if (taskDelegate.getRequestEnum() == RequestEnum.POST) { Map params = taskDelegate.getParams(); @@ -113,7 +110,8 @@ final class HttpThreadTask extends AbsThreadTask { readDynamicFile(is); } else { //创建可设置位置的文件 - file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize); + file = + new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", getTaskConfig().getBuffSize()); //设置每条线程写入文件的位置 file.seek(mConfig.START_LOCATION); if (taskDelegate.isChunked()) { @@ -165,7 +163,7 @@ final class HttpThreadTask extends AbsThreadTask { fos = new FileOutputStream(mConfig.TEMP_FILE, true); foc = fos.getChannel(); fic = Channels.newChannel(is); - ByteBuffer bf = ByteBuffer.allocate(mBufSize); + ByteBuffer bf = ByteBuffer.allocate(getTaskConfig().getBuffSize()); //如果要通过 Future 的 cancel 方法取消正在运行的任务,那么该任务必定是可以 对线程中断做出响应 的任务。 while (isLive() && (len = fic.read(bf)) != -1) { @@ -227,7 +225,7 @@ final class HttpThreadTask extends AbsThreadTask { */ private void readNormal(InputStream is, BufferedRandomAccessFile file) throws IOException { - byte[] buffer = new byte[mBufSize]; + byte[] buffer = new byte[getTaskConfig().getBuffSize()]; int len; while (isLive() && (len = is.read(buffer)) != -1) { if (isBreak()) { @@ -248,7 +246,7 @@ final class HttpThreadTask extends AbsThreadTask { if (isBreak()) { return; } - if (!checkBlock()){ + if (!checkBlock()) { return; } @@ -293,4 +291,8 @@ final class HttpThreadTask extends AbsThreadTask { @Override public int getMaxSpeed() { return mAridManager.getDownloadConfig().getMaxSpeed(); } + + @Override protected DownloadConfig getTaskConfig() { + return mTaskWrapper.getConfig(); + } } 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 52af70fd..c6ca6b15 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 @@ -17,6 +17,10 @@ package com.arialyy.aria.core.inf; import com.arialyy.aria.core.common.ftp.FtpTaskDelegate; import com.arialyy.aria.core.common.http.HttpTaskDelegate; +import com.arialyy.aria.core.config.BaseTaskConfig; +import com.arialyy.aria.core.config.DGroupConfig; +import com.arialyy.aria.core.config.DownloadConfig; +import com.arialyy.aria.core.config.UploadConfig; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.upload.UploadEntity; @@ -76,8 +80,18 @@ public abstract class AbsTaskWrapper this.entity = entity; } + /** + * 任务识别标志 {@link AbsEntity#getKey()} + */ public abstract String getKey(); + /** + * 任务配置 + * + * @return {@link DownloadConfig}、{@link UploadConfig}、{@link DGroupConfig} + */ + public abstract BaseTaskConfig getConfig(); + @Override public ENTITY getEntity() { return entity; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java index c826e328..d8cacfec 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java @@ -48,7 +48,7 @@ public class DownloadGroupTaskQueue } @Override public int getMaxTaskNum() { - return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum(); + return AriaManager.getInstance(AriaManager.APP).getDGroupConfig().getMaxTaskNum(); } @Override public DownloadGroupTask createTask(DGTaskWrapper wrapper) { @@ -65,6 +65,6 @@ public class DownloadGroupTaskQueue } @Override public int getOldMaxNum() { - return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum; + return AriaManager.getInstance(AriaManager.APP).getDGroupConfig().oldMaxTaskNum; } } 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 037ca9ce..47158e13 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 @@ -320,16 +320,9 @@ abstract class AbsSchedulers BaseUListener(UploadTask task, Handler outHandler) { super(task, outHandler); - isConvertSpeed = manager.getUploadConfig().isConvertSpeed(); - mUpdateInterval = manager.getUploadConfig().getUpdateInterval(); } @Override protected void saveData(int state, long location) { - mTaskEntity.setState(state); + mTaskWrapper.setState(state); mEntity.setState(state); if (state == IEntity.STATE_CANCEL) { - if (mEntity instanceof UploadEntity) { - CommonUtil.delTaskRecord(mEntity.getFilePath(), 2, mTaskEntity.isRemoveFile()); - } - return; + CommonUtil.delTaskRecord(mEntity.getFilePath(), 2, mTaskWrapper.isRemoveFile()); } else if (state == IEntity.STATE_STOP) { mEntity.setStopTime(System.currentTimeMillis()); } else if (state == IEntity.STATE_COMPLETE) { 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 24b631e0..b809a473 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 @@ -15,6 +15,8 @@ */ package com.arialyy.aria.core.upload; +import com.arialyy.aria.core.config.Configuration; +import com.arialyy.aria.core.config.UploadConfig; import com.arialyy.aria.core.inf.AbsTaskWrapper; /** @@ -32,4 +34,8 @@ public class UTaskWrapper extends AbsTaskWrapper { @Override public String getKey() { return getEntity().getKey(); } + + @Override public UploadConfig getConfig() { + return Configuration.getInstance().uploadCfg; + } } 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 e94de7d7..88eddc5d 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 @@ -21,6 +21,9 @@ import aria.apache.commons.net.ftp.OnFtpInputStreamListener; import com.arialyy.aria.core.common.StateConstance; import com.arialyy.aria.core.common.SubThreadConfig; import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask; +import com.arialyy.aria.core.config.BaseTaskConfig; +import com.arialyy.aria.core.config.DownloadConfig; +import com.arialyy.aria.core.config.UploadConfig; import com.arialyy.aria.core.inf.IEventListener; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UTaskWrapper; @@ -41,14 +44,14 @@ class FtpThreadTask extends AbsFtpThreadTask { FtpThreadTask(StateConstance constance, IEventListener listener, SubThreadConfig info) { super(constance, listener, info); - mConnectTimeOut = mAridManager.getUploadConfig().getConnectTimeOut(); - mReadTimeOut = mAridManager.getUploadConfig().getIOTimeOut(); - mBufSize = mAridManager.getUploadConfig().getBuffSize(); - isNotNetRetry = mAridManager.getAppConfig().isNotNetRetry(); } @Override public int getMaxSpeed() { - return mAridManager.getUploadConfig().getMaxSpeed(); + return getTaskConfig().getMaxSpeed(); + } + + @Override protected UploadConfig getTaskConfig() { + return mTaskWrapper.getConfig(); } @Override public FtpThreadTask call() throws Exception { @@ -79,7 +82,7 @@ class FtpThreadTask extends AbsFtpThreadTask { return this; } - file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize); + file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", getTaskConfig().getBuffSize()); if (mConfig.START_LOCATION != 0) { //file.skipBytes((int) mConfig.START_LOCATION); file.seek(mConfig.START_LOCATION); 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 8eba6818..19846126 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 @@ -19,6 +19,8 @@ import com.arialyy.aria.core.common.AbsThreadTask; import com.arialyy.aria.core.common.StateConstance; import com.arialyy.aria.core.common.SubThreadConfig; import com.arialyy.aria.core.common.http.HttpTaskDelegate; +import com.arialyy.aria.core.config.BaseTaskConfig; +import com.arialyy.aria.core.config.UploadConfig; import com.arialyy.aria.core.inf.IUploadListener; import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; @@ -40,8 +42,7 @@ import java.util.Set; import java.util.UUID; /** - * Created by Aria.Lao on 2017/7/28. - * 不支持断点的HTTP上传任务 + * Created by Aria.Lao on 2017/7/28. 不支持断点的HTTP上传任务 */ class HttpThreadTask extends AbsThreadTask { private final String TAG = "HttpThreadTask"; @@ -54,10 +55,6 @@ class HttpThreadTask extends AbsThreadTask { HttpThreadTask(StateConstance constance, IUploadListener listener, SubThreadConfig uploadInfo) { super(constance, listener, uploadInfo); - mConnectTimeOut = mAridManager.getUploadConfig().getConnectTimeOut(); - mReadTimeOut = mAridManager.getUploadConfig().getIOTimeOut(); - mBufSize = mAridManager.getUploadConfig().getBuffSize(); - isNotNetRetry = mAridManager.getAppConfig().isNotNetRetry(); } @Override public HttpThreadTask call() throws Exception { @@ -83,11 +80,11 @@ class HttpThreadTask extends AbsThreadTask { mHttpConn.setRequestProperty("Content-Type", taskDelegate.getContentType() + "; boundary=" + BOUNDARY); mHttpConn.setRequestProperty("User-Agent", taskDelegate.getUserAgent()); - mHttpConn.setConnectTimeout(mConnectTimeOut); - mHttpConn.setReadTimeout(mReadTimeOut); + mHttpConn.setConnectTimeout(getTaskConfig().getConnectTimeOut()); + mHttpConn.setReadTimeout(getTaskConfig().getIOTimeOut()); //mHttpConn.setRequestProperty("Range", "bytes=" + 0 + "-" + "100"); //内部缓冲区---分段上传防止oom - mHttpConn.setChunkedStreamingMode(mBufSize); + mHttpConn.setChunkedStreamingMode(getTaskConfig().getBuffSize()); //添加Http请求头部 Set keys = taskDelegate.getHeaders().keySet(); @@ -223,6 +220,10 @@ class HttpThreadTask extends AbsThreadTask { } @Override public int getMaxSpeed() { - return mAridManager.getUploadConfig().getMaxSpeed(); + return getTaskConfig().getMaxSpeed(); + } + + @Override protected UploadConfig getTaskConfig() { + return mTaskWrapper.getConfig(); } } diff --git a/Aria/src/main/java/com/arialyy/aria/orm/AbsWrapper.java b/Aria/src/main/java/com/arialyy/aria/orm/AbsDbWrapper.java similarity index 95% rename from Aria/src/main/java/com/arialyy/aria/orm/AbsWrapper.java rename to Aria/src/main/java/com/arialyy/aria/orm/AbsDbWrapper.java index 49f4eca1..c3910b01 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/AbsWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/AbsDbWrapper.java @@ -18,7 +18,7 @@ package com.arialyy.aria.orm; /** * Created by laoyuyu on 2018/3/30. */ -public abstract class AbsWrapper { +public abstract class AbsDbWrapper { /** * 处理转换 diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java b/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java index cc1770ab..b41dffd7 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java @@ -33,7 +33,7 @@ public abstract class DbEntity { ///** // * 保存关联数据 // */ - //public static void saveRelationData(AbsWrapper wrapper) { + //public static void saveRelationData(AbsDbWrapper wrapper) { // DelegateWrapper.getInstance().saveRelationData(wrapper); //} @@ -42,7 +42,7 @@ public abstract class DbEntity { * * @param expression 查询条件 */ - public static List findRelationData(Class clazz, + public static List findRelationData(Class clazz, String... expression) { return DelegateWrapper.getInstance().findRelationData(clazz, expression); } 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 b2ffad93..d7fa3e3e 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java @@ -53,7 +53,7 @@ class DelegateFind extends AbsDelegate { * 如果实体中有多个{@link One}或{@link Many}注解,将返回nul * {@link One} 的注解对象必须是{@link DbEntity},{@link Many}的注解对象必须是List,并且List中的类型必须是{@link DbEntity} */ - List findRelationData(SQLiteDatabase db, Class clazz, + List findRelationData(SQLiteDatabase db, Class clazz, String... expression) { db = checkDb(db); @@ -202,7 +202,7 @@ class DelegateFind extends AbsDelegate { * @param pColumnAlias 关联查询父表别名 * @param cColumnAlias 关联查询子表别名 */ - private synchronized List newInstanceEntity( + private synchronized List newInstanceEntity( Class clazz, Class

parent, Class child, Cursor cursor, diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java b/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java index 1c542afa..49c80d2d 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java @@ -37,7 +37,7 @@ class DelegateUpdate extends AbsDelegate { ///** // * 添加或更新关联数据 // */ - //void saveRelationData(SQLiteDatabase db, AbsWrapper wrapper) { + //void saveRelationData(SQLiteDatabase db, AbsDbWrapper wrapper) { // Class clazz = wrapper.getClass(); // List fields = CommonUtil.getAllFields(clazz); // DbEntity one = null; diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DelegateWrapper.java b/Aria/src/main/java/com/arialyy/aria/orm/DelegateWrapper.java index 6722ee90..8fdbdf24 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DelegateWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DelegateWrapper.java @@ -60,7 +60,7 @@ public class DelegateWrapper { * * @param expression 查询条件 */ - List findRelationData(Class clazz, String... expression) { + List findRelationData(Class clazz, String... expression) { return mDManager.getDelegate(DelegateFind.class).findRelationData(mDb, clazz, expression); } diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index 349a3db7..6f1d56b7 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -112,9 +112,6 @@ - - - @@ -157,5 +154,8 @@ + + + \ No newline at end of file diff --git a/aria/src/main/java/com/arialyy/aria/core/Configuration.java b/aria/src/main/java/com/arialyy/aria/core/Configuration.java deleted file mode 100644 index 4b3017e8..00000000 --- a/aria/src/main/java/com/arialyy/aria/core/Configuration.java +++ /dev/null @@ -1,621 +0,0 @@ -/* - * 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.core.common.QueueMod; -import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; -import com.arialyy.aria.core.queue.DownloadTaskQueue; -import com.arialyy.aria.core.queue.UploadTaskQueue; -import com.arialyy.aria.util.ALog; -import com.arialyy.aria.util.AriaCrashHandler; -import com.arialyy.aria.util.CommonUtil; -import java.io.File; -import java.io.Serializable; - -/** - * Created by lyy on 2016/12/8. 信息配置 kotlin 方式有bug,不能将public去掉 - */ -public final class Configuration { - private static final String TAG = "Configuration"; - private static final String DOWNLOAD_CONFIG_FILE = "/Aria/AriaDownload.cfg"; - private static final String UPLOAD_CONFIG_FILE = "/Aria/AriaUpload.cfg"; - private static final String APP_CONFIG_FILE = "/Aria/AriaApp.cfg"; - private static final String DGROUP_CONFIG_FILE = "/Aria/AriaDGroup.cfg"; - private static final int TYPE_DOWNLOAD = 1; - private static final int TYPE_UPLOAD = 2; - private static final int TYPE_APP = 3; - private static final int TYPE_DGROUP = 4; - private static volatile Configuration INSTANCE = null; - static final String XML_FILE = "/Aria/aria_config.xml"; - DownloadConfig downloadCfg; - UploadConfig uploadCfg; - AppConfig appCfg; - DGroupConfig dGroupCfg; - - private Configuration() { - //删除老版本的配置文件 - String basePath = AriaManager.APP.getFilesDir().getPath(); - File oldDCfg = new File(String.format("%s/Aria/DownloadConfig.properties", basePath)); - if (oldDCfg.exists()) { // 只需要判断一个 - File oldUCfg = new File(String.format("%s/Aria/UploadConfig.properties", basePath)); - File oldACfg = new File(String.format("%s/Aria/AppConfig.properties", basePath)); - oldDCfg.delete(); - oldUCfg.delete(); - oldACfg.delete(); - // 删除配置触发更新 - File temp = new File(String.format("%s%s", basePath, XML_FILE)); - if (temp.exists()) { - temp.delete(); - } - } - File newDCfg = new File(String.format("%s%s", basePath, DOWNLOAD_CONFIG_FILE)); - File newUCfg = new File(String.format("%s%s", basePath, UPLOAD_CONFIG_FILE)); - File newACfg = new File(String.format("%s%s", basePath, APP_CONFIG_FILE)); - File dgCfg = new File(String.format("%s%s", basePath, DGROUP_CONFIG_FILE)); - // 加载下载配置 - if (newDCfg.exists()) { - downloadCfg = (DownloadConfig) CommonUtil.readObjFromFile(newDCfg.getPath()); - } - if (downloadCfg == null) { - downloadCfg = new DownloadConfig(); - } - // 加载上传配置 - if (newUCfg.exists()) { - uploadCfg = (UploadConfig) CommonUtil.readObjFromFile(newUCfg.getPath()); - } - if (uploadCfg == null) { - uploadCfg = new UploadConfig(); - } - // 加载app配置 - if (newACfg.exists()) { - appCfg = (AppConfig) CommonUtil.readObjFromFile(newACfg.getPath()); - } - if (appCfg == null) { - appCfg = new AppConfig(); - } - // 加载下载类型组合任务的配置 - if (dgCfg.exists()) { - dGroupCfg = (DGroupConfig) CommonUtil.readObjFromFile(dgCfg.getPath()); - } - if (dGroupCfg == null) { - dGroupCfg = new DGroupConfig(); - } - } - - static Configuration getInstance() { - if (INSTANCE == null) { - synchronized (AppConfig.class) { - INSTANCE = new Configuration(); - } - } - return INSTANCE; - } - - /** - * 检查配置文件是否存在,只要{@link DownloadConfig}、{@link UploadConfig}、{@link AppConfig}、{@link - * DGroupConfig}其中一个不存在 则任务配置文件不存在 - * - * @return {@code true}配置存在,{@code false}配置不存在 - */ - boolean configExists() { - String basePath = AriaManager.APP.getFilesDir().getPath(); - return (new File(String.format("%s%s", basePath, DOWNLOAD_CONFIG_FILE))).exists() - && (new File(String.format("%s%s", basePath, UPLOAD_CONFIG_FILE))).exists() - && (new File(String.format("%s%s", basePath, APP_CONFIG_FILE))).exists() - && (new File(String.format("%s%s", basePath, DGROUP_CONFIG_FILE))).exists(); - } - - abstract static class BaseConfig implements Serializable { - - /** - * 类型 - * - * @return {@link #TYPE_DOWNLOAD}、{@link #TYPE_UPLOAD}、{@link #TYPE_APP}、{@link #TYPE_DGROUP} - */ - abstract int getType(); - - /** - * 保存配置 - */ - void save() { - String basePath = AriaManager.APP.getFilesDir().getPath(); - String path = null; - switch (getType()) { - case TYPE_DOWNLOAD: - path = DOWNLOAD_CONFIG_FILE; - break; - case TYPE_UPLOAD: - path = UPLOAD_CONFIG_FILE; - break; - case TYPE_APP: - path = APP_CONFIG_FILE; - break; - } - if (!TextUtils.isEmpty(path)) { - String tempPath = String.format("%s%s", basePath, path); - CommonUtil.deleteFile(tempPath); - CommonUtil.writeObjToFile(tempPath, this); - } else { - ALog.e(TAG, String.format("保存配置失败,配置类型:%s,原因:路径错误", getType())); - } - } - } - - /** - * 通用任务配置 - */ - abstract static class BaseTaskConfig extends BaseConfig implements Serializable { - - /** - * 设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢 - */ - int buffSize = 8192; - - /** - * 进度刷新间隔,默认1秒 - */ - long updateInterval = 1000; - - /** - * 旧任务数 - */ - public int oldMaxTaskNum = 2; - - /** - * 任务队列最大任务数, 默认为2 - */ - int maxTaskNum = 2; - /** - * 下载失败,重试次数,默认为10 - */ - int reTryNum = 10; - /** - * 设置重试间隔,单位为毫秒,默认2000毫秒 - */ - int reTryInterval = 2000; - /** - * 设置url连接超时时间,单位为毫秒,默认5000毫秒 - */ - int connectTimeOut = 5000; - - /** - * 是否需要转换速度单位,转换完成后为:1b/s、1k/s、1m/s、1g/s、1t/s,如果不需要将返回byte长度 - */ - boolean isConvertSpeed = false; - - /** - * 执行队列类型 - * - * @see QueueMod - */ - String queueMod = "wait"; - - /** - * 设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒 - */ - int iOTimeOut = 20 * 1000; - - /** - * 设置最大下载/上传速度,单位:kb, 为0表示不限速 - */ - int maxSpeed = 0; - - /** - * 设置https ca 证书信息;path 为assets目录下的CA证书完整路径 - */ - String caPath; - /** - * name 为CA证书名 - */ - String caName; - - public String getCaPath() { - return caPath; - } - - public BaseConfig setCaPath(String caPath) { - this.caPath = caPath; - save(); - return this; - } - - public String getCaName() { - return caName; - } - - public BaseConfig setCaName(String caName) { - this.caName = caName; - save(); - return this; - } - - public BaseTaskConfig setMaxTaskNum(int maxTaskNum) { - oldMaxTaskNum = this.maxTaskNum; - this.maxTaskNum = maxTaskNum; - save(); - return this; - } - - public int getMaxSpeed() { - return maxSpeed; - } - - public BaseTaskConfig setMaxSpeed(int maxSpeed) { - this.maxSpeed = maxSpeed; - save(); - return this; - } - - public long getUpdateInterval() { - return updateInterval; - } - - /** - * 设置进度更新间隔,该设置对正在运行的任务无效,默认为1000毫秒 - * - * @param updateInterval 不能小于0 - */ - public BaseTaskConfig setUpdateInterval(long updateInterval) { - if (updateInterval <= 0) { - ALog.w("Configuration", "进度更新间隔不能小于0"); - return this; - } - this.updateInterval = updateInterval; - save(); - return this; - } - - public String getQueueMod() { - return queueMod; - } - - public BaseTaskConfig setQueueMod(String queueMod) { - this.queueMod = queueMod; - save(); - return this; - } - - public int getMaxTaskNum() { - return maxTaskNum; - } - - public int getReTryNum() { - return reTryNum; - } - - public BaseTaskConfig setReTryNum(int reTryNum) { - this.reTryNum = reTryNum; - save(); - return this; - } - - public int getReTryInterval() { - return reTryInterval; - } - - public BaseTaskConfig setReTryInterval(int reTryInterval) { - this.reTryInterval = reTryInterval; - save(); - return this; - } - - public boolean isConvertSpeed() { - return isConvertSpeed; - } - - public BaseTaskConfig setConvertSpeed(boolean convertSpeed) { - isConvertSpeed = convertSpeed; - save(); - return this; - } - - public int getConnectTimeOut() { - return connectTimeOut; - } - - public BaseTaskConfig setConnectTimeOut(int connectTimeOut) { - this.connectTimeOut = connectTimeOut; - save(); - return this; - } - - public int getIOTimeOut() { - return iOTimeOut; - } - - public BaseTaskConfig setIOTimeOut(int iOTimeOut) { - this.iOTimeOut = iOTimeOut; - save(); - return this; - } - - public int getBuffSize() { - return buffSize; - } - - public BaseTaskConfig setBuffSize(int buffSize) { - this.buffSize = buffSize; - save(); - return this; - } - } - - /** - * 下载配置 - */ - public static class DownloadConfig extends BaseTaskConfig implements Serializable { - /** - * 下载线程数,下载线程数不能小于1 注意: 1、线程下载数改变后,新的下载任务才会生效; 2、如果任务大小小于1m,该设置不会生效; - * 3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间; 对于采用多线程的任务或旧任务,依然采用原来的文件空间占用方式; - */ - int threadNum = 3; - - /** - * 多线程下载是否使用块下载模式,{@code true}使用,{@code false}不使用 注意: 1、使用分块模式,在读写性能底下的手机上,合并文件需要的时间会更加长; - * 2、优点是使用多线程的块下载,初始化时,文件初始化时将不会预占用对应长度的空间; 3、只对新的多线程下载任务有效 4、只对多线程的任务有效 - */ - boolean useBlock = false; - - public boolean isUseBlock() { - return useBlock; - } - - @Override public DownloadConfig setMaxSpeed(int maxSpeed) { - super.setMaxSpeed(maxSpeed); - DownloadTaskQueue.getInstance().setMaxSpeed(maxSpeed); - return this; - } - - public DownloadConfig setUseBlock(boolean useBlock) { - this.useBlock = useBlock; - save(); - return this; - } - - public DownloadConfig setMaxTaskNum(int maxTaskNum) { - super.setMaxTaskNum(maxTaskNum); - DownloadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum); - return this; - } - - public DownloadConfig setThreadNum(int threadNum) { - this.threadNum = threadNum; - save(); - return this; - } - - public int getThreadNum() { - return threadNum; - } - - private DownloadConfig() { - } - - @Override int getType() { - return TYPE_DOWNLOAD; - } - } - - /** - * 上传配置 - */ - public static class UploadConfig extends BaseTaskConfig implements Serializable { - private static UploadConfig INSTANCE = null; - - private UploadConfig() { - //loadConfig(); - } - - @Override public UploadConfig setMaxSpeed(int maxSpeed) { - super.setMaxSpeed(maxSpeed); - UploadTaskQueue.getInstance().setMaxSpeed(maxSpeed); - return this; - } - - public UploadConfig setMaxTaskNum(int maxTaskNum) { - super.setMaxTaskNum(maxTaskNum); - UploadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum); - return this; - } - - static UploadConfig getInstance() { - if (INSTANCE == null) { - synchronized (UploadConfig.class) { - INSTANCE = new UploadConfig(); - } - } - return INSTANCE; - } - - @Override int getType() { - return TYPE_UPLOAD; - } - } - - /** - * 下载类型的组合任务 - */ - public static class DGroupConfig extends BaseTaskConfig implements Serializable { - - private static DGroupConfig INSTANCE = null; - - /** - * 能同时下载的子任务最大任务数,默认3 - */ - int subMaxTaskNum = 3; - - /** - * 子任务重试次数,默认为5 - */ - int subReTryNum = 5; - - /** - * 子任务下载失败时的重试间隔,单位为毫秒,默认2000毫秒- - */ - int subReTryInterval = 2000; - - private DGroupConfig() { - } - - static DGroupConfig getInstance() { - if (INSTANCE == null) { - synchronized (DGroupConfig.class) { - INSTANCE = new DGroupConfig(); - } - } - return INSTANCE; - } - - @Override int getType() { - return TYPE_DGROUP; - } - - @Override public DGroupConfig setMaxSpeed(int maxSpeed) { - super.setMaxSpeed(maxSpeed); - DownloadGroupTaskQueue.getInstance().setMaxSpeed(maxSpeed); - return this; - } - - public DGroupConfig setMaxTaskNum(int maxTaskNum) { - super.setMaxTaskNum(maxTaskNum); - DownloadGroupTaskQueue.getInstance().setMaxTaskNum(maxSpeed); - return this; - } - - public int getSubMaxTaskNum() { - return subMaxTaskNum; - } - - public DGroupConfig setSubMaxTaskNum(int subMaxTaskNum) { - this.subMaxTaskNum = subMaxTaskNum; - save(); - return this; - } - - public int getSubReTryNum() { - return subReTryNum; - } - - public DGroupConfig setSubReTryNum(int subReTryNum) { - this.subReTryNum = subReTryNum; - save(); - return this; - } - - public int getSubReTryInterval() { - return subReTryInterval; - } - - public DGroupConfig setSubReTryInterval(int subReTryInterval) { - this.subReTryInterval = subReTryInterval; - save(); - return this; - } - } - - /** - * 应用配置 - */ - public static class AppConfig extends BaseConfig implements Serializable { - /** - * 是否使用{@link AriaCrashHandler}来捕获异常 {@code true} 使用;{@code false} 不使用 - */ - boolean useAriaCrashHandler; - - /** - * 设置Aria的日志级别 - * - * {@link ALog#LOG_LEVEL_VERBOSE} - */ - int logLevel; - - /** - * 是否检查网络,{@code true}检查网络 - */ - boolean netCheck = true; - - /** - * 是否使用广播 除非无法使用注解,否则不建议使用广播来接受任务 {@code true} 使用广播,{@code false} 不适用广播 - */ - boolean useBroadcast = false; - - /** - * 断网的时候是否重试,{@code true}断网也重试;{@code false}断网不重试,直接走失败的回调 - */ - boolean notNetRetry = false; - - public boolean isNotNetRetry() { - return notNetRetry; - } - - public AppConfig setNotNetRetry(boolean notNetRetry) { - this.notNetRetry = notNetRetry; - save(); - return this; - } - - public boolean isUseBroadcast() { - return useBroadcast; - } - - public AppConfig setUseBroadcast(boolean useBroadcast) { - this.useBroadcast = useBroadcast; - save(); - return this; - } - - public boolean isNetCheck() { - return netCheck; - } - - public AppConfig setNetCheck(boolean netCheck) { - this.netCheck = netCheck; - save(); - return this; - } - - public AppConfig setLogLevel(int level) { - this.logLevel = level; - ALog.LOG_LEVEL = level; - save(); - return this; - } - - public int getLogLevel() { - return logLevel; - } - - public boolean getUseAriaCrashHandler() { - return useAriaCrashHandler; - } - - public AppConfig setUseAriaCrashHandler(boolean useAriaCrashHandler) { - this.useAriaCrashHandler = useAriaCrashHandler; - if (useAriaCrashHandler) { - Thread.setDefaultUncaughtExceptionHandler(new AriaCrashHandler()); - } else { - Thread.setDefaultUncaughtExceptionHandler(null); - } - save(); - return this; - } - - @Override int getType() { - return TYPE_APP; - } - } -} diff --git a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java index 1281a680..b37bf5c5 100644 --- a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java +++ b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java @@ -27,11 +27,11 @@ import com.arialyy.aria.core.upload.uploader.SimpleUploadUtil; */ public class UploadTask extends AbsNormalTask { - private UploadTask(UTaskWrapper taskEntity, Handler outHandler) { - mTaskWrapper = taskEntity; + private UploadTask(UTaskWrapper taskWrapper, Handler outHandler) { + mTaskWrapper = taskWrapper; mOutHandler = outHandler; mListener = new BaseUListener(this, mOutHandler); - mUtil = new SimpleUploadUtil(taskEntity, (IUploadListener) mListener); + mUtil = new SimpleUploadUtil(taskWrapper, (IUploadListener) mListener); } @Override public int getTaskType() {