pull/330/head
laoyuyu 7 years ago
parent 3c05d8cafc
commit d47ac22dfa
  1. 5
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  2. 45
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  3. 5
      Aria/src/main/java/com/arialyy/aria/core/common/ThreadRecord.java
  4. 3
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  5. 5
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  7. 1
      DEV_LOG.md
  8. 15
      README.md
  9. 2
      app/src/main/assets/aria_config.xml
  10. 2
      build.gradle

@ -567,6 +567,11 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
} else { } else {
tr = mRecord.threadRecords.get(i); tr = mRecord.threadRecords.get(i);
} }
if (tr.blockLen == 0) {
tr.blockLen = i == mTotalThreadNum - 1 ? (fileLength - i * blockSize) : blockSize;
}
if (tr.isComplete) {//该线程已经完成 if (tr.isComplete) {//该线程已经完成
if (resumeRecordLocation(i, startL, endL)) return; if (resumeRecordLocation(i, startL, endL)) return;
continue; continue;

@ -44,10 +44,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
* 线程重试次数 * 线程重试次数
*/ */
private final int RETRY_NUM = 2; private final int RETRY_NUM = 2;
/**
* 线程重试间隔
*/
private final int RETRY_INTERVAL = 5000;
private final String TAG = "AbsThreadTask"; private final String TAG = "AbsThreadTask";
/** /**
* 当前子线程的下载位置 * 当前子线程的下载位置
@ -296,7 +293,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
protected void fail(final long subCurrentLocation, String msg, Exception ex, boolean needRetry) { protected void fail(final long subCurrentLocation, String msg, Exception ex, boolean needRetry) {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
if (ex != null) { if (ex != null) {
//ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex)); ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex));
} else { } else {
ALog.e(TAG, msg); ALog.e(TAG, msg);
} }
@ -327,6 +324,8 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
} }
if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected(AriaManager.APP) if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected(AriaManager.APP)
|| isNotNetRetry) && !isBreak()) { || isNotNetRetry) && !isBreak()) {
ALog.w(TAG,
String.format("任务【%s】thread__%s__正在重试", mConfig.TEMP_FILE.getName(), mConfig.THREAD_ID));
mFailTimer = new Timer(true); mFailTimer = new Timer(true);
mFailTimer.schedule(new TimerTask() { mFailTimer.schedule(new TimerTask() {
@Override public void run() { @Override public void run() {
@ -335,12 +334,10 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
return; return;
} }
mFailTimes++; mFailTimes++;
ALog.w(TAG, String.format("任务【%s】thread__%s__正在重试", mConfig.TEMP_FILE.getName(),
mConfig.THREAD_ID));
handleRetryRecord(); handleRetryRecord();
AbsThreadTask.this.run(); AbsThreadTask.this.run();
} }
}, RETRY_INTERVAL); }, 3000);
} else { } else {
handleFailState(!isBreak()); handleFailState(!isBreak());
} }
@ -365,18 +362,12 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
STATE.COMPLETE_THREAD_NUM++; STATE.COMPLETE_THREAD_NUM++;
tr.isComplete = true; tr.isComplete = true;
} else { } else {
tr.startLocation = file.length(); tr.startLocation = block * tr.threadId + file.length();
mConfig.START_LOCATION = file.length(); mConfig.START_LOCATION = tr.startLocation;
tr.isComplete = false; tr.isComplete = false;
long size = 0; STATE.CURRENT_LOCATION = getBlockRealTotalSize();
for (int i = 0, len = getTaskRecord().threadRecords.size(); i < len; i++) { ALog.i(TAG, String.format("修正分块【%s】进度,开始位置:%s,当前进度:%s", file.getPath(), tr.startLocation,
File temp = new File(String.format(AbsFileer.SUB_PATH, getTaskRecord().filePath, i)); STATE.CURRENT_LOCATION));
if (temp.exists()) {
size += file.length();
}
}
STATE.CURRENT_LOCATION = size;
ALog.i(TAG, String.format("修正分块【%s】进度,开始位置:%s", file.getPath(), tr.startLocation));
} }
} else { } else {
mConfig.START_LOCATION = mChildCurrentLocation == 0 ? mConfig.START_LOCATION mConfig.START_LOCATION = mChildCurrentLocation == 0 ? mConfig.START_LOCATION
@ -384,6 +375,22 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
} }
} }
/**
* 获取分块任务真实的进度
*
* @return 进度
*/
private long getBlockRealTotalSize() {
long size = 0;
for (int i = 0, len = getTaskRecord().threadRecords.size(); i < len; i++) {
File temp = new File(String.format(AbsFileer.SUB_PATH, getTaskRecord().filePath, i));
if (temp.exists()) {
size += temp.length();
}
}
return size;
}
/** /**
* 处理失败状态 * 处理失败状态
* *

@ -47,4 +47,9 @@ public class ThreadRecord extends DbEntity {
* 线程id * 线程id
*/ */
public int threadId = -1; public int threadId = -1;
/**
* 分块长度
*/
public long blockLen = 0;
} }

