添加onWait注解,修复自动添加等待任务的bug

pull/330/head
e 7 years ago
parent b191bb2470
commit 1f3bd90b3b
  1. 10
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java
  2. 3
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java
  3. 5
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  4. 1
      Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java
  5. 6
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java
  6. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  7. 9
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java
  8. 13
      Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java
  9. 18
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  10. 13
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java
  11. 16
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  12. 120
      Aria/src/main/java/com/arialyy/aria/core/queue/QueueControl.java
  13. 13
      Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java
  14. 29
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java
  15. 11
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java
  16. 5
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java
  17. 7
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java
  18. 5
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  19. 10
      Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulerListener.java
  20. 4
      Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java
  21. 12
      Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java
  22. 25
      Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  23. 28
      AriaAnnotations/src/main/java/com/arialyy/annotations/Download.java
  24. 26
      AriaAnnotations/src/main/java/com/arialyy/annotations/DownloadGroup.java
  25. 25
      AriaAnnotations/src/main/java/com/arialyy/annotations/Upload.java
  26. 3
      AriaCompiler/src/main/java/com/arialyy/compiler/AriaProcessor.java
  27. 4
      AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java
  28. 1
      AriaCompiler/src/main/java/com/arialyy/compiler/ProxyConstance.java
  29. 3
      DEV_LOG.md
  30. 2
      README.md
  31. 7
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  32. 10
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  33. 3
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java
  34. 4
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java
  35. 8
      app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java
  36. 2
      app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java
  37. 4
      aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java

@ -27,6 +27,7 @@ import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -79,6 +80,15 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
isDownloadCmd = taskType < ICmd.TASK_TYPE_UPLOAD; isDownloadCmd = taskType < ICmd.TASK_TYPE_UPLOAD;
} }
/**
* 发送等待状态
*/
void sendWaitState() {
if (tempTask != null) {
tempTask.getOutHandler().obtainMessage(ISchedulers.WAIT, tempTask).sendToTarget();
}
}
/** /**
* 删除所有任务 * 删除所有任务
*/ */

