修复上一个版本出现的网络未连接,没有失败回掉的问题,单线程任务线程将不再失败重试,添加retry(),任务running状态下,5s钟保存一次状态
This commit is contained in:
@@ -180,7 +180,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend
|
||||
}
|
||||
if (mConfig.SUPPORT_BP) {
|
||||
writeConfig(false, currentLocation);
|
||||
retryThis(true);
|
||||
retryThis(STATE.THREAD_NUM != 1);
|
||||
} else {
|
||||
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
|
||||
mListener.onFail(true);
|
||||
@@ -198,11 +198,11 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend
|
||||
* @param needRetry 是否可以重试
|
||||
*/
|
||||
private void retryThis(boolean needRetry) {
|
||||
if (!NetUtils.isConnected(AriaManager.APP)){
|
||||
Log.w(TAG, "重试线程失败,网络未连接");
|
||||
return;
|
||||
if (!NetUtils.isConnected(AriaManager.APP)) {
|
||||
Log.w(TAG,
|
||||
"任务【" + mConfig.TEMP_FILE.getName() + "】thread__" + mConfig.THREAD_ID + "__重试失败,网络未连接");
|
||||
}
|
||||
if (mFailNum < RETRY_NUM && needRetry) {
|
||||
if (mFailNum < RETRY_NUM && needRetry && NetUtils.isConnected(AriaManager.APP)) {
|
||||
if (mFailTimer != null) {
|
||||
mFailTimer.purge();
|
||||
mFailTimer.cancel();
|
||||
@@ -219,10 +219,12 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend
|
||||
}, RETRY_INTERVAL);
|
||||
} else {
|
||||
STATE.FAIL_NUM++;
|
||||
STATE.isRunning = false;
|
||||
STATE.isStop = true;
|
||||
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
|
||||
mListener.onFail(true);
|
||||
if (STATE.isFail()) {
|
||||
STATE.isRunning = false;
|
||||
STATE.isStop = true;
|
||||
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
|
||||
mListener.onFail(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -56,7 +56,7 @@ public class StateConstance {
|
||||
* 所有子线程是否都已经下载失败
|
||||
*/
|
||||
public boolean isFail() {
|
||||
return FAIL_NUM == THREAD_NUM;
|
||||
return FAIL_NUM + COMPLETE_THREAD_NUM >= THREAD_NUM;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -31,12 +31,14 @@ import java.lang.ref.WeakReference;
|
||||
class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
|
||||
implements IDownloadListener {
|
||||
protected WeakReference<Handler> outHandler;
|
||||
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
|
||||
private long mLastLen = 0; //上一次发送长度
|
||||
private boolean isFirst = true;
|
||||
protected ENTITY mEntity;
|
||||
protected TASK mTask;
|
||||
private boolean isConvertSpeed = false;
|
||||
boolean isWait = false;
|
||||
private long mLastSaveTime;
|
||||
|
||||
BaseDListener(TASK task, Handler outHandler) {
|
||||
this.outHandler = new WeakReference<>(outHandler);
|
||||
@@ -45,6 +47,7 @@ class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
|
||||
final AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
|
||||
mLastLen = mEntity.getCurrentProgress();
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override public void onPre() {
|
||||
@@ -82,6 +85,11 @@ class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
|
||||
}
|
||||
handleSpeed(speed);
|
||||
sendInState2Target(ISchedulers.RUNNING);
|
||||
if (System.currentTimeMillis() - mLastSaveTime >= RUN_SAVE_INTERVAL){
|
||||
saveData(IEntity.STATE_RUNNING, currentLocation);
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
mLastLen = currentLocation;
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,7 @@ import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.NetUtils;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -405,7 +406,8 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
|
||||
DownloadTaskEntity taskEntity;
|
||||
DownloadEntity entity;
|
||||
|
||||
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
|
||||
private long mLastSaveTime;
|
||||
long lastLen = 0;
|
||||
|
||||
ChildDownloadListener(DownloadTaskEntity entity) {
|
||||
@@ -413,6 +415,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
this.entity = taskEntity.getEntity();
|
||||
lastLen = this.entity.getCurrentProgress();
|
||||
this.entity.setFailNum(0);
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override public void onPre() {
|
||||
@@ -444,6 +447,10 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
entity.setCurrentProgress(currentLocation);
|
||||
handleSpeed(speed);
|
||||
mListener.onSubRunning(entity);
|
||||
if (System.currentTimeMillis() - mLastSaveTime >= RUN_SAVE_INTERVAL) {
|
||||
saveData(IEntity.STATE_RUNNING, currentLocation);
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
}
|
||||
lastLen = currentLocation;
|
||||
}
|
||||
|
||||
@@ -491,7 +498,8 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
*/
|
||||
private void reTry(boolean needRetry) {
|
||||
synchronized (AriaManager.LOCK) {
|
||||
if (entity.getFailNum() < 5 && isRunning && needRetry) {
|
||||
if (entity.getFailNum() < 5 && isRunning && needRetry && NetUtils.isConnected(
|
||||
AriaManager.APP)) {
|
||||
reStartTask();
|
||||
} else {
|
||||
mFailNum++;
|
||||
|
@@ -19,10 +19,13 @@ import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.command.ICmd;
|
||||
import com.arialyy.aria.core.command.normal.CancelCmd;
|
||||
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -199,6 +202,16 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
.exe();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重试下载
|
||||
*/
|
||||
public void reTry() {
|
||||
List<ICmd> cmds = new ArrayList<>();
|
||||
cmds.add(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_STOP));
|
||||
cmds.add(CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START));
|
||||
AriaManager.getInstance(AriaManager.APP).setCmds(cmds).exe();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务
|
||||
*
|
||||
@@ -206,8 +219,8 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
* {@code false}如果任务已经完成,只删除任务数据库记录,
|
||||
*/
|
||||
public void cancel(boolean removeFile) {
|
||||
CancelCmd cancelCmd =
|
||||
(CancelCmd) CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CANCEL);
|
||||
CancelCmd cancelCmd = (CancelCmd) CommonUtil.createNormalCmd(mTargetName, mTaskEntity,
|
||||
NormalCmdFactory.TASK_CANCEL);
|
||||
cancelCmd.removeFile = removeFile;
|
||||
AriaManager.getInstance(AriaManager.APP).setCmd(cancelCmd).exe();
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.core.upload.UploadTask;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@@ -39,6 +40,7 @@ public abstract class AbsUploadTarget<TARGET extends AbsUploadTarget, ENTITY ext
|
||||
CheckUtil.checkDownloadUrl(uploadUrl);
|
||||
if (mEntity.getUrl().equals(uploadUrl)) return (TARGET) this;
|
||||
mEntity.setUrl(uploadUrl);
|
||||
//mEntity.setUrl(CommonUtil.convertUrl(uploadUrl));
|
||||
mEntity.update();
|
||||
return (TARGET) this;
|
||||
}
|
||||
|
@@ -31,12 +31,14 @@ import java.lang.ref.WeakReference;
|
||||
class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
|
||||
implements IUploadListener {
|
||||
private WeakReference<Handler> outHandler;
|
||||
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
|
||||
private long mLastLen = 0; //上一次发送长度
|
||||
private boolean isFirst = true;
|
||||
protected ENTITY mEntity;
|
||||
protected TASK mTask;
|
||||
private boolean isConvertSpeed = false;
|
||||
boolean isWait = false;
|
||||
private long mLastSaveTime;
|
||||
|
||||
BaseUListener(TASK task, Handler outHandler) {
|
||||
this.outHandler = new WeakReference<>(outHandler);
|
||||
@@ -45,6 +47,7 @@ class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
|
||||
final AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
|
||||
mLastLen = mEntity.getCurrentProgress();
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override public void onPre() {
|
||||
@@ -71,6 +74,10 @@ class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
|
||||
}
|
||||
handleSpeed(speed);
|
||||
sendInState2Target(ISchedulers.RUNNING);
|
||||
if (System.currentTimeMillis() - mLastSaveTime >= RUN_SAVE_INTERVAL) {
|
||||
saveData(IEntity.STATE_RUNNING, currentLocation);
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
}
|
||||
mLastLen = currentLocation;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user