任务组子任务控制bug修复,apt注解修复
This commit is contained in:
@@ -19,6 +19,7 @@ import android.util.Log;
|
||||
import com.arialyy.aria.core.command.AbsCmd;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTask;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.BaseGroupTaskEntity;
|
||||
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@@ -48,11 +49,24 @@ public abstract class AbsGroupCmd<T extends BaseGroupTaskEntity> extends AbsCmd<
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建任务
|
||||
*
|
||||
* @return 创建的任务
|
||||
*/
|
||||
AbsTask createTask() {
|
||||
tempTask = (AbsGroupTask) mQueue.createTask(mTargetName, mTaskEntity);
|
||||
return tempTask;
|
||||
}
|
||||
|
||||
boolean checkTask() {
|
||||
tempTask = (AbsGroupTask) mQueue.getTask(mTaskEntity.getEntity());
|
||||
if (tempTask == null || !tempTask.isRunning()) {
|
||||
Log.d(TAG, "任务组没有执行,先执行任务组任务才能够执行子任务");
|
||||
return false;
|
||||
if (tempTask == null) {
|
||||
createTask();
|
||||
if (tempTask.isComplete()) {
|
||||
Log.w(TAG, "任务已完成");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ import static java.util.Collections.unmodifiableSet;
|
||||
* 代理参数获取
|
||||
*/
|
||||
public class ProxyHelper {
|
||||
public Set<String> downloadCounter, uploadCounter, downloadGroupCounter;
|
||||
public Set<String> downloadCounter, uploadCounter, downloadGroupCounter, downloadGroupSubCounter;
|
||||
|
||||
public static volatile ProxyHelper INSTANCE = null;
|
||||
|
||||
@@ -49,6 +49,7 @@ public class ProxyHelper {
|
||||
Class clazz = Class.forName("com.arialyy.aria.ProxyClassCounter");
|
||||
Method download = clazz.getMethod("getDownloadCounter");
|
||||
Method downloadGroup = clazz.getMethod("getDownloadGroupCounter");
|
||||
Method downloadGroupSub = clazz.getMethod("getDownloadGroupSubCounter");
|
||||
Method upload = clazz.getMethod("getUploadCounter");
|
||||
Object object = clazz.newInstance();
|
||||
Object dc = download.invoke(object);
|
||||
@@ -59,6 +60,10 @@ public class ProxyHelper {
|
||||
if (dgc != null) {
|
||||
downloadGroupCounter = unmodifiableSet((Set<String>) dgc);
|
||||
}
|
||||
Object dgsc = downloadGroupSub.invoke(object);
|
||||
if (dgsc != null){
|
||||
downloadGroupSubCounter = unmodifiableSet((Set<? extends String>) dgsc);
|
||||
}
|
||||
Object uc = upload.invoke(object);
|
||||
if (uc != null) {
|
||||
uploadCounter = unmodifiableSet((Set<String>) uc);
|
||||
|
@@ -139,10 +139,12 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
String className = obj.getClass().getName();
|
||||
Set<String> dCounter = ProxyHelper.getInstance().downloadCounter;
|
||||
Set<String> dgCounter = ProxyHelper.getInstance().downloadGroupCounter;
|
||||
Set<String> dgsCounter = ProxyHelper.getInstance().downloadGroupSubCounter;
|
||||
if (dCounter != null && dCounter.contains(className)) {
|
||||
DownloadSchedulers.getInstance().register(obj);
|
||||
}
|
||||
if (dgCounter != null && dgCounter.contains(className)) {
|
||||
if ((dgCounter != null && dgCounter.contains(className)) || (dgsCounter != null
|
||||
&& dgsCounter.contains(className))) {
|
||||
DownloadGroupSchedulers.getInstance().register(obj);
|
||||
}
|
||||
return this;
|
||||
@@ -155,10 +157,12 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
String className = obj.getClass().getName();
|
||||
Set<String> dCounter = ProxyHelper.getInstance().downloadCounter;
|
||||
Set<String> dgCounter = ProxyHelper.getInstance().downloadGroupCounter;
|
||||
Set<String> dgsCounter = ProxyHelper.getInstance().downloadGroupSubCounter;
|
||||
if (dCounter != null && dCounter.contains(className)) {
|
||||
DownloadSchedulers.getInstance().unRegister(obj);
|
||||
}
|
||||
if (dgCounter != null && dgCounter.contains(className)) {
|
||||
if (dgCounter != null && dgCounter.contains(className) || (dgsCounter != null
|
||||
&& dgsCounter.contains(className))) {
|
||||
DownloadGroupSchedulers.getInstance().unRegister(obj);
|
||||
}
|
||||
if (needRmReceiver) {
|
||||
|
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.download.downloader;
|
||||
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.IUtil;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
@@ -82,6 +81,8 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
private int mCompleteNum = 0;
|
||||
//失败的任务数
|
||||
private int mFailNum = 0;
|
||||
//停止的任务数
|
||||
private int mStopNum = 0;
|
||||
//实际的下载任务数
|
||||
int mActualTaskNum = 0;
|
||||
/**
|
||||
@@ -98,6 +99,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
if (tasks != null && !tasks.isEmpty()) {
|
||||
for (DownloadTaskEntity te : tasks) {
|
||||
te.removeFile = mTaskEntity.removeFile;
|
||||
if (te.getEntity() == null) continue;
|
||||
mTasksMap.put(te.getEntity().getUrl(), te);
|
||||
}
|
||||
}
|
||||
@@ -108,6 +110,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
if (entity.getState() == IEntity.STATE_COMPLETE && file.exists()) {
|
||||
mCompleteNum++;
|
||||
mInitNum++;
|
||||
mStopNum++;
|
||||
mCurrentLocation += entity.getFileSize();
|
||||
} else {
|
||||
mExeMap.put(entity.getUrl(), createChildDownloadTask(entity));
|
||||
@@ -134,6 +137,10 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
* @param url 子任务下载地址
|
||||
*/
|
||||
public void startSubTask(String url) {
|
||||
isRunning = true;
|
||||
if (mTimer == null) {
|
||||
startTimer();
|
||||
}
|
||||
Downloader d = getDownloader(url);
|
||||
if (d != null && !d.isRunning()) {
|
||||
d.start();
|
||||
@@ -172,8 +179,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
private Downloader getDownloader(String url) {
|
||||
Downloader d = mDownloaderMap.get(url);
|
||||
if (d == null) {
|
||||
Log.e(TAG, "链接【" + url + "】对应的下载器不存在");
|
||||
return null;
|
||||
return startChildDownload(mExeMap.get(url));
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -283,6 +289,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
if (mTimer != null) {
|
||||
mTimer.purge();
|
||||
mTimer.cancel();
|
||||
mTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,6 +300,10 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
closeTimer(true);
|
||||
mListener.onPostPre(mTotalSize);
|
||||
mListener.onStart(mCurrentLocation);
|
||||
startTimer();
|
||||
}
|
||||
|
||||
private void startTimer() {
|
||||
mTimer = new Timer(true);
|
||||
mTimer.schedule(new TimerTask() {
|
||||
@Override public void run() {
|
||||
@@ -308,12 +319,13 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
/**
|
||||
* 启动子任务下载器
|
||||
*/
|
||||
void startChildDownload(DownloadTaskEntity taskEntity) {
|
||||
Downloader startChildDownload(DownloadTaskEntity taskEntity) {
|
||||
ChildDownloadListener listener = new ChildDownloadListener(taskEntity);
|
||||
Downloader dt = new Downloader(listener, taskEntity);
|
||||
mDownloaderMap.put(taskEntity.getEntity().getUrl(), dt);
|
||||
if (mExePool.isShutdown()) return;
|
||||
if (mExePool.isShutdown()) return dt;
|
||||
mExePool.execute(dt);
|
||||
return dt;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -400,6 +412,11 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
saveData(IEntity.STATE_STOP, stopLocation);
|
||||
handleSpeed(0);
|
||||
mListener.onSubStop(entity);
|
||||
mStopNum++;
|
||||
if (mStopNum >= mInitNum) {
|
||||
closeTimer(false);
|
||||
mListener.onStop(mCurrentLocation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onCancel() {
|
||||
|
@@ -86,7 +86,6 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
||||
if (mSleepTime > 0) Thread.sleep(mSleepTime);
|
||||
file.write(buffer, 0, len);
|
||||
progress(len);
|
||||
Log.d(TAG, len + "");
|
||||
}
|
||||
if (STATE.isCancel || STATE.isStop) return;
|
||||
//支持断点的处理
|
||||
|
Reference in New Issue
Block a user