@ -493,8 +493,7 @@ public abstract class AbsGroupUtil implements IUtil {
subEntity.setFailNum(subEntity.getFailNum() + 1); subEntity.setFailNum(subEntity.getFailNum() + 1);
saveData(IEntity.STATE_FAIL, lastLen); saveData(IEntity.STATE_FAIL, lastLen);
handleSpeed(0); handleSpeed(0);
//reTry(needRetry); reTry(needRetry);
reTry(false);
} }
/** /**

@ -143,11 +143,6 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
if (mSleepTime > 0) { if (mSleepTime > 0) {
Thread.sleep(mSleepTime); Thread.sleep(mSleepTime);
} }
//
//bf.flip();
//foc.write(bf);
//bf.compact();
//progress(len);
if (mChildCurrentLocation + len >= mConfig.END_LOCATION) { if (mChildCurrentLocation + len >= mConfig.END_LOCATION) {
len = (int) (mConfig.END_LOCATION - mChildCurrentLocation); len = (int) (mConfig.END_LOCATION - mChildCurrentLocation);
bf.flip(); bf.flip();

@ -35,7 +35,7 @@ class DBConfig {
/*adb pull /mnt/sdcard/Android/data/com.arialyy.simple/files/DB/AriaLyyDb d:/db*/ /*adb pull /mnt/sdcard/Android/data/com.arialyy.simple/files/DB/AriaLyyDb d:/db*/
static Map<String, Class> mapping = new HashMap<>(); static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME; static String DB_NAME;
static int VERSION = 39; static int VERSION = 40;
/** /**
* 是否将数据库保存在Sd卡{@code true} * 是否将数据库保存在Sd卡{@code true}

@ -1,6 +1,7 @@
## 开发日志 ## 开发日志
+ v_3.4.6 + v_3.4.6
- 修复android 4.4.4 版本多dex下无法进行回调的问题 - 修复android 4.4.4 版本多dex下无法进行回调的问题
- 新增`updateUrl(newUrl)`用于修改任务的url,[see](https://aria.laoyuyu.me/aria_doc/api/task_handle.html#%E6%9B%B4%E6%96%B0%E4%BB%BB%E5%8A%A1url)
- 优化分块下载 - 优化分块下载
- 修复了字符串中有特殊字符导致的路径冲突问题;修复ftp分块下载失败问题 - 修复了字符串中有特殊字符导致的路径冲突问题;修复ftp分块下载失败问题
- 修复连接中有`+`导致的地址呗使用问题。 - 修复连接中有`+`导致的地址呗使用问题。

@ -31,8 +31,8 @@ Aria有以下特点:
[![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion)
[![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion)
```java ```java
compile 'com.arialyy.aria:aria-core:3.4.5' compile 'com.arialyy.aria:aria-core:3.4.6'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.4.5' annotationProcessor 'com.arialyy.aria:aria-compiler:3.4.6'
``` ```
如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:<last-version>'`替换为 如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:<last-version>'`替换为
``` ```
@ -100,10 +100,13 @@ protected void onCreate(Bundle savedInstanceState) {
### 版本日志 ### 版本日志
+ v_3.4.4 + v_3.4.6
- 实现[多线程分块下载](https://aria.laoyuyu.me/aria_doc/start/config.html) - 修复android 4.4.4 版本多dex下无法进行回调的问题
- 修复`stopAll()`和`resumeAll()`导致的进度为0问题 - 新增`updateUrl(newUrl)`用于修改任务的url,[see](https://aria.laoyuyu.me/aria_doc/api/task_handle.html#%E6%9B%B4%E6%96%B0%E4%BB%BB%E5%8A%A1url)
- 修复任务组添加header无效的问题 - 优化分块下载
- 修复了字符串中有特殊字符导致的路径冲突问题;修复ftp分块下载失败问题
- 修复连接中有`+`导致的地址呗使用问题。
- 修复表重复创建导致的崩溃问题 https://github.com/AriaLyy/Aria/issues/264
[更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md)

@ -37,7 +37,7 @@
<maxTaskNum value="1"/> <maxTaskNum value="1"/>
<!--设置下载失败,重试次数,默认为10--> <!--设置下载失败,重试次数,默认为10-->
<reTryNum value="2"/> <reTryNum value="1"/>
<!--设置重试间隔,单位为毫秒,默认2000毫秒--> <!--设置重试间隔,单位为毫秒,默认2000毫秒-->
<reTryInterval value="5000"/> <reTryInterval value="5000"/>

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

Loading…
Cancel
Save