修复组合任务在获取子任务信息的过程中,手动停止或删除,没有回调的问题
This commit is contained in:
@@ -217,14 +217,20 @@ public abstract class AbsGroupLoader implements ILoaderVisitor, ILoader {
|
||||
|
||||
@Override public void cancel() {
|
||||
isCancel = true;
|
||||
mInfoTask.cancel();
|
||||
closeTimer();
|
||||
mSubQueue.removeAllTask();
|
||||
mListener.onCancel();
|
||||
}
|
||||
|
||||
@Override public void stop() {
|
||||
mInfoTask.stop();
|
||||
isStop = true;
|
||||
mSubQueue.stopAllTask();
|
||||
if (mSubQueue.getExecSize() == 0) {
|
||||
mListener.onStop(mGTWrapper.getEntity().getCurrentProgress());
|
||||
} else {
|
||||
mSubQueue.stopAllTask();
|
||||
}
|
||||
closeTimer();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ final class SimpleSubQueue implements ISubQueue<AbsSubDLoadUtil> {
|
||||
/**
|
||||
* 最大执行任务数
|
||||
*/
|
||||
private int mExecSize;
|
||||
private int mMaxExecSize;
|
||||
|
||||
/**
|
||||
* 是否停止任务任务
|
||||
@@ -51,7 +51,7 @@ final class SimpleSubQueue implements ISubQueue<AbsSubDLoadUtil> {
|
||||
private boolean isStopAll = false;
|
||||
|
||||
private SimpleSubQueue() {
|
||||
mExecSize = Configuration.getInstance().dGroupCfg.getSubMaxTaskNum();
|
||||
mMaxExecSize = Configuration.getInstance().dGroupCfg.getSubMaxTaskNum();
|
||||
}
|
||||
|
||||
static SimpleSubQueue newInstance() {
|
||||
@@ -73,6 +73,10 @@ final class SimpleSubQueue implements ISubQueue<AbsSubDLoadUtil> {
|
||||
return mCache.size();
|
||||
}
|
||||
|
||||
public int getExecSize(){
|
||||
return mExec.size();
|
||||
}
|
||||
|
||||
boolean isStopAll() {
|
||||
return isStopAll;
|
||||
}
|
||||
@@ -82,7 +86,7 @@ final class SimpleSubQueue implements ISubQueue<AbsSubDLoadUtil> {
|
||||
}
|
||||
|
||||
@Override public void startTask(AbsSubDLoadUtil fileer) {
|
||||
if (mExec.size() < mExecSize) {
|
||||
if (mExec.size() < mMaxExecSize) {
|
||||
mCache.remove(fileer.getKey());
|
||||
mExec.put(fileer.getKey(), fileer);
|
||||
ALog.d(TAG,
|
||||
@@ -102,6 +106,7 @@ final class SimpleSubQueue implements ISubQueue<AbsSubDLoadUtil> {
|
||||
@Override public void stopAllTask() {
|
||||
isStopAll = true;
|
||||
ALog.d(TAG, "停止组合任务");
|
||||
mCache.clear();
|
||||
Set<String> keys = mExec.keySet();
|
||||
for (String key : keys) {
|
||||
AbsSubDLoadUtil loader = mExec.get(key);
|
||||
@@ -117,12 +122,12 @@ final class SimpleSubQueue implements ISubQueue<AbsSubDLoadUtil> {
|
||||
ALog.e(TAG, String.format("修改组合任务子任务队列数失败,num: %s", num));
|
||||
return;
|
||||
}
|
||||
if (num == mExecSize) {
|
||||
ALog.i(TAG, String.format("忽略此次修改,oldSize: %s, num: %s", mExecSize, num));
|
||||
if (num == mMaxExecSize) {
|
||||
ALog.i(TAG, String.format("忽略此次修改,oldSize: %s, num: %s", mMaxExecSize, num));
|
||||
return;
|
||||
}
|
||||
int oldSize = mExecSize;
|
||||
mExecSize = num;
|
||||
int oldSize = mMaxExecSize;
|
||||
mMaxExecSize = num;
|
||||
int diff = Math.abs(oldSize - num);
|
||||
|
||||
if (oldSize < num) { // 处理队列变小的情况,该情况下将停止队尾任务,并将这些任务添加到缓存队列中
|
||||
|
||||
@@ -229,6 +229,7 @@ public abstract class AbsNormalLoader<T extends AbsTaskWrapper> implements ILoad
|
||||
ALog.d(TAG, String.format("任务【%s】正在删除,删除任务失败", mTaskWrapper.getKey()));
|
||||
return;
|
||||
}
|
||||
mInfoTask.cancel();
|
||||
closeTimer();
|
||||
isCancel = true;
|
||||
onCancel();
|
||||
@@ -262,6 +263,7 @@ public abstract class AbsNormalLoader<T extends AbsTaskWrapper> implements ILoad
|
||||
if (isStop) {
|
||||
return;
|
||||
}
|
||||
mInfoTask.stop();
|
||||
closeTimer();
|
||||
isStop = true;
|
||||
onStop();
|
||||
|
||||
@@ -34,6 +34,16 @@ public interface IInfoTask extends ILoaderComponent {
|
||||
*/
|
||||
void setCallback(Callback callback);
|
||||
|
||||
/**
|
||||
* 任务停止
|
||||
*/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* 任务取消
|
||||
*/
|
||||
void cancel();
|
||||
|
||||
interface Callback {
|
||||
/**
|
||||
* 处理完成
|
||||
|
||||
Reference in New Issue
Block a user