修复组合任务在获取子任务信息的过程中,手动停止或删除,没有回调的问题

This commit is contained in:
laoyuyu
2020-12-09 21:22:01 +08:00
parent 35e66caab5
commit 9db8f1e9c0
16 changed files with 174 additions and 54 deletions

View File

@@ -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();
}

View File

@@ -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) { // 处理队列变小的情况,该情况下将停止队尾任务,并将这些任务添加到缓存队列中

View File

@@ -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();

View File

@@ -34,6 +34,16 @@ public interface IInfoTask extends ILoaderComponent {
*/
void setCallback(Callback callback);
/**
* 任务停止
*/
void stop();
/**
* 任务取消
*/
void cancel();
interface Callback {
/**
* 处理完成