AriaLyy 7 years ago
parent fb76b012a0
commit 018b623830
  1. 7
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java
  2. 12
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  3. 16
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  4. 3
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java
  5. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  6. 6
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  7. 9
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java
  8. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/SimpleDownloadUtil.java
  9. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java
  10. 25
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  11. 4
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java
  12. 4
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  13. 9
      Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
  14. 4
      Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java
  15. 4
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  16. 5
      DEV_LOG.md
  17. 9
      app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java
  18. 1
      app/src/main/java/com/arialyy/simple/download/service_download/DownloadService.java

@ -116,6 +116,13 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
mQueue.startTask(tempTask);
}
/**
* 恢复任务
*/
void resumeTask() {
mQueue.resumeTask(tempTask);
}
/**
* 启动指定任务
*

@ -12,6 +12,7 @@ import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.NetUtils;
import java.util.ArrayList;
import java.util.List;
@ -105,13 +106,7 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
* 处理等待状态的任务
*/
private void resumeWaitTask() {
int maxTaskNum;
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
if (isDownloadCmd) {
maxTaskNum = manager.getDownloadConfig().getMaxTaskNum();
} else {
maxTaskNum = manager.getUploadConfig().getMaxTaskNum();
}
int maxTaskNum = mQueue.getMaxTaskNum();
if (mWaitList == null || mWaitList.isEmpty()) return;
for (AbsTaskEntity te : mWaitList) {
if (mQueue.getCurrentExePoolNum() < maxTaskNum) {
@ -129,6 +124,9 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
*/
private void resumeEntity(AbsTaskEntity te) {
if (te instanceof DownloadTaskEntity) {
if (te.requestType == AbsTaskEntity.FTP) {
te.urlEntity = CommonUtil.getFtpUrlInfo(te.getEntity().getKey());
}
mQueue = DownloadTaskQueue.getInstance();
} else if (te instanceof UploadTaskEntity) {
mQueue = UploadTaskQueue.getInstance();

@ -17,6 +17,7 @@
package com.arialyy.aria.core.command.normal;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.QueueMod;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
@ -24,13 +25,13 @@ import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.manager.TEManager;
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.core.upload.UploadTaskEntity;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.NetUtils;
import java.util.ArrayList;
import java.util.List;
@ -53,14 +54,12 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
return;
}
String mod;
int maxTaskNum;
int maxTaskNum = mQueue.getMaxTaskNum();
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
if (isDownloadCmd) {
mod = manager.getDownloadConfig().getQueueMod();
maxTaskNum = manager.getDownloadConfig().getMaxTaskNum();
} else {
mod = manager.getUploadConfig().getQueueMod();
maxTaskNum = manager.getUploadConfig().getMaxTaskNum();
}
AbsTask task = getTask();
@ -79,12 +78,14 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|| task.getState() == IEntity.STATE_OTHER
|| task.getState() == IEntity.STATE_POST_PRE
|| task.getState() == IEntity.STATE_COMPLETE) {
startTask();
//startTask();
resumeTask();
}
}
} else {
if (!task.isRunning()) {
startTask();
//startTask();
resumeTask();
}
}
if (mQueue.getCurrentCachePoolNum() == 0) {
@ -142,6 +143,9 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
for (AbsTaskEntity te : waitList) {
if (te.getEntity() == null) continue;
if (te instanceof DownloadTaskEntity) {
if (te.requestType == AbsTaskEntity.FTP) {
te.urlEntity = CommonUtil.getFtpUrlInfo(te.getEntity().getKey());
}
mQueue = DownloadTaskQueue.getInstance();
} else if (te instanceof UploadTaskEntity) {
mQueue = UploadTaskQueue.getInstance();

@ -89,6 +89,9 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
}
ALog.i(TAG,
"================================= --end-- ===================================");
}else {
String msg = client.getReplyString();
ALog.w(TAG, msg);
}
client.disconnect();
return;

@ -113,6 +113,8 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
return this;
}
@Override public DownloadEntity clone() throws CloneNotSupportedException {
return (DownloadEntity) super.clone();
}

@ -28,6 +28,7 @@ import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.ISchedulerListener;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList;
@ -68,6 +69,11 @@ public class DownloadReceiver extends AbsReceiver {
*/
public DownloadTarget load(DownloadEntity entity, boolean refreshInfo) {
CheckUtil.checkDownloadUrl(entity.getUrl());
if (entity.getUrl().startsWith("ftp")) {
ALog.w(TAG,
"使用实体启动FTP下载,如果你的FTP服务器需要登录,那么你需要调用登录的接口,如:Aria.download(this).load(url).login(user, pw).start()");
return new FtpDownloadTarget(entity, targetName, refreshInfo);
}
return new DownloadTarget(entity, targetName, refreshInfo);
}

@ -29,12 +29,21 @@ import java.io.File;
public class FtpDownloadTarget extends DownloadTarget {
private final String TAG = "FtpDownloadTarget";
FtpDownloadTarget(DownloadEntity entity, String targetName, boolean refreshInfo) {
super(entity, targetName, refreshInfo);
init(refreshInfo);
}
FtpDownloadTarget(String url, String targetName) {
this(url, targetName, false);
}
FtpDownloadTarget(String url, String targetName, boolean refreshInfo) {
super(url, targetName);
init(refreshInfo);
}
private void init(boolean refreshInfo) {
int lastIndex = url.lastIndexOf("/");
mEntity.setFileName(url.substring(lastIndex + 1, url.length()));
mTaskEntity.urlEntity = CommonUtil.getFtpUrlInfo(url);

@ -90,7 +90,9 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
@Override public void run() {
mListener.onPre();
if (mTaskEntity.getEntity().getFileSize() <= 1 || mTaskEntity.refreshInfo) {
if (mTaskEntity.getEntity().getFileSize() <= 1
|| mTaskEntity.refreshInfo
|| mTaskEntity.requestType == AbsTaskEntity.FTP) {
new Thread(createInfoThread()).start();
} else {
mDownloader.start();

@ -68,7 +68,7 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
/**
* 请求类型
* {@link AbsTaskEntity#HTTP}{@link AbsTaskEntity#FTP}
* {@link AbsTaskEntity#HTTP}{@link AbsTaskEntity#FTP}{@link AbsTaskEntity#FTP_DIR}
*/
public int requestType = HTTP;

@ -20,7 +20,6 @@ import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.queue.pool.BaseCachePool;
import com.arialyy.aria.core.queue.pool.BaseExecutePool;
import com.arialyy.aria.util.ALog;
@ -59,6 +58,23 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
}
}
/**
* 恢复任务
* 如果执行队列任务未满则直接启动任务
* 如果执行队列已经满了则暂停执行队列队首任务并恢复指定任务
*
* @param task 需要恢复飞任务
*/
@Override public void resumeTask(TASK task) {
if (mExecutePool.size() >= getMaxTaskNum()) {
task.getTaskEntity().getEntity().setState(IEntity.STATE_WAIT);
mCachePool.putTaskToFirst(task);
stopTask(mExecutePool.pollTask());
} else {
startTask(task);
}
}
/**
* 停止所有任务
*/
@ -70,10 +86,6 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
}
}
@Override public int getMaxTaskNum() {
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
}
/**
* 获取配置文件配置的最大可执行任务数
*/
@ -115,7 +127,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
int oldMaxSize = getConfigMaxNum();
int diff = downloadNum - oldMaxSize;
if (oldMaxSize == downloadNum) {
ALog.e(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过");
ALog.w(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过");
return;
}
//设置的任务数小于配置任务数
@ -174,7 +186,6 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
if (task != null) {
ALog.d(TAG, "从缓存池删除任务,删除" + (mCachePool.removeTask(task) ? "成功" : "失败"));
}
}
@Override public void reTryStart(TASK task) {

@ -56,6 +56,10 @@ public class DownloadGroupTaskQueue
return DownloadSharePool.getInstance().executePool;
}
@Override public int getMaxTaskNum() {
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
}
@Override public DownloadGroupTask createTask(String targetName, DownloadGroupTaskEntity entity) {
DownloadGroupTask task = null;
if (!TextUtils.isEmpty(targetName)) {

@ -135,4 +135,8 @@ public class DownloadTaskQueue
task.setHighestPriority(false);
super.stopTask(task);
}
@Override public int getMaxTaskNum() {
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
}
}

@ -38,6 +38,15 @@ public interface ITaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
*/
boolean taskIsRunning(String key);
/**
* 恢复任务
* 如果执行队列任务未满则直接启动任务
* 如果执行队列已经满了则暂停执行队列队首任务并恢复指定任务
*
* @param task 需要恢复飞任务
*/
void resumeTask(TASK task);
/**
* 停止所有任务
*/

@ -58,6 +58,10 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity>
return AriaManager.getInstance(AriaManager.APP).getUploadConfig().oldMaxTaskNum;
}
@Override public int getMaxTaskNum() {
return AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum();
}
@Override public UploadTask createTask(String targetName, UploadTaskEntity entity) {
UploadTask task = null;
if (!TextUtils.isEmpty(targetName)) {

@ -161,9 +161,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
}
case CANCEL:
mQueue.removeTaskFormQueue(task.getKey());
if (mQueue.getCurrentExePoolNum() < AriaManager.getInstance(AriaManager.APP)
.getUploadConfig()
.getMaxTaskNum()) {
if (mQueue.getCurrentExePoolNum() < mQueue.getMaxTaskNum()) {
startNextTask();
}
break;

@ -1,9 +1,10 @@
## 开发日志
+ v_3.3.6
- 增加日志输出级别控制
- 修复公网FTP地址不能下载的问题
- 修复http下载地址有空格的时候下载失败的问题
- 修复公网FTP地址不能下载的问题 https://github.com/AriaLyy/Aria/issues/146
- 修复http下载地址有空格的时候下载失败的问题 https://github.com/AriaLyy/Aria/issues/131
- 修复Activity在`onDestroy()`中调用`Aria.download(this).unRegister();`导致回调失效的问题
- 修复Adapter下载FTP任务问题、任务调度问题 https://github.com/AriaLyy/Aria/issues/157
- 优化代码,优化了IO性能
+ v_3.3.5 修复任务组、上传任务无法启动的bug
+ v_3.3.4 优化任务代码结构,修复上一个版本暂停后无法自动执行任务的问题

@ -37,8 +37,9 @@ import java.io.File;
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
//private final String URL = "ftp://192.168.1.9:21/下载/AriaPrj.zip";
//private final String URL = "ftp://192.168.1.9:21/下载/[电影天堂www.dy2018.com]赛车总动员3BD中英双字.mp4";
private final String URL = "ftp://h:h@tv.dl1234.com:2199/付岩洞复仇者们05.mkv";
//private final String URL = "ftp://172.18.104.64:21/upload/测试/成都.mp3";
//private final String URL = "ftp://h:h@tv.dl1234.com:2199/付岩洞复仇者们05.mkv";
//private final String URL = "ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]xd联盟HD高清国粤双语中字.mkv";
private final String URL = "ftp://172.18.104.71:21/upload/AS.zip";
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
@ -60,8 +61,8 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
switch (view.getId()) {
case R.id.start:
Aria.download(this).loadFtp(URL, true)
.charSet("GBK")
//.login("lao", "123456")
//.charSet("GBK")
.login("lao", "123456")
.setDownloadPath("/mnt/sdcard/").start();
break;
case R.id.stop:

@ -30,7 +30,6 @@ import com.arialyy.frame.util.show.T;
* 在服务中使用 Aria进行下载
*/
public class DownloadService extends Service {
private static final String DOWNLOAD_URL =
"http://rs.0.gaoshouyou.com/d/df/db/03df9eab61dbc48a5939f671f05f1cdf.apk";
private DownloadNotification mNotify;

Loading…
Cancel
Save