Skip to content
Permalink
Browse files

修复一个表创建失败的问题 #570

修复一个非分块模式下导致下载失败的问题 #571
修复一个服务器端无法创建socket连接,却没有返回码导致客户端卡住的问题 #569
修复文件删除后,组合任务没有重新下载的问题 #574
优化缓存队列和执行队列
  • Loading branch information
AriaLyy committed Dec 22, 2019
1 parent 27c889e commit 8dc16ce302d824313b1fa661132ed3832910a2a9
Showing with 563 additions and 718 deletions.
  1. +1 −1 AppFrame/build.gradle
  2. +8 −4 Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  3. +23 −24 Aria/src/main/java/com/arialyy/aria/core/queue/DTaskQueue.java
  4. +20 −57 Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java
  5. +30 −61 Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java
  6. +2 −1 Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadExecutePool.java
  7. +11 −20 Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadExecutePool.java
  8. +7 −1 DEV_LOG.md
  9. +0 −4 FtpComponent/src/main/java/aria/apache/commons/net/ftp/FTPClient.java
  10. +2 −1 FtpComponent/src/main/java/com/arialyy/aria/ftp/BaseFtpThreadTaskAdapter.java
  11. +4 −6 FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUFileInfoThread.java
  12. +45 −6 FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUThreadTaskAdapter.java
  13. +5 −0 HttpComponent/src/main/java/com/arialyy/aria/http/HttpFileInfoThread.java
  14. +1 −0 HttpComponent/src/main/java/com/arialyy/aria/http/download/DGroupLoaderUtil.java
  15. +1 −0 HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java
  16. +18 −8 PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java
  17. +12 −1 PublicComponent/src/main/java/com/arialyy/aria/core/group/AbsGroupUtil.java
  18. +3 −2 PublicComponent/src/main/java/com/arialyy/aria/core/listener/BaseListener.java
  19. +11 −6 PublicComponent/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java
  20. +1 −1 PublicComponent/src/main/java/com/arialyy/aria/core/task/AbsTask.java
  21. +5 −0 PublicComponent/src/main/java/com/arialyy/aria/core/wrapper/ITaskWrapper.java
  22. +2 −53 PublicComponent/src/main/java/com/arialyy/aria/orm/AbsDelegate.java
  23. +0 −242 PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateCommon.java
  24. +4 −0 PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateFind.java
  25. +6 −2 PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java
  26. +3 −4 PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateWrapper.java
  27. +15 −20 PublicComponent/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  28. +280 −3 PublicComponent/src/main/java/com/arialyy/aria/orm/SqlUtil.java
  29. +1 −0 PublicComponent/src/main/java/com/arialyy/aria/util/ComponentUtil.java
  30. +14 −21 README.md
  31. +1 −1 app/src/main/assets/aria_config.xml
  32. +0 −161 app/src/main/assets/aria_config_1.xml
  33. +2 −0 app/src/main/java/com/arialyy/simple/MainActivity.java
  34. +1 −1 app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java
  35. +2 −1 app/src/main/java/com/arialyy/simple/modlue/CommonModule.java
  36. +15 −0 app/src/main/res/drawable/ic_sftp.xml
  37. +5 −3 app/src/main/res/values/strings.xml
  38. +2 −2 build.gradle
