Skip to content

Commit

Permalink
Merge pull request #633 from DaveBoy/aria
Browse files Browse the repository at this point in the history
组合下载子任务失败Exception为空,单个任务下载失败后最终组任务回调stop/fail开关设置
  • Loading branch information
AriaLyy committed Mar 13, 2020
2 parents de09add + a65b2e3 commit cd31276
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
Expand Up @@ -31,6 +31,11 @@ public class DGroupConfig extends BaseTaskConfig implements Serializable {
*/
int subMaxTaskNum = 3;

/**
* 子任务失败时回调stop,默认true
*/
private boolean subFailAsStop = true;

/**
* 子任务重试次数,默认为5
*/
Expand Down Expand Up @@ -118,4 +123,14 @@ public DGroupConfig setSubReTryInterval(int subReTryInterval) {
save();
return this;
}

public boolean isSubFailAsStop() {
return subFailAsStop;
}

public DGroupConfig setSubFailAsStop(boolean subFailAsStop) {
this.subFailAsStop = subFailAsStop;
save();
return this;
}
}
Expand Up @@ -144,6 +144,10 @@ public void startElement(String uri, String localName, String qName, Attributes
int subMaxTaskNum = checkInt(value) ? Integer.parseInt(value) : 3;
setField("subMaxTaskNum", subMaxTaskNum, ConfigType.D_GROUP);
break;
case "subFailAsStop": // 子任务失败时回调stop
setField("subFailAsStop", checkBoolean(value) ? Boolean.valueOf(value) : false,
ConfigType.D_GROUP);
break;
case "subReTryNum": // 子任务重试次数
int subReTryNum = checkInt(value) ? Integer.parseInt(value) : 5;
setField("subReTryNum", subReTryNum, ConfigType.D_GROUP);
Expand Down
Expand Up @@ -184,6 +184,9 @@ private synchronized void handleComplete(AbsSubDLoadUtil loader) {
== mGState.getSubSize()) {
if (mGState.getStopNum() == 0 && mGState.getFailNum() == 0) {
mGState.listener.onComplete();
} else if(mGState.getStopNum() == 0&&!Configuration.getInstance().dGroupCfg.isSubFailAsStop() ){
mGState.listener.onFail(false, new AriaException(TAG,
String.format("任务组【%s】下载失败", mGState.getGroupHash())));
} else {
mGState.listener.onStop(mGState.getProgress());
}
Expand Down
Expand Up @@ -30,6 +30,8 @@
import com.arialyy.aria.util.ErrorHelp;
import com.arialyy.aria.util.RecordUtil;

import static com.arialyy.aria.core.task.AbsTask.ERROR_INFO_KEY;

/**
* Created by Aria.Lao on 2017/7/20. 任务组下载事件
*/
Expand Down Expand Up @@ -85,6 +87,7 @@ public void onSubFail(DownloadEntity subEntity, AriaException e) {
handleSubSpeed(subEntity, 0);
saveSubState(IEntity.STATE_FAIL, subEntity);
saveCurrentLocation();
mSeedEntity.groupTask.putExpand(ERROR_INFO_KEY,e);
sendInState2Target(ISchedulers.SUB_FAIL, subEntity);
if (e != null) {
e.printStackTrace();
Expand Down
Expand Up @@ -107,8 +107,8 @@ public static List<DownloadEntity> createHttpSubTask(String groupHash, List<Stri
int lastIndex = url.lastIndexOf(File.separator);
//去除url末尾携带的的参数
int endIndex = url.lastIndexOf("?");
if(endIndex<0)endIndex=url.length();

if(endIndex<0||endIndex<lastIndex)endIndex=url.length();
entity.setFileName(url.substring(lastIndex + 1,endIndex));
entity.setGroupHash(groupHash);
entity.setGroupChild(true);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/assets/aria_config.xml
Expand Up @@ -126,7 +126,8 @@

<!--进度更新更新间隔,默认1000毫秒-->
<updateInterval value="1000"/>

<!--子任务失败时组任务回调stop,默认true false将回调fail-->
<subFailAsStop value="true"/>

<!-- =============================以下为子任务的配置====================================-->

Expand Down

0 comments on commit cd31276

Please sign in to comment.