修复组合任务获取文件信息时,其中子任务失败,状态回调错误的问题

pull/907/head
laoyuyu 4 years ago
parent 9db8f1e9c0
commit 5853fe9e3e
  1. 26
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java
  2. 13
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoader.java
  3. 3
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoaderUtil.java
  4. 1
      PublicComponent/src/main/java/com/arialyy/aria/core/group/GroupRunState.java
  5. 2
      PublicComponent/src/main/java/com/arialyy/aria/core/group/SimpleSchedulers.java
  6. 12
      app/src/main/java/com/arialyy/simple/core/download/group/GroupModule.java

@ -20,7 +20,6 @@ import com.arialyy.aria.core.common.CompleteInfo;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.listener.DownloadGroupListener;
import com.arialyy.aria.core.loader.IInfoTask;
import com.arialyy.aria.core.loader.ILoaderVisitor;
import com.arialyy.aria.exception.AriaException;
@ -44,9 +43,21 @@ public final class HttpDGInfoTask implements IInfoTask {
private boolean getLenComplete = false;
private AtomicInteger count = new AtomicInteger();
private AtomicInteger failCount = new AtomicInteger();
private DownloadGroupListener listener;
private boolean isStop = false, isCancel = false;
public interface DGInfoCallback extends Callback {
/**
* 子任务失败
*/
void onSubFail(DownloadEntity subEntity, AriaHTTPException e, boolean needRetry);
/**
* 组合任务停止
*/
void onStop(long len);
}
/**
* 子任务回调
*/
@ -61,15 +72,14 @@ public final class HttpDGInfoTask implements IInfoTask {
ALog.e(TAG, String.format("获取文件信息失败,url:%s", ((DownloadEntity) entity).getUrl()));
count.getAndIncrement();
failCount.getAndIncrement();
listener.onSubFail((DownloadEntity) entity, new AriaHTTPException(
String.format("子任务获取文件长度失败,url:%s", ((DownloadEntity) entity).getUrl())));
((DGInfoCallback) callback).onSubFail((DownloadEntity) entity, new AriaHTTPException(
String.format("子任务获取文件长度失败,url:%s", ((DownloadEntity) entity).getUrl())), needRetry);
checkGetSizeComplete(count.get(), failCount.get());
}
};
HttpDGInfoTask(DGTaskWrapper wrapper, DownloadGroupListener listener) {
HttpDGInfoTask(DGTaskWrapper wrapper) {
this.wrapper = wrapper;
this.listener = listener;
}
/**
@ -95,7 +105,7 @@ public final class HttpDGInfoTask implements IInfoTask {
if (mPool != null && !getLenComplete) {
ALog.d(TAG, "获取长度未完成的情况下,停止组合任务");
mPool.shutdown();
listener.onStop(0);
((DGInfoCallback)callback).onStop(0);
return;
}
// 处理组合任务大小未知的情况
@ -150,7 +160,7 @@ public final class HttpDGInfoTask implements IInfoTask {
* 检查组合任务大小是否获取完成获取完成后取消阻塞并设置组合任务大小
*/
private void checkGetSizeComplete(int count, int failCount) {
if (isStop || isCancel){
if (isStop || isCancel) {
ALog.w(TAG, "任务已停止或已取消,isStop = " + isStop + ", isCancel = " + isCancel);
notifyLock();
return;

@ -26,6 +26,7 @@ import com.arialyy.aria.core.listener.DownloadGroupListener;
import com.arialyy.aria.core.loader.IInfoTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.exception.AriaException;
import com.arialyy.aria.exception.AriaHTTPException;
import java.io.File;
/**
@ -64,7 +65,17 @@ final class HttpDGLoader extends AbsGroupLoader {
@Override public void addComponent(IInfoTask infoTask) {
mInfoTask = infoTask;
mInfoTask.setCallback(new IInfoTask.Callback() {
mInfoTask.setCallback(new HttpDGInfoTask.DGInfoCallback() {
@Override
public void onSubFail(DownloadEntity subEntity, AriaHTTPException e, boolean needRetry) {
getState().countFailNum(subEntity.getKey());
}
@Override public void onStop(long len) {
getListener().onStop(len);
}
@Override public void onSucceed(String key, CompleteInfo info) {
startSub();
}

@ -38,8 +38,7 @@ public final class HttpDGLoaderUtil extends AbsGroupLoaderUtil {
@Override protected LoaderStructure buildLoaderStructure() {
LoaderStructure structure = new LoaderStructure();
structure.addComponent(new HttpDGInfoTask((DGTaskWrapper) getTaskWrapper(),
(DownloadGroupListener) getListener()));
structure.addComponent(new HttpDGInfoTask((DGTaskWrapper) getTaskWrapper()));
structure.accept(getLoader());
return structure;
}

@ -47,7 +47,6 @@ public final class GroupRunState {
* 停止的任务数
*/
private AtomicInteger mStopNum = new AtomicInteger();
;
/**
* 当前进度

@ -182,7 +182,7 @@ final class SimpleSchedulers implements Handler.Callback {
Log.d(TAG,
String.format("handleComplete, size = %s, completeNum = %s, failNum = %s, stopNum = %s",
mGState.getSubSize(), mGState.getCompleteNum(), mGState.getFailNum(),
mGState.getSubSize()));
mGState.getStopNum()));
TaskRecord record = loader.getRecord();
if (record != null && record.isBlock) {

@ -32,9 +32,9 @@ public class GroupModule extends BaseModule {
public List<String> getUrls() {
List<String> urls = new ArrayList<>();
urls.add("http://61.155.99.75:88/sdkdown.muzhiwan.com/openfile/2019/10/26/com.mrxz.mzw_5db3eeef782b1.apk");
urls.add("http://cpsdown.muzhiwan.com/2020/05/07/com.kaihei.wufan.mars_5eb3947b4341b.apk");
urls.add("http://113.143.35.118:88/sdkdown.muzhiwan.com/openfile/2019/11/27/com.droidhang.ad.mzw_5dde4ffe2b2e5.apk");
urls.add("http://storage.jd.com/apk/newchannel/jingdongdaojia-lechuang30.apk");
urls.add("https://appdownload.alicdn.com/publish/cainiao4android/latest/cainiao4android_1598322688221.apk");
urls.add("http://dl-tc.coolapkmarket.com/down/apk_file/2020/0927/Coolapk-10.5.3-2009271_sign.apk");
return urls;
}
List<String> getUrls1() {
@ -50,9 +50,9 @@ public class GroupModule extends BaseModule {
List<String> names = new ArrayList<>();
//String[] str = getContext().getResources().getStringArray(R.array.group_names);
//Collections.addAll(names, str);
names.add("末日血战.apk");
names.add("开黑三国.apk");
names.add("放置奇兵.apk");
names.add("京东到家.apk");
names.add("菜鸟.apk");
names.add("酷安.apk");
//names.add("4.png");
//names.add("5.png");
return names;

Loading…
Cancel
Save