@@ -35,7 +35,7 @@ dependencies {
api 'com.google.code.gson:gson:2.8.2'
api 'io.reactivex:rxandroid:1.2.0'
api 'io.reactivex:rxjava:1.1.5'
implementation 'com.squareup.okhttp3:okhttp:3.2.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
@@ -95,8 +95,7 @@
* 停止所有任务
*/
@Override public void stopAllTask() {
for (String key : mExecutePool.getAllTask().keySet()) {
TASK task = mExecutePool.getAllTask().get(key);
for (TASK task : mExecutePool.getAllTask()) {
if (task != null) {
int state = task.getState();
if (task.isRunning() || (state != IEntity.STATE_COMPLETE
@@ -106,8 +105,13 @@
}
}

for (String key : mCachePool.getAllTask().keySet()) {
TASK task = mCachePool.getAllTask().get(key);
//for (String key : mCachePool.getAllTask().keySet()) {
// TASK task = mCachePool.getAllTask().get(key);
// if (task != null) {
// task.stop(TaskSchedulerType.TYPE_STOP_NOT_NEXT);
// }
//}
for (TASK task : mCachePool.getAllTask()) {
if (task != null) {
task.stop(TaskSchedulerType.TYPE_STOP_NOT_NEXT);
}
@@ -26,7 +26,7 @@
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.ALog;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.List;
import java.util.Set;

/**
@@ -68,40 +68,39 @@ public void maxTaskNum(DMaxNumEvent event) {
*/
public void setTaskHighestPriority(DownloadTask task) {
task.setHighestPriority(true);
Map<String, DownloadTask> exeTasks = mExecutePool.getAllTask();
//Map<String, DownloadTask> exeTasks = mExecutePool.getAllTask();
List<DownloadTask> exeTasks = mExecutePool.getAllTask();
if (exeTasks != null && !exeTasks.isEmpty()) {
Set<String> keys = exeTasks.keySet();
for (String key : keys) {
DownloadTask temp = exeTasks.get(key);
for (DownloadTask temp : exeTasks) {
if (temp != null && temp.isRunning() && temp.isHighestPriorityTask() && !temp.getKey()
.equals(task.getKey())) {
ALog.e(TAG, "设置最高优先级任务失败,失败原因【任务中已经有最高优先级任务,请等待上一个最高优先级任务完成,或手动暂停该任务】");
task.setHighestPriority(false);
return;
}
}
}
int maxSize = AriaConfig.getInstance().getDConfig().getMaxTaskNum();
int currentSize = mExecutePool.size();
if (currentSize == 0 || currentSize < maxSize) {
startTask(task);
} else {
Set<DownloadTask> tempTasks = new LinkedHashSet<>();
for (int i = 0; i < maxSize; i++) {
DownloadTask oldTsk = mExecutePool.pollTask();
if (oldTsk != null && oldTsk.isRunning()) {
if (i == maxSize - 1) {
oldTsk.stop(TaskSchedulerType.TYPE_STOP_AND_WAIT);
mCachePool.putTaskToFirst(oldTsk);
break;
int maxSize = AriaConfig.getInstance().getDConfig().getMaxTaskNum();
int currentSize = mExecutePool.size();
if (currentSize == 0 || currentSize < maxSize) {
startTask(task);
} else {
Set<DownloadTask> tempTasks = new LinkedHashSet<>();
for (int i = 0; i < maxSize; i++) {
DownloadTask oldTsk = mExecutePool.pollTask();
if (oldTsk != null && oldTsk.isRunning()) {
if (i == maxSize - 1) {
oldTsk.stop(TaskSchedulerType.TYPE_STOP_AND_WAIT);
mCachePool.putTaskToFirst(oldTsk);
break;
}
tempTasks.add(oldTsk);
}
tempTasks.add(oldTsk);
}
}
startTask(task);
startTask(task);

for (DownloadTask temp : tempTasks) {
mExecutePool.putTask(temp);
for (DownloadTask temp : tempTasks) {
mExecutePool.putTask(temp);
}
}
}
}
@@ -20,65 +20,43 @@
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.concurrent.LinkedBlockingDeque;

/**
* Created by lyy on 2016/8/14. 任务缓存池,所有下载任务最先缓存在这个池中
*/
public class BaseCachePool<TASK extends AbsTask> implements IPool<TASK> {
private static final String TAG = "BaseCachePool";
private final String TAG = CommonUtil.getClassName(this);
private static final int MAX_NUM = Integer.MAX_VALUE; //最大下载任务数
private static final long TIME_OUT = 1000;
private static final Object LOCK = new Object();
private Map<String, TASK> mCacheMap;
private LinkedBlockingQueue<TASK> mCacheQueue;
private Deque<TASK> mCacheQueue;

BaseCachePool() {
mCacheQueue = new LinkedBlockingQueue<>(MAX_NUM);
mCacheMap = new ConcurrentHashMap<>();
mCacheQueue = new LinkedBlockingDeque<>(MAX_NUM);
}

/**
* 获取被缓存的任务
*/
public Map<String, TASK> getAllTask() {
return mCacheMap;
public List<TASK> getAllTask() {
return new ArrayList<>(mCacheQueue);
}

/**
* 清除所有缓存的任务
*/
public void clear() {
for (String key : mCacheMap.keySet()) {
TASK task = mCacheMap.get(key);
mCacheQueue.remove(task);
mCacheMap.remove(key);
}
mCacheQueue.clear();
}

/**
* 将任务放在队首
*/
public boolean putTaskToFirst(TASK task) {
if (mCacheQueue.isEmpty()) {
return putTask(task);
} else {
Set<TASK> temps = new LinkedHashSet<>();
temps.add(task);
for (int i = 0, len = size(); i < len; i++) {
TASK temp = pollTask();
temps.add(temp);
}
for (TASK t : temps) {
putTask(t);
}
return true;
}
return mCacheQueue.offerFirst(task);
}

@Override public boolean putTask(TASK task) {
@@ -87,36 +65,21 @@ public boolean putTaskToFirst(TASK task) {
ALog.e(TAG, "任务不能为空!!");
return false;
}
String key = task.getKey();
if (mCacheQueue.contains(task)) {
ALog.w(TAG, "任务【" + task.getTaskName() + "】进入缓存队列失败,原因:已经在缓存队列中");
return false;
} else {
boolean s = mCacheQueue.offer(task);
ALog.d(TAG, "任务【" + task.getTaskName() + "】进入缓存队列" + (s ? "成功" : "失败"));
if (s) {
mCacheMap.put(CommonUtil.keyToHashKey(key), task);
}
return s;
}
}
}

@Override public TASK pollTask() {
synchronized (LOCK) {
try {
TASK task;
task = mCacheQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
if (task != null) {
String url = task.getKey();
mCacheMap.remove(CommonUtil.keyToHashKey(url));
}
return task;
} catch (InterruptedException e) {
e.printStackTrace();
}
return mCacheQueue.pollFirst();
}
return null;
}

@Override public TASK getTask(String key) {
@@ -125,12 +88,17 @@ public boolean putTaskToFirst(TASK task) {
ALog.e(TAG, "key 为null");
return null;
}
return mCacheMap.get(CommonUtil.keyToHashKey(key));
for (TASK task : mCacheQueue) {
if (task.getKey().equals(key)) {
return task;
}
}
}
return null;
}

@Override public boolean taskExits(String key) {
return mCacheMap.containsKey(CommonUtil.keyToHashKey(key));
return getTask(key) != null;
}

@Override public boolean removeTask(TASK task) {
@@ -139,8 +107,6 @@ public boolean putTaskToFirst(TASK task) {
ALog.e(TAG, "任务不能为空");
return false;
} else {
String key = CommonUtil.keyToHashKey(task.getKey());
mCacheMap.remove(key);
return mCacheQueue.remove(task);
}
}
@@ -152,10 +118,7 @@ public boolean putTaskToFirst(TASK task) {
ALog.e(TAG, "请传入有效的下载链接");
return false;
}
String temp = CommonUtil.keyToHashKey(key);
TASK task = mCacheMap.get(temp);
mCacheMap.remove(temp);
return mCacheQueue.remove(task);
return mCacheQueue.remove(getTask(key));
}
}

0 comments on commit 8dc16ce

Please sign in to comment.
You can’t perform that action at this time.