Skip to content

Commit

Permalink
3.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
AriaLyy committed Jul 6, 2018
1 parent 3c05d8c commit d47ac22
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 35 deletions.
Expand Up @@ -567,6 +567,11 @@ private void handleBreakpoint() {
} else {
tr = mRecord.threadRecords.get(i);
}

if (tr.blockLen == 0) {
tr.blockLen = i == mTotalThreadNum - 1 ? (fileLength - i * blockSize) : blockSize;
}

if (tr.isComplete) {//该线程已经完成
if (resumeRecordLocation(i, startL, endL)) return;
continue;
Expand Down
45 changes: 26 additions & 19 deletions Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
Expand Up @@ -44,10 +44,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
* 线程重试次数
*/
private final int RETRY_NUM = 2;
/**
* 线程重试间隔
*/
private final int RETRY_INTERVAL = 5000;

private final String TAG = "AbsThreadTask";
/**
* 当前子线程的下载位置
Expand Down Expand Up @@ -296,7 +293,7 @@ protected void fail(final long subCurrentLocation, String msg, Exception ex) {
protected void fail(final long subCurrentLocation, String msg, Exception ex, boolean needRetry) {
synchronized (AriaManager.LOCK) {
if (ex != null) {
//ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex));
ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex));
} else {
ALog.e(TAG, msg);
}
Expand Down Expand Up @@ -327,6 +324,8 @@ private void retryThis(boolean needRetry) {
}
if (mFailTimes < RETRY_NUM && needRetry && (NetUtils.isConnected(AriaManager.APP)
|| isNotNetRetry) && !isBreak()) {
ALog.w(TAG,
String.format("任务【%s】thread__%s__正在重试", mConfig.TEMP_FILE.getName(), mConfig.THREAD_ID));
mFailTimer = new Timer(true);
mFailTimer.schedule(new TimerTask() {
@Override public void run() {
Expand All @@ -335,12 +334,10 @@ private void retryThis(boolean needRetry) {
return;
}
mFailTimes++;
ALog.w(TAG, String.format("任务【%s】thread__%s__正在重试", mConfig.TEMP_FILE.getName(),
mConfig.THREAD_ID));
handleRetryRecord();
AbsThreadTask.this.run();
}
}, RETRY_INTERVAL);
}, 3000);
} else {
handleFailState(!isBreak());
}
Expand All @@ -365,25 +362,35 @@ private void handleRetryRecord() {
STATE.COMPLETE_THREAD_NUM++;
tr.isComplete = true;
} else {
tr.startLocation = file.length();
mConfig.START_LOCATION = file.length();
tr.startLocation = block * tr.threadId + file.length();
mConfig.START_LOCATION = tr.startLocation;
tr.isComplete = false;
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 += file.length();
}
}
STATE.CURRENT_LOCATION = size;
ALog.i(TAG, String.format("修正分块【%s】进度,开始位置:%s", file.getPath(), tr.startLocation));
STATE.CURRENT_LOCATION = getBlockRealTotalSize();
ALog.i(TAG, String.format("修正分块【%s】进度,开始位置:%s,当前进度:%s", file.getPath(), tr.startLocation,
STATE.CURRENT_LOCATION));
}
} else {
mConfig.START_LOCATION = mChildCurrentLocation == 0 ? mConfig.START_LOCATION
: mConfig.THREAD_RECORD.startLocation;
}
}

/**
* 获取分块任务真实的进度
*
* @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;
}

/**
* 处理失败状态
*
Expand Down
Expand Up @@ -47,4 +47,9 @@ public class ThreadRecord extends DbEntity {
* 线程id
*/
public int threadId = -1;

/**
* 分块长度
*/
public long blockLen = 0;
}
Expand Up @@ -493,8 +493,7 @@ private class ChildDownloadListener implements IDownloadListener {
subEntity.setFailNum(subEntity.getFailNum() + 1);
saveData(IEntity.STATE_FAIL, lastLen);
handleSpeed(0);
//reTry(needRetry);
reTry(false);
reTry(needRetry);
}

/**
Expand Down
Expand Up @@ -143,11 +143,6 @@ private void readDynamicFile(InputStream is) {
if (mSleepTime > 0) {
Thread.sleep(mSleepTime);
}
//
//bf.flip();
//foc.write(bf);
//bf.compact();
//progress(len);
if (mChildCurrentLocation + len >= mConfig.END_LOCATION) {
len = (int) (mConfig.END_LOCATION - mChildCurrentLocation);
bf.flip();
Expand Down
2 changes: 1 addition & 1 deletion Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
Expand Up @@ -35,7 +35,7 @@ class DBConfig {
/*adb pull /mnt/sdcard/Android/data/com.arialyy.simple/files/DB/AriaLyyDb d:/db*/
static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME;
static int VERSION = 39;
static int VERSION = 40;

/**
* 是否将数据库保存在Sd卡,{@code true} 是
Expand Down
1 change: 1 addition & 0 deletions DEV_LOG.md
@@ -1,6 +1,7 @@
## 开发日志
+ v_3.4.6
- 修复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分块下载失败问题
- 修复连接中有`+`导致的地址呗使用问题。
Expand Down
15 changes: 9 additions & 6 deletions README.md
Expand Up @@ -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/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion)
```java
compile 'com.arialyy.aria:aria-core:3.4.5'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.4.5'
compile 'com.arialyy.aria:aria-core:3.4.6'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.4.6'
```
如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:<last-version>'`替换为
```
Expand Down Expand Up @@ -100,10 +100,13 @@ protected void onCreate(Bundle savedInstanceState) {


### 版本日志
+ v_3.4.4
- 实现[多线程分块下载](https://aria.laoyuyu.me/aria_doc/start/config.html)
- 修复`stopAll()``resumeAll()`导致的进度为0问题
- 修复任务组添加header无效的问题
+ v_3.4.6
- 修复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分块下载失败问题
- 修复连接中有`+`导致的地址呗使用问题。
- 修复表重复创建导致的崩溃问题 https://github.com/AriaLyy/Aria/issues/264

[更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md)

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/aria_config.xml
Expand Up @@ -37,7 +37,7 @@
<maxTaskNum value="1"/>

<!--设置下载失败,重试次数,默认为10-->
<reTryNum value="2"/>
<reTryNum value="1"/>

<!--设置重试间隔,单位为毫秒,默认2000毫秒-->
<reTryInterval value="5000"/>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -39,7 +39,7 @@ task clean(type: Delete) {
ext {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
publishVersion = '3.4.6_dev3'
publishVersion = '3.4.6'
// publishVersion = '1.0.3' //FTP插件
repoName='maven'
desc = 'android 下载框架'
Expand Down

0 comments on commit d47ac22

Please sign in to comment.