@ -17,8 +17,8 @@
package com.arialyy.aria.core.command.normal; package com.arialyy.aria.core.command.normal;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
/** /**
@ -37,6 +37,7 @@ class AddCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
if (task == null) { if (task == null) {
mTaskEntity.getEntity().setState(IEntity.STATE_WAIT); mTaskEntity.getEntity().setState(IEntity.STATE_WAIT);
createTask(); createTask();
sendWaitState();
} else { } else {
ALog.w(TAG, "添加命令执行失败,【该任务已经存在】"); ALog.w(TAG, "添加命令执行失败,【该任务已经存在】");
} }

@ -79,6 +79,8 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|| task.getState() == IEntity.STATE_COMPLETE) { || task.getState() == IEntity.STATE_COMPLETE) {
//startTask(); //startTask();
resumeTask(); resumeTask();
} else {
sendWaitState();
} }
} }
} else { } else {
@ -141,6 +143,8 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
private void handleTask(List<AbsTaskEntity> waitList) { private void handleTask(List<AbsTaskEntity> waitList) {
for (AbsTaskEntity te : waitList) { for (AbsTaskEntity te : waitList) {
if (te.getEntity() == null) continue; if (te.getEntity() == null) continue;
AbsTask task = getTask(te.getEntity());
if (task != null) continue;
if (te instanceof DownloadTaskEntity) { if (te instanceof DownloadTaskEntity) {
if (te.requestType == AbsTaskEntity.D_FTP || te.requestType == AbsTaskEntity.U_FTP) { if (te.requestType == AbsTaskEntity.D_FTP || te.requestType == AbsTaskEntity.U_FTP) {
te.urlEntity = CommonUtil.getFtpUrlInfo(te.getEntity().getKey()); te.urlEntity = CommonUtil.getFtpUrlInfo(te.getEntity().getKey());
@ -152,6 +156,7 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
mQueue = DownloadGroupTaskQueue.getInstance(); mQueue = DownloadGroupTaskQueue.getInstance();
} }
createTask(te); createTask(te);
sendWaitState();
} }
} }
} }

@ -31,6 +31,7 @@ import java.lang.ref.WeakReference;
*/ */
class BaseDListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>, TASK extends AbsTask<TASK_ENTITY>> class BaseDListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>, TASK extends AbsTask<TASK_ENTITY>>
implements IDownloadListener { implements IDownloadListener {
private static final String TAG = "BaseDListener";
protected WeakReference<Handler> outHandler; protected WeakReference<Handler> outHandler;
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度 private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
private long mLastLen = 0; //上一次发送长度 private long mLastLen = 0; //上一次发送长度

@ -17,6 +17,7 @@ package com.arialyy.aria.core.download;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.downloader.DownloadGroupUtil; import com.arialyy.aria.core.download.downloader.DownloadGroupUtil;
@ -81,6 +82,11 @@ public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity> {
mUtil.cancel(); mUtil.cancel();
} }
@Override public String getTaskName() {
return "任务组->" + (TextUtils.isEmpty(mTaskEntity.getEntity().getAlias())
? mTaskEntity.getEntity().getGroupName() : mTaskEntity.getEntity().getAlias());
}
public static class Builder { public static class Builder {
DownloadGroupTaskEntity taskEntity; DownloadGroupTaskEntity taskEntity;
Handler outHandler; Handler outHandler;

@ -148,6 +148,10 @@ public class DownloadTask extends AbsNormalTask<DownloadTaskEntity> {
mUtil.cancel(); mUtil.cancel();
} }
@Override public String getTaskName() {
return mEntity.getFileName();
}
public static class Builder { public static class Builder {
DownloadTaskEntity taskEntity; DownloadTaskEntity taskEntity;
Handler outHandler; Handler outHandler;

@ -38,6 +38,10 @@ public abstract class AbsTask<TASK_ENTITY extends AbsTaskEntity> implements ITas
protected Context mContext; protected Context mContext;
protected boolean isHeighestTask = false; protected boolean isHeighestTask = false;
public Handler getOutHandler() {
return mOutHandler;
}
/** /**
* 任务是否完成 * 任务是否完成
* *
@ -163,6 +167,11 @@ public abstract class AbsTask<TASK_ENTITY extends AbsTaskEntity> implements ITas
return mTaskEntity; return mTaskEntity;
} }
/**
* 获取任务名也就是文件名
*/
public abstract String getTaskName();
public String getTargetName() { public String getTargetName() {
return mTargetName; return mTargetName;
} }

@ -163,6 +163,19 @@ public class TEManager {
} }
} }
/**
* 更新任务实体
*/
public void putTEntity(String key, AbsTaskEntity tEntity) {
final Lock lock = this.lock;
lock.lock();
try {
cache.put(convertKey(key), tEntity);
} finally {
lock.unlock();
}
}
/** /**
* 向管理器中增加任务实体 * 向管理器中增加任务实体
* *

@ -63,7 +63,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
* 如果执行队列任务未满则直接启动任务 * 如果执行队列任务未满则直接启动任务
* 如果执行队列已经满了则暂停执行队列队首任务并恢复指定任务 * 如果执行队列已经满了则暂停执行队列队首任务并恢复指定任务
* *
* @param task 需要恢复任务 * @param task 需要恢复任务
*/ */
@Override public void resumeTask(TASK task) { @Override public void resumeTask(TASK task) {
if (mExecutePool.size() >= getMaxTaskNum()) { if (mExecutePool.size() >= getMaxTaskNum()) {
@ -167,12 +167,12 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
} }
@Override public void stopTask(TASK task) { @Override public void stopTask(TASK task) {
if (!task.isRunning()) ALog.w(TAG, "停止任务失败,【任务已经停止】"); if (!task.isRunning()) ALog.w(TAG, "停止任务【" + task.getTaskName() + "】失败,原因:已停止");
if (mExecutePool.removeTask(task)) { if (mExecutePool.removeTask(task)) {
task.stop(); task.stop();
} else { } else {
task.stop(); task.stop();
ALog.w(TAG, "删除任务失败,【执行队列中没有该任务】"); ALog.w(TAG, "删除任务【" + task.getTaskName() + "】失败,原因:执行队列中没有该任务");
} }
} }
@ -180,27 +180,29 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
//TEManager.getInstance().removeTEntity(key); //TEManager.getInstance().removeTEntity(key);
TASK task = mExecutePool.getTask(key); TASK task = mExecutePool.getTask(key);
if (task != null) { if (task != null) {
ALog.d(TAG, "从执行池删除任务,删除" + (mExecutePool.removeTask(task) ? "成功" : "失败")); ALog.d(TAG,
"从执行池删除任务【" + task.getTaskName() + "】" + (mExecutePool.removeTask(task) ? "成功" : "失败"));
} }
task = mCachePool.getTask(key); task = mCachePool.getTask(key);
if (task != null) { if (task != null) {
ALog.d(TAG, "从缓存池删除任务,删除" + (mCachePool.removeTask(task) ? "成功" : "失败")); ALog.d(TAG,
"从缓存池删除任务【" + task.getTaskName() + "】" + (mCachePool.removeTask(task) ? "成功" : "失败"));
} }
} }
@Override public void reTryStart(TASK task) { @Override public void reTryStart(TASK task) {
if (task == null) { if (task == null) {
ALog.e(TAG, "重试失败,task 为null"); ALog.e(TAG, "任务重试失败,原因:task 为null");
return; return;
} }
if (!NetUtils.isConnected(AriaManager.APP)) { if (!NetUtils.isConnected(AriaManager.APP)) {
ALog.e(TAG, "重试失败,网络未连接"); ALog.e(TAG, "任务【" + task.getTaskName() + "】重试失败,原因:网络未连接");
return; return;
} }
if (!task.isRunning()) { if (!task.isRunning()) {
task.start(); task.start();
} else { } else {
ALog.e(TAG, "任务没有完全停止,重试下载失败"); ALog.e(TAG, "任务【" + task.getTaskName() + "】重试失败,原因:任务没有完全停止,");
} }
} }

@ -63,10 +63,15 @@ public class DownloadGroupTaskQueue
@Override public DownloadGroupTask createTask(String targetName, DownloadGroupTaskEntity entity) { @Override public DownloadGroupTask createTask(String targetName, DownloadGroupTaskEntity entity) {
DownloadGroupTask task = null; DownloadGroupTask task = null;
if (!TextUtils.isEmpty(targetName)) { if (!TextUtils.isEmpty(targetName)) {
task = (DownloadGroupTask) TaskFactory.getInstance() if (mCachePool.getTask(entity.getEntity().getKey()) == null
.createTask(targetName, entity, DownloadGroupSchedulers.getInstance()); && mExecutePool.getTask(entity.getEntity().getKey()) == null) {
entity.key = entity.getEntity().getGroupName(); task = (DownloadGroupTask) TaskFactory.getInstance()
mCachePool.putTask(task); .createTask(targetName, entity, DownloadGroupSchedulers.getInstance());
entity.key = entity.getEntity().getGroupName();
mCachePool.putTask(task);
} else {
ALog.w(TAG, "任务已存在");
}
} else { } else {
ALog.e(TAG, "target name 为 null!!"); ALog.e(TAG, "target name 为 null!!");
} }

@ -33,8 +33,7 @@ import java.util.Set;
* Created by lyy on 2016/8/17. * Created by lyy on 2016/8/17.
* 下载任务队列 * 下载任务队列
*/ */
public class DownloadTaskQueue public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DownloadTaskEntity> {
extends AbsTaskQueue<DownloadTask, DownloadTaskEntity> {
private static final String TAG = "DownloadTaskQueue"; private static final String TAG = "DownloadTaskQueue";
private static volatile DownloadTaskQueue INSTANCE = null; private static volatile DownloadTaskQueue INSTANCE = null;
@ -120,10 +119,15 @@ public class DownloadTaskQueue
@Override public DownloadTask createTask(String target, DownloadTaskEntity entity) { @Override public DownloadTask createTask(String target, DownloadTaskEntity entity) {
DownloadTask task = null; DownloadTask task = null;
if (!TextUtils.isEmpty(target)) { if (!TextUtils.isEmpty(target)) {
task = (DownloadTask) TaskFactory.getInstance() if (mCachePool.getTask(entity.getEntity().getKey()) == null
.createTask(target, entity, DownloadSchedulers.getInstance()); && mExecutePool.getTask(entity.getEntity().getKey()) == null) {
entity.key = entity.getEntity().getDownloadPath(); task = (DownloadTask) TaskFactory.getInstance()
mCachePool.putTask(task); .createTask(target, entity, DownloadSchedulers.getInstance());
entity.key = entity.getEntity().getDownloadPath();
mCachePool.putTask(task);
} else {
ALog.w(TAG, "任务已存在");
}
} else { } else {
ALog.e(TAG, "target name 为 null!!"); ALog.e(TAG, "target name 为 null!!");
} }

@ -1,120 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.queue;
import android.os.Handler;
import android.os.Message;
import android.util.SparseArray;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity;
/**
* Created by Aria.Lao on 2017/8/3.
* 队列控制器用于处理各种命令
*/
public class QueueControl implements Handler.Callback {
/**
* 获取任务命令
*/
public static final int CMD_GET_TASK = 0xa1;
/**
* 创建任务命令
*/
public static final int CMD_CREATE_TASK = 0xa2;
/**
* 启动任务命令
*/
public static final int CMD_START_TASK = 0xa3;
/**
* 停止任务命令
*/
public static final int CMD_STOP_TASK = 0xa4;
/**
* 删除任务命令
*/
public static final int CMD_CANCEL_TASK = 0xa5;
/**
* 停止所有任务命令
*/
public static final int CMD_STOP_ALL_TASK = 0xa6;
/**
* 删除所有任务命令
*/
public static final int CMD_CANCEL_ALL_TASK = 0xa7;
/**
* 队列类型为单文件下载队列
*/
public static final int TYPE_SIMPLE_DOWNLOAD_QUEUE = 0xc1;
/**
* 队列类型为任务组下载队列
*/
public static final int TYPE_SIMPLE_DOWNLOAD_GROUP_QUEUE = 0xc2;
/**
* 队列类型为单文件上传队列
*/
public static final int TYPE_SIMPLE_UPLOAD_QUEUE = 0xc3;
private Handler outHandler;
private AbsTaskQueue queue;
public QueueControl(Handler.Callback callback, int type) {
outHandler = new Handler(callback);
switch (type) {
case TYPE_SIMPLE_DOWNLOAD_QUEUE:
queue = DownloadTaskQueue.getInstance();
break;
case TYPE_SIMPLE_DOWNLOAD_GROUP_QUEUE:
queue = DownloadGroupTaskQueue.getInstance();
break;
case TYPE_SIMPLE_UPLOAD_QUEUE:
queue = UploadTaskQueue.getInstance();
break;
}
}
@Override public boolean handleMessage(Message msg) {
switch (msg.what) {
case CMD_GET_TASK:
outHandler.obtainMessage(CMD_GET_TASK, queue.getTask(((AbsEntity) msg.obj).getKey()))
.sendToTarget();
break;
case CMD_CREATE_TASK:
SparseArray params = (SparseArray) msg.obj;
outHandler.obtainMessage(CMD_CREATE_TASK,
queue.createTask(String.valueOf(params.get(1)), (AbsTaskEntity) params.get(2)))
.sendToTarget();
break;
case CMD_START_TASK:
queue.startTask((AbsTask) msg.obj);
break;
case CMD_STOP_TASK:
queue.stopTask((AbsTask) msg.obj);
break;
case CMD_CANCEL_TASK:
queue.cancelTask((AbsTask) msg.obj);
break;
case CMD_STOP_ALL_TASK:
queue.stopAllTask();
break;
case CMD_CANCEL_ALL_TASK:
queue.removeAllTask();
break;
}
return true;
}
}

@ -65,10 +65,15 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity>
@Override public UploadTask createTask(String targetName, UploadTaskEntity entity) { @Override public UploadTask createTask(String targetName, UploadTaskEntity entity) {
UploadTask task = null; UploadTask task = null;
if (!TextUtils.isEmpty(targetName)) { if (!TextUtils.isEmpty(targetName)) {
task = (UploadTask) TaskFactory.getInstance() if (mCachePool.getTask(entity.getEntity().getKey()) == null
.createTask(targetName, entity, UploadSchedulers.getInstance()); && mExecutePool.getTask(entity.getEntity().getKey()) == null) {
entity.key = entity.getEntity().getFilePath(); task = (UploadTask) TaskFactory.getInstance()
mCachePool.putTask(task); .createTask(targetName, entity, UploadSchedulers.getInstance());
entity.key = entity.getEntity().getFilePath();
mCachePool.putTask(task);
} else {
ALog.w(TAG, "任务已存在");
}
} else { } else {
ALog.e(TAG, "target name 为 null是!!"); ALog.e(TAG, "target name 为 null是!!");
} }

@ -54,8 +54,8 @@ public class BaseCachePool<TASK extends AbsTask> implements IPool<TASK> {
/** /**
* 清除所有缓存的任务 * 清除所有缓存的任务
*/ */
public void clear(){ public void clear() {
for (String key : mCacheMap.keySet()){ for (String key : mCacheMap.keySet()) {
TASK task = mCacheMap.get(key); TASK task = mCacheMap.get(key);
mCacheQueue.remove(task); mCacheQueue.remove(task);
mCacheMap.remove(key); mCacheMap.remove(key);
@ -85,16 +85,16 @@ public class BaseCachePool<TASK extends AbsTask> implements IPool<TASK> {
@Override public boolean putTask(TASK task) { @Override public boolean putTask(TASK task) {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
if (task == null) { if (task == null) {
ALog.e(TAG, "下载任务不能为空!!"); ALog.e(TAG, "任务不能为空!!");
return false; return false;
} }
String url = task.getKey(); String url = task.getKey();
if (mCacheQueue.contains(task)) { if (mCacheQueue.contains(task)) {
ALog.w(TAG, "队列中已经包含了该任务,任务下载链接【" + url + "】"); ALog.w(TAG, "任务【" + task.getTaskName() + "】进入缓存队列失败,原因:已经在缓存队列中");
return false; return false;
} else { } else {
boolean s = mCacheQueue.offer(task); boolean s = mCacheQueue.offer(task);
ALog.d(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】")); ALog.d(TAG, "任务【" + task.getTaskName() + "】进入缓存队列" + (s ? "成功" : "失败"));
if (s) { if (s) {
mCacheMap.put(CommonUtil.keyToHashKey(url), task); mCacheMap.put(CommonUtil.keyToHashKey(url), task);
} }
@ -120,14 +120,13 @@ public class BaseCachePool<TASK extends AbsTask> implements IPool<TASK> {
return null; return null;
} }
@Override public TASK getTask(String downloadUrl) { @Override public TASK getTask(String key) {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
if (TextUtils.isEmpty(downloadUrl)) { if (TextUtils.isEmpty(key)) {
ALog.e(TAG, "请传入有效的下载链接"); ALog.e(TAG, "key 为null");
return null; return null;
} }
String key = CommonUtil.keyToHashKey(downloadUrl); return mCacheMap.get(CommonUtil.keyToHashKey(key));
return mCacheMap.get(key);
} }
} }
@ -144,15 +143,15 @@ public class BaseCachePool<TASK extends AbsTask> implements IPool<TASK> {
} }
} }
@Override public boolean removeTask(String downloadUrl) { @Override public boolean removeTask(String key) {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
if (TextUtils.isEmpty(downloadUrl)) { if (TextUtils.isEmpty(key)) {
ALog.e(TAG, "请传入有效的下载链接"); ALog.e(TAG, "请传入有效的下载链接");
return false; return false;
} }
String key = CommonUtil.keyToHashKey(downloadUrl); String temp = CommonUtil.keyToHashKey(key);
TASK task = mCacheMap.get(key); TASK task = mCacheMap.get(temp);
mCacheMap.remove(key); mCacheMap.remove(temp);
return mCacheQueue.remove(task); return mCacheQueue.remove(task);
} }
} }

@ -65,9 +65,8 @@ public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
ALog.e(TAG, "任务不能为空!!"); ALog.e(TAG, "任务不能为空!!");
return false; return false;
} }
String url = task.getKey();
if (mExecuteQueue.contains(task)) { if (mExecuteQueue.contains(task)) {
ALog.e(TAG, "队列中已经包含了该任务,任务key【" + url + "】"); ALog.e(TAG, "任务【" + task.getTaskName() + "】进入执行队列失败,原因:已经在执行队列中");
return false; return false;
} else { } else {
if (mExecuteQueue.size() >= mSize) { if (mExecuteQueue.size() >= mSize) {
@ -112,7 +111,7 @@ public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
String url = newTask.getKey(); String url = newTask.getKey();
boolean s = mExecuteQueue.offer(newTask); boolean s = mExecuteQueue.offer(newTask);
ALog.d(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】")); ALog.d(TAG, "任务【" + newTask.getTaskName() + "】进入执行队列" + (s ? "成功" : "失败"));
if (s) { if (s) {
mExecuteMap.put(CommonUtil.keyToHashKey(url), newTask); mExecuteMap.put(CommonUtil.keyToHashKey(url), newTask);
} }
@ -128,7 +127,7 @@ public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
try { try {
TASK oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS); TASK oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
if (oldTask == null) { if (oldTask == null) {
ALog.w(TAG, "移除任务失败"); ALog.w(TAG, "移除任务失败,原因:任务为null");
return false; return false;
} }
oldTask.stop(); oldTask.stop();
@ -162,7 +161,7 @@ public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
@Override public TASK getTask(String key) { @Override public TASK getTask(String key) {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
if (TextUtils.isEmpty(key)) { if (TextUtils.isEmpty(key)) {
ALog.e(TAG, "请传入有效的任务key"); ALog.e(TAG, "key 为null");
return null; return null;
} }
return mExecuteMap.get(CommonUtil.keyToHashKey(key)); return mExecuteMap.get(CommonUtil.keyToHashKey(key));
@ -183,7 +182,7 @@ public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
@Override public boolean removeTask(String key) { @Override public boolean removeTask(String key) {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
if (TextUtils.isEmpty(key)) { if (TextUtils.isEmpty(key)) {
ALog.e(TAG, "请传入有效的任务key"); ALog.e(TAG, "key 为null");
return false; return false;
} }
String convertKey = CommonUtil.keyToHashKey(key); String convertKey = CommonUtil.keyToHashKey(key);

@ -39,10 +39,9 @@ class DownloadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> {
ALog.e(TAG, "任务不能为空!!"); ALog.e(TAG, "任务不能为空!!");
return false; return false;
} }
String url = task.getKey();
if (mExecuteQueue.contains(task)) { if (mExecuteQueue.contains(task)) {
if (!task.isRunning()) return true; if (!task.isRunning()) return true;
ALog.e(TAG, "队列中已经包含了该任务,任务key【" + url + "】"); ALog.e(TAG, "任务【" + task.getTaskName() + "】进入执行队列失败,错误原因:已经在执行队列中");
return false; return false;
} else { } else {
if (mExecuteQueue.size() >= mSize) { if (mExecuteQueue.size() >= mSize) {
@ -65,7 +64,7 @@ class DownloadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> {
try { try {
TASK oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS); TASK oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
if (oldTask == null) { if (oldTask == null) {
ALog.e(TAG, "移除任务失败"); ALog.w(TAG, "移除任务失败,错误原因:任务为null");
return false; return false;
} }
if (oldTask.isHighestPriorityTask()) { if (oldTask.isHighestPriorityTask()) {

@ -21,7 +21,12 @@ import com.arialyy.aria.core.inf.ITask;
/** /**
* Created by Aria.Lao on 2017/6/7. * Created by Aria.Lao on 2017/6/7.
*/ */
public class AbsSchedulerListener<TASK extends ITask, SUB_ENTITY extends AbsNormalEntity> implements ISchedulerListener<TASK> { public class AbsSchedulerListener<TASK extends ITask, SUB_ENTITY extends AbsNormalEntity>
implements ISchedulerListener<TASK> {
@Override public void onWait(TASK task) {
}
@Override public void onPre(TASK task) { @Override public void onPre(TASK task) {

@ -175,6 +175,8 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
} }
if (what == CANCEL || what == COMPLETE) { if (what == CANCEL || what == COMPLETE) {
TEManager.getInstance().removeTEntity(task.getKey()); TEManager.getInstance().removeTEntity(task.getKey());
} else {
TEManager.getInstance().putTEntity(task.getKey(), task.getTaskEntity());
} }
callback(what, task); callback(what, task);
} }
@ -201,6 +203,9 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
return; return;
} }
switch (state) { switch (state) {
case WAIT:
listener.onWait(task);
break;
case PRE: case PRE:
listener.onPre(task); listener.onPre(task);
break; break;

@ -21,6 +21,12 @@ import com.arialyy.aria.core.inf.ITask;
* Target处理任务监听 * Target处理任务监听
*/ */
public interface ISchedulerListener<TASK extends ITask> { public interface ISchedulerListener<TASK extends ITask> {
/**
* 队列已经满了继续创建任务将会回调该方法
*/
void onWait(TASK task);
/** /**
* 预处理有时有些地址链接比较慢这时可以先在这个地方出来一些界面上的UI如按钮的状态 * 预处理有时有些地址链接比较慢这时可以先在这个地方出来一些界面上的UI如按钮的状态
* 在这个回调中任务是获取不到文件大小下载速度等参数 * 在这个回调中任务是获取不到文件大小下载速度等参数
@ -66,8 +72,4 @@ public interface ISchedulerListener<TASK extends ITask> {
* 任务执行中 * 任务执行中
*/ */
void onTaskRunning(TASK task); void onTaskRunning(TASK task);
} }

@ -70,6 +70,10 @@ public interface ISchedulers<Task extends AbsTask> extends Handler.Callback {
* 恢复任务 * 恢复任务
*/ */
int RESUME = 8; int RESUME = 8;
/**
* 等待
*/
int WAIT = 10;
/** /**
* 任务组子任务预处理 * 任务组子任务预处理

@ -17,6 +17,8 @@ package com.arialyy.aria.core.upload;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.AbsUploadTarget; import com.arialyy.aria.core.inf.AbsUploadTarget;
import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.manager.TEManager;
@ -97,4 +99,14 @@ public class FtpUploadTarget
mTaskEntity.urlEntity.account = account; mTaskEntity.urlEntity.account = account;
return this; return this;
} }
/**
* 添加任务
*/
public void add() {
AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CREATE,
checkTaskType()))
.exe();
}
} }

@ -23,6 +23,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.util.LruCache; import android.support.v4.util.LruCache;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
@ -31,9 +32,11 @@ import java.lang.reflect.Field;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* Created by lyy on 2015/11/2. * Created by lyy on 2015/11/2.
@ -50,7 +53,8 @@ final class SqlHelper extends SQLiteOpenHelper {
private static final int DEL_DATA = 6; private static final int DEL_DATA = 6;
private static volatile SqlHelper INSTANCE = null; private static volatile SqlHelper INSTANCE = null;
private static LruCache<Integer, DbEntity> mDataCache = new LruCache<>(1024); private static LruCache<String, DbEntity> mDataCache = new LruCache<>(1024);
//private static Map<String, DbEntity> mDataCache = new ConcurrentHashMap<>();
static SqlHelper init(Context context) { static SqlHelper init(Context context) {
if (INSTANCE == null) { if (INSTANCE == null) {
@ -330,7 +334,7 @@ final class SqlHelper extends SQLiteOpenHelper {
db = checkDb(db); db = checkDb(db);
Class<?> clazz = dbEntity.getClass(); Class<?> clazz = dbEntity.getClass();
List<Field> fields = CommonUtil.getAllFields(clazz); List<Field> fields = CommonUtil.getAllFields(clazz);
DbEntity cacheEntity = mDataCache.get(dbEntity.hashCode()); DbEntity cacheEntity = mDataCache.get(getCacheKey(dbEntity));
if (fields != null && fields.size() > 0) { if (fields != null && fields.size() > 0) {
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
StringBuilder prams = new StringBuilder(); StringBuilder prams = new StringBuilder();
@ -342,7 +346,15 @@ final class SqlHelper extends SQLiteOpenHelper {
continue; continue;
} }
try { try {
if (cacheEntity != null && field.get(dbEntity) == field.get(cacheEntity)) { if (cacheEntity != null
&& field.get(dbEntity) == field.get(cacheEntity)
&& !field.getName().equals("state")) { //在LruCache中 state字段总是不能重新赋值...
//if (dbEntity instanceof DownloadEntity && field.getName().equals("state")) {
// Log.i(TAG, "cacheState => "
// + ((DownloadEntity) cacheEntity).getState()
// + ", newState => "
// + ((DownloadEntity) dbEntity).getState());
//}
continue; continue;
} }
@ -383,9 +395,14 @@ final class SqlHelper extends SQLiteOpenHelper {
db.execSQL(sql.toString()); db.execSQL(sql.toString());
} }
} }
mDataCache.put(getCacheKey(dbEntity), dbEntity);
close(db); close(db);
} }
private static String getCacheKey(DbEntity dbEntity) {
return dbEntity.getClass().getName() + "_" + dbEntity.rowID;
}
/** /**
* 插入数据 * 插入数据
*/ */
@ -673,7 +690,7 @@ final class SqlHelper extends SQLiteOpenHelper {
} }
} }
entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid")); entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid"));
mDataCache.put(entity.hashCode(), entity); mDataCache.put(getCacheKey(entity), entity);
entitys.add(entity); entitys.add(entity);
} }
closeCursor(cursor); closeCursor(cursor);

@ -35,71 +35,79 @@ import java.lang.annotation.Target;
* 则表示所有下载任务中只有下载地址为"http://www.baidu.com"的任务才能回调该注解的方法 * 则表示所有下载任务中只有下载地址为"http://www.baidu.com"的任务才能回调该注解的方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Download { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Download {
/**
* {@code @Download.onPre}注解下载队列已经满了继续创建新任务将会回调该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onWait{
String[] value() default { AriaConstance.NO_URL };
}
/** /**
* 如果你在方法中添加{@code @Download.onPre}注解在预处理完成时Aria会调用该方法 * {@code @Download.onPre}注解在预处理完成时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onPre { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onPre {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Download.onTaskPre}注解在任务预处理完成时Aria会调用该方法 * {@code @Download.onTaskPre}注解在任务预处理完成时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskPre { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskPre {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Download.onTaskResume}注解在任务恢复下载时Aria会调用该方法 * {@code @Download.onTaskResume}注解在任务恢复下载时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskResume { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskResume {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Download.onTaskStart}注解在任务开始下载时Aria会调用该方法 * {@code @Download.onTaskStart}注解在任务开始下载时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStart { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStart {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Download.onTaskStop}注解在任务停止时Aria会调用该方法 * {@code @Download.onTaskStop}注解在任务停止时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStop { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStop {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Download.onTaskCancel}l注解在任务取消时Aria会调用该方法 * {@code @Download.onTaskCancel}l注解在任务取消时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskCancel { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskCancel {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Download.onTaskFail)注解在任务预失败时Aria会调用该方法 * {@code @Download.onTaskFail)注解在任务预失败时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskFail { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskFail {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Download.onTaskComplete}注解在任务完成时Aria会调用该方法 * {@code @Download.onTaskComplete}注解在任务完成时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskComplete { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskComplete {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Download.onTaskRunning}注解在任务正在下载Aria会调用该方法 * {@code @Download.onTaskRunning}注解在任务正在下载Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskRunning { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskRunning {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Download.onNoSupportBreakPoint}注解如果该任务不支持断点Aria会调用该方法 * {@code @Download.onNoSupportBreakPoint}注解如果该任务不支持断点Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD)
@interface onNoSupportBreakPoint { @interface onNoSupportBreakPoint {

@ -44,64 +44,72 @@ import java.lang.annotation.Target;
* </pre> * </pre>
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface DownloadGroup { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface DownloadGroup {
/**
* {@code @Download.onPre}注解队列已经满了继续创建新任务将会回调该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onWait {
String[] value() default { AriaConstance.NO_URL };
}
/** /**
* 如果你在方法中添加{@code @DownloadGroup.onPre}注解在预处理完成时Aria会调用该方法 * {@code @DownloadGroup.onPre}注解在预处理完成时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onPre { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onPre {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @DownloadGroup.onTaskPre}注解在任务预处理完成时Aria会调用该方法 * {@code @DownloadGroup.onTaskPre}注解在任务预处理完成时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskPre { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskPre {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @DownloadGroup.onTaskResume}注解在任务恢复下载时Aria会调用该方法 * {@code @DownloadGroup.onTaskResume}注解在任务恢复下载时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskResume { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskResume {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @DownloadGroup.onTaskStart}注解在任务开始下载时Aria会调用该方法 * {@code @DownloadGroup.onTaskStart}注解在任务开始下载时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStart { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStart {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @DownloadGroup.onTaskStop}注解在任务停止时Aria会调用该方法 * {@code @DownloadGroup.onTaskStop}注解在任务停止时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStop { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStop {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @DownloadGroup.onTaskCancel}l注解在任务取消时Aria会调用该方法 * {@code @DownloadGroup.onTaskCancel}l注解在任务取消时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskCancel { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskCancel {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @DownloadGroup.onTaskFail)注解在任务预失败时Aria会调用该方法 * {@code @DownloadGroup.onTaskFail)注解在任务预失败时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskFail { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskFail {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @DownloadGroup.onTaskComplete}注解在任务完成时Aria会调用该方法 * {@code @DownloadGroup.onTaskComplete}注解在任务完成时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskComplete { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskComplete {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @DownloadGroup.onTaskRunning}注解在任务正在下载Aria会调用该方法 * {@code @DownloadGroup.onTaskRunning}注解在任务正在下载Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskRunning { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskRunning {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };

@ -37,63 +37,70 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Upload { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Upload {
/** /**
* 如果你在方法中添加{@code @Upload.onPre}注解在预处理完成时Aria会调用该方法 * {@code @Download.onPre}注解队列已经满了继续创建新任务将会回调该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onWait {
String[] value() default { AriaConstance.NO_URL };
}
/**
* {@code @Upload.onPre}注解在预处理完成时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onPre { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onPre {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Upload.onTaskResume}注解在任务恢复下载时Aria会调用该方法 * {@code @Upload.onTaskResume}注解在任务恢复下载时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskResume { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskResume {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Upload.onTaskStart}注解在任务开始下载时Aria会调用该方法 * {@code @Upload.onTaskStart}注解在任务开始下载时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStart { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStart {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Upload.onTaskStop}注解在任务停止时Aria会调用该方法 * {@code @Upload.onTaskStop}注解在任务停止时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStop { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStop {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Upload.onTaskCancel}l注解在任务取消时Aria会调用该方法 * {@code @Upload.onTaskCancel}l注解在任务取消时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskCancel { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskCancel {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Upload.onTaskFail)注解在任务预失败时Aria会调用该方法 * {@code @Upload.onTaskFail)注解在任务预失败时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskFail { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskFail {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Upload.onTaskComplete}注解在任务完成时Aria会调用该方法 * {@code @Upload.onTaskComplete}注解在任务完成时Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskComplete { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskComplete {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Upload.onTaskRunning}注解在任务正在下载Aria会调用该方法 * {@code @Upload.onTaskRunning}注解在任务正在下载Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskRunning { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskRunning {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** /**
* 如果你在方法中添加{@code @Upload.onNoSupportBreakPoint}注解如果该任务不支持断点Aria会调用该方法 * {@code @Upload.onNoSupportBreakPoint}注解如果该任务不支持断点Aria会调用该方法
*/ */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onNoSupportBreakPoint { @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onNoSupportBreakPoint {
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };

@ -44,6 +44,7 @@ import javax.lang.model.element.TypeElement;
@Override public Set<String> getSupportedAnnotationTypes() { @Override public Set<String> getSupportedAnnotationTypes() {
Set<String> annotataions = new LinkedHashSet<>(); Set<String> annotataions = new LinkedHashSet<>();
//单任务下载的注解 //单任务下载的注解
annotataions.add(Download.onWait.class.getCanonicalName());
annotataions.add(Download.onPre.class.getCanonicalName()); annotataions.add(Download.onPre.class.getCanonicalName());
annotataions.add(Download.onNoSupportBreakPoint.class.getCanonicalName()); annotataions.add(Download.onNoSupportBreakPoint.class.getCanonicalName());
annotataions.add(Download.onTaskCancel.class.getCanonicalName()); annotataions.add(Download.onTaskCancel.class.getCanonicalName());
@ -55,6 +56,7 @@ import javax.lang.model.element.TypeElement;
annotataions.add(Download.onTaskStart.class.getCanonicalName()); annotataions.add(Download.onTaskStart.class.getCanonicalName());
annotataions.add(Download.onTaskStop.class.getCanonicalName()); annotataions.add(Download.onTaskStop.class.getCanonicalName());
//下载任务组的注解 //下载任务组的注解
annotataions.add(DownloadGroup.onWait.class.getCanonicalName());
annotataions.add(DownloadGroup.onPre.class.getCanonicalName()); annotataions.add(DownloadGroup.onPre.class.getCanonicalName());
annotataions.add(DownloadGroup.onTaskCancel.class.getCanonicalName()); annotataions.add(DownloadGroup.onTaskCancel.class.getCanonicalName());
annotataions.add(DownloadGroup.onTaskComplete.class.getCanonicalName()); annotataions.add(DownloadGroup.onTaskComplete.class.getCanonicalName());
@ -73,6 +75,7 @@ import javax.lang.model.element.TypeElement;
annotataions.add(DownloadGroup.onSubTaskStart.class.getCanonicalName()); annotataions.add(DownloadGroup.onSubTaskStart.class.getCanonicalName());
annotataions.add(DownloadGroup.onSubTaskStop.class.getCanonicalName()); annotataions.add(DownloadGroup.onSubTaskStop.class.getCanonicalName());
//上传任务的注解 //上传任务的注解
annotataions.add(Upload.onWait.class.getCanonicalName());
annotataions.add(Upload.onPre.class.getCanonicalName()); annotataions.add(Upload.onPre.class.getCanonicalName());
annotataions.add(Upload.onNoSupportBreakPoint.class.getCanonicalName()); annotataions.add(Upload.onNoSupportBreakPoint.class.getCanonicalName());
annotataions.add(Upload.onTaskCancel.class.getCanonicalName()); annotataions.add(Upload.onTaskCancel.class.getCanonicalName());

@ -44,6 +44,7 @@ class ElementHandler {
* PackageElement 一般代表Package * PackageElement 一般代表Package
*/ */
void handleDownload(RoundEnvironment roundEnv) { void handleDownload(RoundEnvironment roundEnv) {
mPbUtil.saveMethod(TaskEnum.DOWNLOAD, roundEnv, Download.onWait.class, ProxyConstance.WAIT);
mPbUtil.saveMethod(TaskEnum.DOWNLOAD, roundEnv, Download.onNoSupportBreakPoint.class, mPbUtil.saveMethod(TaskEnum.DOWNLOAD, roundEnv, Download.onNoSupportBreakPoint.class,
ProxyConstance.TASK_NO_SUPPORT_BREAKPOINT); ProxyConstance.TASK_NO_SUPPORT_BREAKPOINT);
mPbUtil.saveMethod(TaskEnum.DOWNLOAD, roundEnv, Download.onPre.class, ProxyConstance.PRE); mPbUtil.saveMethod(TaskEnum.DOWNLOAD, roundEnv, Download.onPre.class, ProxyConstance.PRE);
@ -69,6 +70,8 @@ class ElementHandler {
* 处理搜索到的下载任务组注解 * 处理搜索到的下载任务组注解
*/ */
void handleDownloadGroup(RoundEnvironment roundEnv) { void handleDownloadGroup(RoundEnvironment roundEnv) {
mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP, roundEnv, DownloadGroup.onWait.class,
ProxyConstance.WAIT);
mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP, roundEnv, DownloadGroup.onPre.class, mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP, roundEnv, DownloadGroup.onPre.class,
ProxyConstance.PRE); ProxyConstance.PRE);
mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP, roundEnv, DownloadGroup.onTaskCancel.class, mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP, roundEnv, DownloadGroup.onTaskCancel.class,
@ -113,6 +116,7 @@ class ElementHandler {
* 处理搜索到的上传注解F * 处理搜索到的上传注解F
*/ */
void handleUpload(RoundEnvironment roundEnv) { void handleUpload(RoundEnvironment roundEnv) {
mPbUtil.saveMethod(TaskEnum.UPLOAD, roundEnv, Upload.onWait.class, ProxyConstance.WAIT);
mPbUtil.saveMethod(TaskEnum.UPLOAD, roundEnv, Upload.onNoSupportBreakPoint.class, mPbUtil.saveMethod(TaskEnum.UPLOAD, roundEnv, Upload.onNoSupportBreakPoint.class,
ProxyConstance.TASK_NO_SUPPORT_BREAKPOINT); ProxyConstance.TASK_NO_SUPPORT_BREAKPOINT);
mPbUtil.saveMethod(TaskEnum.UPLOAD, roundEnv, Upload.onPre.class, ProxyConstance.PRE); mPbUtil.saveMethod(TaskEnum.UPLOAD, roundEnv, Upload.onPre.class, ProxyConstance.PRE);

@ -50,6 +50,7 @@ interface ProxyConstance {
String COUNT_METHOD_DOWNLOAD_GROUP_SUB = "getDownloadGroupSubCounter"; String COUNT_METHOD_DOWNLOAD_GROUP_SUB = "getDownloadGroupSubCounter";
String COUNT_METHOD_UPLOAD = "getUploadCounter"; String COUNT_METHOD_UPLOAD = "getUploadCounter";
int WAIT = 0X10;
int PRE = 0X11; int PRE = 0X11;
int TASK_PRE = 0X12; int TASK_PRE = 0X12;
int TASK_RESUME = 0X13; int TASK_RESUME = 0X13;

@ -1,4 +1,7 @@
## 开发日志 ## 开发日志
+ v_3.3.12
- 添加`@Download.onWait、@Upload.onWait、@DownloadGroup.onWait`三个新注解,队列已经满了,继续创建新任务,任务处于等待中,将会执行被这三个注解标志的方法
- app被kill,但是还存在等待中的任务A;第二次重新启动,先创建一个新的任务B,Aria会自动把B放进等待队列中,这时再次创建任务A,会导致重复下载,进度错乱的问题;本版本已修复这个问题
+ v_3.3.11 + v_3.3.11
- 添加进度更新间隔api,在`aria_config.xml`配置`<updateInterval value="1000"/>`或在代码中调用 - 添加进度更新间隔api,在`aria_config.xml`配置`<updateInterval value="1000"/>`或在代码中调用
`AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)`便可以改变进度刷新间隔 `AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)`便可以改变进度刷新间隔

@ -96,7 +96,7 @@ protected void onCreate(Bundle savedInstanceState) {
### [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki) ### [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki)
### 升级日志 ### 版本日志
+ v_3.3.11 + v_3.3.11
- 添加进度更新间隔api,在`aria_config.xml`配置`<updateInterval value="1000"/>`或在代码中调用 - 添加进度更新间隔api,在`aria_config.xml`配置`<updateInterval value="1000"/>`或在代码中调用
`AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)`便可以改变进度刷新间隔 `AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)`便可以改变进度刷新间隔

@ -122,6 +122,10 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
return true; return true;
} }
@Download.onWait void onWait(DownloadTask task){
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
}
@Download.onPre protected void onPre(DownloadTask task) { @Download.onPre protected void onPre(DownloadTask task) {
setBtState(false); setBtState(false);
} }
@ -230,7 +234,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//.setRequestMode(RequestEnum.POST) //.setRequestMode(RequestEnum.POST)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk") .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk")
.resetState() .resetState()
.start(); //.start();
.add();
} }
@Override protected void onDestroy() { @Override protected void onDestroy() {

@ -17,16 +17,13 @@ package com.arialyy.simple.download.group;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.support.design.widget.FloatingActionButton;
import android.view.View; import android.view.View;
import butterknife.Bind; import butterknife.Bind;
import com.arialyy.annotations.DownloadGroup; import com.arialyy.annotations.DownloadGroup;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadGroupTask; import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T; import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R; import com.arialyy.simple.R;
@ -66,8 +63,6 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
showPopupWindow(position); showPopupWindow(position);
} }
}); });
} }
private void showPopupWindow(int position) { private void showPopupWindow(int position) {
@ -111,6 +106,10 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
} }
} }
@DownloadGroup.onWait void taskWait(DownloadGroupTask task) {
L.d(TAG, task.getTaskName() + "wait");
}
@DownloadGroup.onPre() protected void onPre(DownloadGroupTask task) { @DownloadGroup.onPre() protected void onPre(DownloadGroupTask task) {
L.d(TAG, "group pre"); L.d(TAG, "group pre");
} }
@ -162,5 +161,4 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
T.showShort(this, "任务组下载完成"); T.showShort(this, "任务组下载完成");
L.d(TAG, "任务组下载完成"); L.d(TAG, "任务组下载完成");
} }
} }

@ -76,13 +76,16 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
@Download.onPre void onPre(DownloadTask task) { @Download.onPre void onPre(DownloadTask task) {
mAdapter.updateState(task.getEntity()); mAdapter.updateState(task.getEntity());
Log.d(TAG, task.getTaskName() + ", " + task.getState());
} }
@Download.onTaskStart void taskStart(DownloadTask task) { @Download.onTaskStart void taskStart(DownloadTask task) {
Log.d(TAG, task.getTaskName() + ", " + task.getState());
mAdapter.updateState(task.getEntity()); mAdapter.updateState(task.getEntity());
} }
@Download.onTaskResume void taskResume(DownloadTask task) { @Download.onTaskResume void taskResume(DownloadTask task) {
Log.d(TAG, task.getTaskName() + ", " + task.getState());
mAdapter.updateState(task.getEntity()); mAdapter.updateState(task.getEntity());
} }

@ -78,6 +78,10 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
} }
} }
@Download.onWait void taskWait(DownloadTask task){
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
}
@Download.onTaskStart void taskStart(DownloadTask task) { @Download.onTaskStart void taskStart(DownloadTask task) {
mAdapter.updateBtState(task.getKey(), false); mAdapter.updateBtState(task.getKey(), false);
} }

@ -34,7 +34,7 @@ import com.arialyy.simple.databinding.ActivityFtpUploadBinding;
* Ftp 文件上传demo * Ftp 文件上传demo
*/ */
public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> { public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
private final String FILE_PATH = "/mnt/sdcard/Download/me.jpg"; private final String FILE_PATH = "/mnt/sdcard/gg.zip";
private final String URL = "ftp://192.168.1.2:21/upload/测试"; private final String URL = "ftp://192.168.1.2:21/upload/测试";
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
@ -56,7 +56,7 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
Aria.upload(this).loadFtp(FILE_PATH).setUploadUrl(URL).login("lao", "123456").start(); Aria.upload(this).loadFtp(FILE_PATH).setUploadUrl(URL).login("lao", "123456").add();
break; break;
case R.id.stop: case R.id.stop:
Aria.upload(this).loadFtp(FILE_PATH).stop(); Aria.upload(this).loadFtp(FILE_PATH).stop();
@ -67,6 +67,10 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
} }
} }
@Upload.onWait void onWait(UploadTask task){
Log.d(TAG, task.getTaskName() + "_wait");
}
@Upload.onPre public void onPre(UploadTask task) { @Upload.onPre public void onPre(UploadTask task) {
getBinding().setFileSize(task.getConvertFileSize()); getBinding().setFileSize(task.getConvertFileSize());
} }

@ -17,6 +17,7 @@
package com.arialyy.simple.upload; package com.arialyy.simple.upload;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import butterknife.Bind; import butterknife.Bind;
import butterknife.OnClick; import butterknife.OnClick;
import com.arialyy.annotations.Upload; import com.arialyy.annotations.Upload;
@ -63,6 +64,7 @@ public class HttpUploadActivity extends BaseActivity<ActivityUploadBinding> {
Aria.upload(this).load(FILE_PATH).cancel(); Aria.upload(this).load(FILE_PATH).cancel();
} }
@Upload.onPre public void onPre(UploadTask task) { @Upload.onPre public void onPre(UploadTask task) {
} }

@ -74,6 +74,10 @@ public class UploadTask extends AbsNormalTask<UploadTaskEntity> {
mUtil.cancel(); mUtil.cancel();
} }
@Override public String getTaskName() {
return mTaskEntity.getEntity().getFileName();
}
public static class Builder { public static class Builder {
private Handler mOutHandler; private Handler mOutHandler;
private UploadTaskEntity mTaskEntity; private UploadTaskEntity mTaskEntity;

Loading…
Cancel
Save