From 1f3bd90b3b36bb6a8f92389cc5bb76fb34290f40 Mon Sep 17 00:00:00 2001 From: e <511455842@qq.com> Date: Wed, 31 Jan 2018 19:52:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0onWait=E6=B3=A8=E8=A7=A3?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E4=BB=BB=E5=8A=A1=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/command/normal/AbsNormalCmd.java | 10 ++ .../aria/core/command/normal/AddCmd.java | 3 +- .../aria/core/command/normal/StartCmd.java | 5 + .../aria/core/download/BaseDListener.java | 1 + .../aria/core/download/DownloadGroupTask.java | 6 + .../aria/core/download/DownloadTask.java | 4 + .../com/arialyy/aria/core/inf/AbsTask.java | 9 ++ .../arialyy/aria/core/manager/TEManager.java | 13 ++ .../arialyy/aria/core/queue/AbsTaskQueue.java | 18 +-- .../core/queue/DownloadGroupTaskQueue.java | 13 +- .../aria/core/queue/DownloadTaskQueue.java | 16 ++- .../arialyy/aria/core/queue/QueueControl.java | 120 ------------------ .../aria/core/queue/UploadTaskQueue.java | 13 +- .../aria/core/queue/pool/BaseCachePool.java | 29 ++--- .../aria/core/queue/pool/BaseExecutePool.java | 11 +- .../core/queue/pool/DownloadExecutePool.java | 5 +- .../core/scheduler/AbsSchedulerListener.java | 7 +- .../aria/core/scheduler/AbsSchedulers.java | 5 + .../core/scheduler/ISchedulerListener.java | 10 +- .../aria/core/scheduler/ISchedulers.java | 4 + .../aria/core/upload/FtpUploadTarget.java | 12 ++ .../java/com/arialyy/aria/orm/SqlHelper.java | 25 +++- .../com/arialyy/annotations/Download.java | 28 ++-- .../arialyy/annotations/DownloadGroup.java | 26 ++-- .../java/com/arialyy/annotations/Upload.java | 25 ++-- .../com/arialyy/compiler/AriaProcessor.java | 3 + .../com/arialyy/compiler/ElementHandler.java | 4 + .../com/arialyy/compiler/ProxyConstance.java | 1 + DEV_LOG.md | 3 + README.md | 2 +- .../simple/download/SingleTaskActivity.java | 7 +- .../download/group/DownloadGroupActivity.java | 10 +- .../multi_download/MultiDownloadActivity.java | 3 + .../multi_download/MultiTaskActivity.java | 4 + .../simple/upload/FtpUploadActivity.java | 8 +- .../simple/upload/HttpUploadActivity.java | 2 + .../arialyy/aria/core/upload/UploadTask.java | 4 + 37 files changed, 255 insertions(+), 214 deletions(-) delete mode 100644 Aria/src/main/java/com/arialyy/aria/core/queue/QueueControl.java diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java index cfe019dd..c4964772 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.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.DownloadTaskQueue; 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.util.ALog; import com.arialyy.aria.util.CommonUtil; @@ -79,6 +80,15 @@ public abstract class AbsNormalCmd extends AbsCmd { isDownloadCmd = taskType < ICmd.TASK_TYPE_UPLOAD; } + /** + * 发送等待状态 + */ + void sendWaitState() { + if (tempTask != null) { + tempTask.getOutHandler().obtainMessage(ISchedulers.WAIT, tempTask).sendToTarget(); + } + } + /** * 删除所有任务 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java index 9c9c851e..554e9c74 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java @@ -17,8 +17,8 @@ package com.arialyy.aria.core.command.normal; 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.IEntity; import com.arialyy.aria.util.ALog; /** @@ -37,6 +37,7 @@ class AddCmd extends AbsNormalCmd { if (task == null) { mTaskEntity.getEntity().setState(IEntity.STATE_WAIT); createTask(); + sendWaitState(); } else { ALog.w(TAG, "添加命令执行失败,【该任务已经存在】"); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java index 1a7b3c18..82120c32 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java @@ -79,6 +79,8 @@ class StartCmd extends AbsNormalCmd { || task.getState() == IEntity.STATE_COMPLETE) { //startTask(); resumeTask(); + } else { + sendWaitState(); } } } else { @@ -141,6 +143,8 @@ class StartCmd extends AbsNormalCmd { private void handleTask(List waitList) { for (AbsTaskEntity te : waitList) { if (te.getEntity() == null) continue; + AbsTask task = getTask(te.getEntity()); + if (task != null) continue; if (te instanceof DownloadTaskEntity) { if (te.requestType == AbsTaskEntity.D_FTP || te.requestType == AbsTaskEntity.U_FTP) { te.urlEntity = CommonUtil.getFtpUrlInfo(te.getEntity().getKey()); @@ -152,6 +156,7 @@ class StartCmd extends AbsNormalCmd { mQueue = DownloadGroupTaskQueue.getInstance(); } createTask(te); + sendWaitState(); } } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java index ce686b2d..04b6d44f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java @@ -31,6 +31,7 @@ import java.lang.ref.WeakReference; */ class BaseDListener, TASK extends AbsTask> implements IDownloadListener { + private static final String TAG = "BaseDListener"; protected WeakReference outHandler; private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度 private long mLastLen = 0; //上一次发送长度 diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java index f4b4e0b3..ee2b44b4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java @@ -17,6 +17,7 @@ package com.arialyy.aria.core.download; import android.os.Handler; import android.os.Looper; +import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.downloader.DownloadGroupUtil; @@ -81,6 +82,11 @@ public class DownloadGroupTask extends AbsGroupTask { mUtil.cancel(); } + @Override public String getTaskName() { + return "任务组->" + (TextUtils.isEmpty(mTaskEntity.getEntity().getAlias()) + ? mTaskEntity.getEntity().getGroupName() : mTaskEntity.getEntity().getAlias()); + } + public static class Builder { DownloadGroupTaskEntity taskEntity; Handler outHandler; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java index b32d5634..b45a9478 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java @@ -148,6 +148,10 @@ public class DownloadTask extends AbsNormalTask { mUtil.cancel(); } + @Override public String getTaskName() { + return mEntity.getFileName(); + } + public static class Builder { DownloadTaskEntity taskEntity; Handler outHandler; diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java index d067478b..838b0eb0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java @@ -38,6 +38,10 @@ public abstract class AbsTask implements ITas protected Context mContext; protected boolean isHeighestTask = false; + public Handler getOutHandler() { + return mOutHandler; + } + /** * 任务是否完成 * @@ -163,6 +167,11 @@ public abstract class AbsTask implements ITas return mTaskEntity; } + /** + * 获取任务名,也就是文件名 + */ + public abstract String getTaskName(); + public String getTargetName() { return mTargetName; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java b/Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java index 7ead1e77..56018a88 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java @@ -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(); + } + } + /** * 向管理器中增加任务实体 * diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java index e55c1302..b8c02a25 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java @@ -63,7 +63,7 @@ abstract class AbsTaskQueue= getMaxTaskNum()) { @@ -167,12 +167,12 @@ abstract class AbsTaskQueue { +public class DownloadTaskQueue extends AbsTaskQueue { private static final String TAG = "DownloadTaskQueue"; private static volatile DownloadTaskQueue INSTANCE = null; @@ -120,10 +119,15 @@ public class DownloadTaskQueue @Override public DownloadTask createTask(String target, DownloadTaskEntity entity) { DownloadTask task = null; if (!TextUtils.isEmpty(target)) { - task = (DownloadTask) TaskFactory.getInstance() - .createTask(target, entity, DownloadSchedulers.getInstance()); - entity.key = entity.getEntity().getDownloadPath(); - mCachePool.putTask(task); + if (mCachePool.getTask(entity.getEntity().getKey()) == null + && mExecutePool.getTask(entity.getEntity().getKey()) == null) { + task = (DownloadTask) TaskFactory.getInstance() + .createTask(target, entity, DownloadSchedulers.getInstance()); + entity.key = entity.getEntity().getDownloadPath(); + mCachePool.putTask(task); + } else { + ALog.w(TAG, "任务已存在"); + } } else { ALog.e(TAG, "target name 为 null!!"); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/QueueControl.java b/Aria/src/main/java/com/arialyy/aria/core/queue/QueueControl.java deleted file mode 100644 index 107bc203..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/QueueControl.java +++ /dev/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; - } -} diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java index c2def42c..293b81f7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java @@ -65,10 +65,15 @@ public class UploadTaskQueue extends AbsTaskQueue @Override public UploadTask createTask(String targetName, UploadTaskEntity entity) { UploadTask task = null; if (!TextUtils.isEmpty(targetName)) { - task = (UploadTask) TaskFactory.getInstance() - .createTask(targetName, entity, UploadSchedulers.getInstance()); - entity.key = entity.getEntity().getFilePath(); - mCachePool.putTask(task); + if (mCachePool.getTask(entity.getEntity().getKey()) == null + && mExecutePool.getTask(entity.getEntity().getKey()) == null) { + task = (UploadTask) TaskFactory.getInstance() + .createTask(targetName, entity, UploadSchedulers.getInstance()); + entity.key = entity.getEntity().getFilePath(); + mCachePool.putTask(task); + } else { + ALog.w(TAG, "任务已存在"); + } } else { ALog.e(TAG, "target name 为 null是!!"); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java index fb8d0f59..ca656847 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java @@ -54,8 +54,8 @@ public class BaseCachePool implements IPool { /** * 清除所有缓存的任务 */ - public void clear(){ - for (String key : mCacheMap.keySet()){ + public void clear() { + for (String key : mCacheMap.keySet()) { TASK task = mCacheMap.get(key); mCacheQueue.remove(task); mCacheMap.remove(key); @@ -85,16 +85,16 @@ public class BaseCachePool implements IPool { @Override public boolean putTask(TASK task) { synchronized (AriaManager.LOCK) { if (task == null) { - ALog.e(TAG, "下载任务不能为空!!"); + ALog.e(TAG, "任务不能为空!!"); return false; } String url = task.getKey(); if (mCacheQueue.contains(task)) { - ALog.w(TAG, "队列中已经包含了该任务,任务下载链接【" + url + "】"); + ALog.w(TAG, "任务【" + task.getTaskName() + "】进入缓存队列失败,原因:已经在缓存队列中"); return false; } else { boolean s = mCacheQueue.offer(task); - ALog.d(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】")); + ALog.d(TAG, "任务【" + task.getTaskName() + "】进入缓存队列" + (s ? "成功" : "失败")); if (s) { mCacheMap.put(CommonUtil.keyToHashKey(url), task); } @@ -120,14 +120,13 @@ public class BaseCachePool implements IPool { return null; } - @Override public TASK getTask(String downloadUrl) { + @Override public TASK getTask(String key) { synchronized (AriaManager.LOCK) { - if (TextUtils.isEmpty(downloadUrl)) { - ALog.e(TAG, "请传入有效的下载链接"); + if (TextUtils.isEmpty(key)) { + ALog.e(TAG, "key 为null"); return null; } - String key = CommonUtil.keyToHashKey(downloadUrl); - return mCacheMap.get(key); + return mCacheMap.get(CommonUtil.keyToHashKey(key)); } } @@ -144,15 +143,15 @@ public class BaseCachePool implements IPool { } } - @Override public boolean removeTask(String downloadUrl) { + @Override public boolean removeTask(String key) { synchronized (AriaManager.LOCK) { - if (TextUtils.isEmpty(downloadUrl)) { + if (TextUtils.isEmpty(key)) { ALog.e(TAG, "请传入有效的下载链接"); return false; } - String key = CommonUtil.keyToHashKey(downloadUrl); - TASK task = mCacheMap.get(key); - mCacheMap.remove(key); + String temp = CommonUtil.keyToHashKey(key); + TASK task = mCacheMap.get(temp); + mCacheMap.remove(temp); return mCacheQueue.remove(task); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java index 58e69bc2..60e24552 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java @@ -65,9 +65,8 @@ public class BaseExecutePool implements IPool { ALog.e(TAG, "任务不能为空!!"); return false; } - String url = task.getKey(); if (mExecuteQueue.contains(task)) { - ALog.e(TAG, "队列中已经包含了该任务,任务key【" + url + "】"); + ALog.e(TAG, "任务【" + task.getTaskName() + "】进入执行队列失败,原因:已经在执行队列中"); return false; } else { if (mExecuteQueue.size() >= mSize) { @@ -112,7 +111,7 @@ public class BaseExecutePool implements IPool { synchronized (AriaManager.LOCK) { String url = newTask.getKey(); boolean s = mExecuteQueue.offer(newTask); - ALog.d(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】")); + ALog.d(TAG, "任务【" + newTask.getTaskName() + "】进入执行队列" + (s ? "成功" : "失败")); if (s) { mExecuteMap.put(CommonUtil.keyToHashKey(url), newTask); } @@ -128,7 +127,7 @@ public class BaseExecutePool implements IPool { try { TASK oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS); if (oldTask == null) { - ALog.w(TAG, "移除任务失败"); + ALog.w(TAG, "移除任务失败,原因:任务为null"); return false; } oldTask.stop(); @@ -162,7 +161,7 @@ public class BaseExecutePool implements IPool { @Override public TASK getTask(String key) { synchronized (AriaManager.LOCK) { if (TextUtils.isEmpty(key)) { - ALog.e(TAG, "请传入有效的任务key"); + ALog.e(TAG, "key 为null"); return null; } return mExecuteMap.get(CommonUtil.keyToHashKey(key)); @@ -183,7 +182,7 @@ public class BaseExecutePool implements IPool { @Override public boolean removeTask(String key) { synchronized (AriaManager.LOCK) { if (TextUtils.isEmpty(key)) { - ALog.e(TAG, "请传入有效的任务key"); + ALog.e(TAG, "key 为null"); return false; } String convertKey = CommonUtil.keyToHashKey(key); diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java index 4fde7329..db3b6c83 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java @@ -39,10 +39,9 @@ class DownloadExecutePool extends BaseExecutePool { ALog.e(TAG, "任务不能为空!!"); return false; } - String url = task.getKey(); if (mExecuteQueue.contains(task)) { if (!task.isRunning()) return true; - ALog.e(TAG, "队列中已经包含了该任务,任务key【" + url + "】"); + ALog.e(TAG, "任务【" + task.getTaskName() + "】进入执行队列失败,错误原因:已经在执行队列中"); return false; } else { if (mExecuteQueue.size() >= mSize) { @@ -65,7 +64,7 @@ class DownloadExecutePool extends BaseExecutePool { try { TASK oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS); if (oldTask == null) { - ALog.e(TAG, "移除任务失败"); + ALog.w(TAG, "移除任务失败,错误原因:任务为null"); return false; } if (oldTask.isHighestPriorityTask()) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java index 863c595b..e6e36ebe 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java @@ -21,7 +21,12 @@ import com.arialyy.aria.core.inf.ITask; /** * Created by Aria.Lao on 2017/6/7. */ -public class AbsSchedulerListener implements ISchedulerListener { +public class AbsSchedulerListener + implements ISchedulerListener { + + @Override public void onWait(TASK task) { + + } @Override public void onPre(TASK task) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java index 55916c1c..83f82b28 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java @@ -175,6 +175,8 @@ abstract class AbsSchedulers { + + /** + * 队列已经满了,继续创建任务,将会回调该方法 + */ + void onWait(TASK task); + /** * 预处理,有时有些地址链接比较慢,这时可以先在这个地方出来一些界面上的UI,如按钮的状态。 * 在这个回调中,任务是获取不到文件大小,下载速度等参数 @@ -66,8 +72,4 @@ public interface ISchedulerListener { * 任务执行中 */ void onTaskRunning(TASK task); - - - - } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java index c48ebf2e..679c6b85 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java @@ -70,6 +70,10 @@ public interface ISchedulers extends Handler.Callback { * 恢复任务 */ int RESUME = 8; + /** + * 等待 + */ + int WAIT = 10; /** * 任务组子任务预处理 diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java index ed2967b3..22398a27 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java @@ -17,6 +17,8 @@ package com.arialyy.aria.core.upload; import android.support.annotation.NonNull; 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.AbsUploadTarget; import com.arialyy.aria.core.manager.TEManager; @@ -97,4 +99,14 @@ public class FtpUploadTarget mTaskEntity.urlEntity.account = account; return this; } + + /** + * 添加任务 + */ + public void add() { + AriaManager.getInstance(AriaManager.APP) + .setCmd(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CREATE, + checkTaskType())) + .exe(); + } } diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java index c3dd262b..3b75d256 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -23,6 +23,7 @@ import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import android.support.v4.util.LruCache; import android.text.TextUtils; +import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CheckUtil; @@ -31,9 +32,11 @@ import java.lang.reflect.Field; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Date; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; /** * 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 volatile SqlHelper INSTANCE = null; - private static LruCache mDataCache = new LruCache<>(1024); + private static LruCache mDataCache = new LruCache<>(1024); + //private static Map mDataCache = new ConcurrentHashMap<>(); static SqlHelper init(Context context) { if (INSTANCE == null) { @@ -330,7 +334,7 @@ final class SqlHelper extends SQLiteOpenHelper { db = checkDb(db); Class clazz = dbEntity.getClass(); List fields = CommonUtil.getAllFields(clazz); - DbEntity cacheEntity = mDataCache.get(dbEntity.hashCode()); + DbEntity cacheEntity = mDataCache.get(getCacheKey(dbEntity)); if (fields != null && fields.size() > 0) { StringBuilder sql = new StringBuilder(); StringBuilder prams = new StringBuilder(); @@ -342,7 +346,15 @@ final class SqlHelper extends SQLiteOpenHelper { continue; } 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; } @@ -383,9 +395,14 @@ final class SqlHelper extends SQLiteOpenHelper { db.execSQL(sql.toString()); } } + mDataCache.put(getCacheKey(dbEntity), dbEntity); 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")); - mDataCache.put(entity.hashCode(), entity); + mDataCache.put(getCacheKey(entity), entity); entitys.add(entity); } closeCursor(cursor); diff --git a/AriaAnnotations/src/main/java/com/arialyy/annotations/Download.java b/AriaAnnotations/src/main/java/com/arialyy/annotations/Download.java index 41110643..7c40bf24 100644 --- a/AriaAnnotations/src/main/java/com/arialyy/annotations/Download.java +++ b/AriaAnnotations/src/main/java/com/arialyy/annotations/Download.java @@ -35,71 +35,79 @@ import java.lang.annotation.Target; * 则表示,所有下载任务中,只有下载地址为"http://www.baidu.com"的任务才能回调该注解的方法。 */ @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 { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Download.onTaskPre}注解,在任务预处理完成时,Aria会调用该方法 + * {@code @Download.onTaskPre}注解,在任务预处理完成时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskPre { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Download.onTaskResume}注解,在任务恢复下载时,Aria会调用该方法 + * {@code @Download.onTaskResume}注解,在任务恢复下载时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskResume { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Download.onTaskStart}注解,在任务开始下载时,Aria会调用该方法 + * {@code @Download.onTaskStart}注解,在任务开始下载时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStart { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Download.onTaskStop}注解,在任务停止时,Aria会调用该方法 + * {@code @Download.onTaskStop}注解,在任务停止时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStop { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Download.onTaskCancel}l注解,在任务取消时,Aria会调用该方法 + * {@code @Download.onTaskCancel}l注解,在任务取消时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskCancel { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Download.onTaskFail)注解,在任务预失败时,Aria会调用该方法 + * {@code @Download.onTaskFail)注解,在任务预失败时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskFail { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Download.onTaskComplete}注解,在任务完成时,Aria会调用该方法 + * {@code @Download.onTaskComplete}注解,在任务完成时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskComplete { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Download.onTaskRunning}注解,在任务正在下载,Aria会调用该方法 + * {@code @Download.onTaskRunning}注解,在任务正在下载,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskRunning { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Download.onNoSupportBreakPoint}注解,如果该任务不支持断点,Aria会调用该方法 + * {@code @Download.onNoSupportBreakPoint}注解,如果该任务不支持断点,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onNoSupportBreakPoint { diff --git a/AriaAnnotations/src/main/java/com/arialyy/annotations/DownloadGroup.java b/AriaAnnotations/src/main/java/com/arialyy/annotations/DownloadGroup.java index 11521b9d..bb26d4f1 100644 --- a/AriaAnnotations/src/main/java/com/arialyy/annotations/DownloadGroup.java +++ b/AriaAnnotations/src/main/java/com/arialyy/annotations/DownloadGroup.java @@ -44,64 +44,72 @@ import java.lang.annotation.Target; * */ @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 { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @DownloadGroup.onTaskPre}注解,在任务预处理完成时,Aria会调用该方法 + * {@code @DownloadGroup.onTaskPre}注解,在任务预处理完成时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskPre { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @DownloadGroup.onTaskResume}注解,在任务恢复下载时,Aria会调用该方法 + * {@code @DownloadGroup.onTaskResume}注解,在任务恢复下载时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskResume { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @DownloadGroup.onTaskStart}注解,在任务开始下载时,Aria会调用该方法 + * {@code @DownloadGroup.onTaskStart}注解,在任务开始下载时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStart { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @DownloadGroup.onTaskStop}注解,在任务停止时,Aria会调用该方法 + * {@code @DownloadGroup.onTaskStop}注解,在任务停止时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStop { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @DownloadGroup.onTaskCancel}l注解,在任务取消时,Aria会调用该方法 + * {@code @DownloadGroup.onTaskCancel}l注解,在任务取消时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskCancel { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @DownloadGroup.onTaskFail)注解,在任务预失败时,Aria会调用该方法 + * {@code @DownloadGroup.onTaskFail)注解,在任务预失败时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskFail { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @DownloadGroup.onTaskComplete}注解,在任务完成时,Aria会调用该方法 + * {@code @DownloadGroup.onTaskComplete}注解,在任务完成时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskComplete { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @DownloadGroup.onTaskRunning}注解,在任务正在下载,Aria会调用该方法 + * {@code @DownloadGroup.onTaskRunning}注解,在任务正在下载,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskRunning { String[] value() default { AriaConstance.NO_URL }; diff --git a/AriaAnnotations/src/main/java/com/arialyy/annotations/Upload.java b/AriaAnnotations/src/main/java/com/arialyy/annotations/Upload.java index cc197f92..362a3b47 100644 --- a/AriaAnnotations/src/main/java/com/arialyy/annotations/Upload.java +++ b/AriaAnnotations/src/main/java/com/arialyy/annotations/Upload.java @@ -37,63 +37,70 @@ import java.lang.annotation.Target; @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 { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Upload.onTaskResume}注解,在任务恢复下载时,Aria会调用该方法 + * {@code @Upload.onTaskResume}注解,在任务恢复下载时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskResume { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Upload.onTaskStart}注解,在任务开始下载时,Aria会调用该方法 + * {@code @Upload.onTaskStart}注解,在任务开始下载时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStart { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Upload.onTaskStop}注解,在任务停止时,Aria会调用该方法 + * {@code @Upload.onTaskStop}注解,在任务停止时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskStop { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Upload.onTaskCancel}l注解,在任务取消时,Aria会调用该方法 + * {@code @Upload.onTaskCancel}l注解,在任务取消时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskCancel { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Upload.onTaskFail)注解,在任务预失败时,Aria会调用该方法 + * {@code @Upload.onTaskFail)注解,在任务预失败时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskFail { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Upload.onTaskComplete}注解,在任务完成时,Aria会调用该方法 + * {@code @Upload.onTaskComplete}注解,在任务完成时,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskComplete { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Upload.onTaskRunning}注解,在任务正在下载,Aria会调用该方法 + * {@code @Upload.onTaskRunning}注解,在任务正在下载,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onTaskRunning { String[] value() default { AriaConstance.NO_URL }; } /** - * 如果你在方法中添加{@code @Upload.onNoSupportBreakPoint}注解,如果该任务不支持断点,Aria会调用该方法 + * {@code @Upload.onNoSupportBreakPoint}注解,如果该任务不支持断点,Aria会调用该方法 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onNoSupportBreakPoint { String[] value() default { AriaConstance.NO_URL }; diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/AriaProcessor.java b/AriaCompiler/src/main/java/com/arialyy/compiler/AriaProcessor.java index ede028cc..33b9bb25 100644 --- a/AriaCompiler/src/main/java/com/arialyy/compiler/AriaProcessor.java +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/AriaProcessor.java @@ -44,6 +44,7 @@ import javax.lang.model.element.TypeElement; @Override public Set getSupportedAnnotationTypes() { Set annotataions = new LinkedHashSet<>(); //单任务下载的注解 + annotataions.add(Download.onWait.class.getCanonicalName()); annotataions.add(Download.onPre.class.getCanonicalName()); annotataions.add(Download.onNoSupportBreakPoint.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.onTaskStop.class.getCanonicalName()); //下载任务组的注解 + annotataions.add(DownloadGroup.onWait.class.getCanonicalName()); annotataions.add(DownloadGroup.onPre.class.getCanonicalName()); annotataions.add(DownloadGroup.onTaskCancel.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.onSubTaskStop.class.getCanonicalName()); //上传任务的注解 + annotataions.add(Upload.onWait.class.getCanonicalName()); annotataions.add(Upload.onPre.class.getCanonicalName()); annotataions.add(Upload.onNoSupportBreakPoint.class.getCanonicalName()); annotataions.add(Upload.onTaskCancel.class.getCanonicalName()); diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java b/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java index bcb697a5..e497fe65 100644 --- a/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java @@ -44,6 +44,7 @@ class ElementHandler { * PackageElement 一般代表Package */ void handleDownload(RoundEnvironment roundEnv) { + mPbUtil.saveMethod(TaskEnum.DOWNLOAD, roundEnv, Download.onWait.class, ProxyConstance.WAIT); mPbUtil.saveMethod(TaskEnum.DOWNLOAD, roundEnv, Download.onNoSupportBreakPoint.class, ProxyConstance.TASK_NO_SUPPORT_BREAKPOINT); mPbUtil.saveMethod(TaskEnum.DOWNLOAD, roundEnv, Download.onPre.class, ProxyConstance.PRE); @@ -69,6 +70,8 @@ class ElementHandler { * 处理搜索到的下载任务组注解 */ void handleDownloadGroup(RoundEnvironment roundEnv) { + mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP, roundEnv, DownloadGroup.onWait.class, + ProxyConstance.WAIT); mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP, roundEnv, DownloadGroup.onPre.class, ProxyConstance.PRE); mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP, roundEnv, DownloadGroup.onTaskCancel.class, @@ -113,6 +116,7 @@ class ElementHandler { * 处理搜索到的上传注解F */ void handleUpload(RoundEnvironment roundEnv) { + mPbUtil.saveMethod(TaskEnum.UPLOAD, roundEnv, Upload.onWait.class, ProxyConstance.WAIT); mPbUtil.saveMethod(TaskEnum.UPLOAD, roundEnv, Upload.onNoSupportBreakPoint.class, ProxyConstance.TASK_NO_SUPPORT_BREAKPOINT); mPbUtil.saveMethod(TaskEnum.UPLOAD, roundEnv, Upload.onPre.class, ProxyConstance.PRE); diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyConstance.java b/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyConstance.java index 002d0d89..8ebb6978 100644 --- a/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyConstance.java +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyConstance.java @@ -50,6 +50,7 @@ interface ProxyConstance { String COUNT_METHOD_DOWNLOAD_GROUP_SUB = "getDownloadGroupSubCounter"; String COUNT_METHOD_UPLOAD = "getUploadCounter"; + int WAIT = 0X10; int PRE = 0X11; int TASK_PRE = 0X12; int TASK_RESUME = 0X13; diff --git a/DEV_LOG.md b/DEV_LOG.md index 3b31349b..35476cb2 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -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 - 添加进度更新间隔api,在`aria_config.xml`配置``或在代码中调用 `AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)`便可以改变进度刷新间隔 diff --git a/README.md b/README.md index f3d1aa47..6ec226a7 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ protected void onCreate(Bundle savedInstanceState) { ### [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki) -### 升级日志 +### 版本日志 + v_3.3.11 - 添加进度更新间隔api,在`aria_config.xml`配置``或在代码中调用 `AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)`便可以改变进度刷新间隔 diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index d6b07b78..de5f6eb8 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -122,6 +122,10 @@ public class SingleTaskActivity extends BaseActivity { return true; } + @Download.onWait void onWait(DownloadTask task){ + Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); + } + @Download.onPre protected void onPre(DownloadTask task) { setBtState(false); } @@ -230,7 +234,8 @@ public class SingleTaskActivity extends BaseActivity { //.setRequestMode(RequestEnum.POST) .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk") .resetState() - .start(); + //.start(); + .add(); } @Override protected void onDestroy() { diff --git a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java index b682d4c7..75397bd1 100644 --- a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java @@ -17,16 +17,13 @@ package com.arialyy.simple.download.group; import android.os.Bundle; import android.os.Environment; -import android.support.design.widget.FloatingActionButton; import android.view.View; import butterknife.Bind; import com.arialyy.annotations.DownloadGroup; 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.DownloadGroupTask; 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.T; import com.arialyy.simple.R; @@ -66,8 +63,6 @@ public class DownloadGroupActivity extends BaseActivity { } } + @Download.onWait void taskWait(DownloadTask task){ + Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); + } + @Download.onTaskStart void taskStart(DownloadTask task) { mAdapter.updateBtState(task.getKey(), false); } diff --git a/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java b/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java index edc42725..8b34f75a 100644 --- a/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java @@ -34,7 +34,7 @@ import com.arialyy.simple.databinding.ActivityFtpUploadBinding; * Ftp 文件上传demo */ public class FtpUploadActivity extends BaseActivity { - 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/测试"; @Override protected void init(Bundle savedInstanceState) { @@ -56,7 +56,7 @@ public class FtpUploadActivity extends BaseActivity { public void onClick(View view) { switch (view.getId()) { 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; case R.id.stop: Aria.upload(this).loadFtp(FILE_PATH).stop(); @@ -67,6 +67,10 @@ public class FtpUploadActivity extends BaseActivity { } } + @Upload.onWait void onWait(UploadTask task){ + Log.d(TAG, task.getTaskName() + "_wait"); + } + @Upload.onPre public void onPre(UploadTask task) { getBinding().setFileSize(task.getConvertFileSize()); } diff --git a/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java b/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java index 91963876..9ebb8d56 100644 --- a/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java @@ -17,6 +17,7 @@ package com.arialyy.simple.upload; import android.os.Bundle; +import android.util.Log; import butterknife.Bind; import butterknife.OnClick; import com.arialyy.annotations.Upload; @@ -63,6 +64,7 @@ public class HttpUploadActivity extends BaseActivity { Aria.upload(this).load(FILE_PATH).cancel(); } + @Upload.onPre public void onPre(UploadTask task) { } diff --git a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java index 678a84ac..8e0e4e87 100644 --- a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java +++ b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java @@ -74,6 +74,10 @@ public class UploadTask extends AbsNormalTask { mUtil.cancel(); } + @Override public String getTaskName() { + return mTaskEntity.getEntity().getFileName(); + } + public static class Builder { private Handler mOutHandler; private UploadTaskEntity mTaskEntity;