pull/330/head
laoyuyu 6 years ago
commit 542ea8c42f
  1. 20
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  2. 2
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  3. 3
      Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java
  4. 4
      README.md
  5. 2
      build.gradle

@ -16,6 +16,7 @@
package com.arialyy.aria.core.common; package com.arialyy.aria.core.common;
import android.content.Context; import android.content.Context;
import android.util.SparseArray;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
@ -64,11 +65,9 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
protected StateConstance mConstance; protected StateConstance mConstance;
//总线程数 //总线程数
protected int mTotalThreadNum; protected int mTotalThreadNum;
//启动线程数
private int mStartThreadNum;
//已完成的线程数 //已完成的线程数
private int mCompleteThreadNum; private int mCompleteThreadNum;
private Map<Integer, AbsThreadTask> mTask = new HashMap<>(); private SparseArray<AbsThreadTask> mTask = new SparseArray<>();
private Timer mTimer; private Timer mTimer;
@Deprecated private File mConfigFile; @Deprecated private File mConfigFile;
@ -111,8 +110,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
closeTimer(); closeTimer();
mCompleteThreadNum = 0; mCompleteThreadNum = 0;
mTotalThreadNum = 0; mTotalThreadNum = 0;
mStartThreadNum = 0; if (mTask != null && mTask.size() != 0) {
if (mTask != null && !mTask.isEmpty()) {
for (int i = 0; i < mTask.size(); i++) { for (int i = 0; i < mTask.size(); i++) {
AbsThreadTask task = mTask.get(i); AbsThreadTask task = mTask.get(i);
if (task != null && !task.isRunning()) { if (task != null && !task.isRunning()) {
@ -137,7 +135,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
mConstance.TASK_RECORD = mRecord; mConstance.TASK_RECORD = mRecord;
if (!mTaskEntity.isSupportBP()) { if (!mTaskEntity.isSupportBP()) {
mTotalThreadNum = 1; mTotalThreadNum = 1;
mStartThreadNum = 1;
} else { } else {
mTotalThreadNum = mTotalThreadNum =
mTaskEntity.isNewTask() ? setNewTaskThreadNum() : mTotalThreadNum; mTaskEntity.isNewTask() ? setNewTaskThreadNum() : mTotalThreadNum;
@ -252,7 +249,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
closeTimer(); closeTimer();
mConstance.isRunning = false; mConstance.isRunning = false;
mConstance.isCancel = true; mConstance.isCancel = true;
for (int i = 0; i < mStartThreadNum; i++) { for (int i = 0; i < mTask.size(); i++) {
AbsThreadTask task = mTask.get(i); AbsThreadTask task = mTask.get(i);
if (task != null) { if (task != null) {
task.cancel(); task.cancel();
@ -266,7 +263,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
mConstance.isRunning = false; mConstance.isRunning = false;
mConstance.isStop = true; mConstance.isStop = true;
if (mConstance.isComplete()) return; if (mConstance.isComplete()) return;
for (int i = 0; i < mStartThreadNum; i++) { for (int i = 0; i < mTask.size(); i++) {
AbsThreadTask task = mTask.get(i); AbsThreadTask task = mTask.get(i);
if (task != null && !task.isThreadComplete()) { if (task != null && !task.isThreadComplete()) {
task.stop(); task.stop();
@ -338,7 +335,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
tr.startLocation = 0; tr.startLocation = 0;
tr.isComplete = false; tr.isComplete = false;
tr.endLocation = mEntity.getFileSize(); tr.endLocation = mEntity.getFileSize();
mStartThreadNum++;
} else if (file.length() == mEntity.getFileSize()) { } else if (file.length() == mEntity.getFileSize()) {
tr.isComplete = true; tr.isComplete = true;
mCompleteThreadNum++; mCompleteThreadNum++;
@ -348,14 +344,11 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
tr.startLocation = file.length(); tr.startLocation = file.length();
tr.isComplete = false; tr.isComplete = false;
} }
mStartThreadNum++;
} }
} else { } else {
for (ThreadRecord tr : mRecord.threadRecords) { for (ThreadRecord tr : mRecord.threadRecords) {
if (tr.isComplete) { if (tr.isComplete) {
mCompleteThreadNum++; mCompleteThreadNum++;
} else {
mStartThreadNum++;
} }
} }
} }
@ -376,7 +369,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
ALog.i(TAG, String.format("分块文件【%s】不存在,该分块将重新开始", temp.getPath())); ALog.i(TAG, String.format("分块文件【%s】不存在,该分块将重新开始", temp.getPath()));
tr.isComplete = false; tr.isComplete = false;
tr.startLocation = -1; tr.startLocation = -1;
mStartThreadNum++;
} else { } else {
if (tr.isComplete) { if (tr.isComplete) {
mCompleteThreadNum++; mCompleteThreadNum++;
@ -400,7 +392,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
temp.delete(); temp.delete();
tr.startLocation = i * blockLen; tr.startLocation = i * blockLen;
} }
mStartThreadNum++;
} }
} }
} }
@ -453,7 +444,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
tRecord.isComplete = true; tRecord.isComplete = true;
continue; continue;
} }
mStartThreadNum++;
if (record != null) { if (record != null) {
Long temp = Long.parseLong(String.valueOf(record)); Long temp = Long.parseLong(String.valueOf(record));
tRecord.startLocation = temp > 0 ? temp : 0; tRecord.startLocation = temp > 0 ? temp : 0;

@ -455,7 +455,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
} }
@Override public AbsThreadTask call() throws Exception { @Override public AbsThreadTask call() throws Exception {
isInterrupted = true; isInterrupted = false;
return this; return this;
} }
} }

@ -81,7 +81,8 @@ public class ThreadTaskManager {
ALog.e(TAG, "线程池已经关闭"); ALog.e(TAG, "线程池已经关闭");
return; return;
} }
Set<Future> temp = mThreadTasks.get(getKey(key)); key = getKey(key);
Set<Future> temp = mThreadTasks.get(key);
try { try {
for (Future future : temp) { for (Future future : temp) {
if (future.isDone() || future.isCancelled()) { if (future.isDone() || future.isCancelled()) {

@ -32,8 +32,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.15' compile 'com.arialyy.aria:aria-core:3.4.16'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.4.15' annotationProcessor 'com.arialyy.aria:aria-compiler:3.4.16'
``` ```
如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:<last-version>'`替换为 如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:<last-version>'`替换为
``` ```

@ -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.15' publishVersion = '3.4.16'
// publishVersion = '1.0.3' //FTP插件 // publishVersion = '1.0.3' //FTP插件
repoName='maven' repoName='maven'
desc = 'android 下载框架' desc = 'android 下载框架'

Loading…
Cancel
Save