修复上一个版本出现的网络未连接,没有失败回掉的问题,单线程任务线程将不再失败重试,添加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) {
|
if (mConfig.SUPPORT_BP) {
|
||||||
writeConfig(false, currentLocation);
|
writeConfig(false, currentLocation);
|
||||||
retryThis(true);
|
retryThis(STATE.THREAD_NUM != 1);
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
|
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
|
||||||
mListener.onFail(true);
|
mListener.onFail(true);
|
||||||
@@ -199,10 +199,10 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend
|
|||||||
*/
|
*/
|
||||||
private void retryThis(boolean needRetry) {
|
private void retryThis(boolean needRetry) {
|
||||||
if (!NetUtils.isConnected(AriaManager.APP)) {
|
if (!NetUtils.isConnected(AriaManager.APP)) {
|
||||||
Log.w(TAG, "重试线程失败,网络未连接");
|
Log.w(TAG,
|
||||||
return;
|
"任务【" + 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) {
|
if (mFailTimer != null) {
|
||||||
mFailTimer.purge();
|
mFailTimer.purge();
|
||||||
mFailTimer.cancel();
|
mFailTimer.cancel();
|
||||||
@@ -219,12 +219,14 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend
|
|||||||
}, RETRY_INTERVAL);
|
}, RETRY_INTERVAL);
|
||||||
} else {
|
} else {
|
||||||
STATE.FAIL_NUM++;
|
STATE.FAIL_NUM++;
|
||||||
|
if (STATE.isFail()) {
|
||||||
STATE.isRunning = false;
|
STATE.isRunning = false;
|
||||||
STATE.isStop = true;
|
STATE.isStop = true;
|
||||||
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
|
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
|
||||||
mListener.onFail(true);
|
mListener.onFail(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将记录写入到配置文件
|
* 将记录写入到配置文件
|
||||||
|
@@ -56,7 +56,7 @@ public class StateConstance {
|
|||||||
* 所有子线程是否都已经下载失败
|
* 所有子线程是否都已经下载失败
|
||||||
*/
|
*/
|
||||||
public boolean isFail() {
|
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>>
|
class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
|
||||||
implements IDownloadListener {
|
implements IDownloadListener {
|
||||||
protected WeakReference<Handler> outHandler;
|
protected WeakReference<Handler> outHandler;
|
||||||
|
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
|
||||||
private long mLastLen = 0; //上一次发送长度
|
private long mLastLen = 0; //上一次发送长度
|
||||||
private boolean isFirst = true;
|
private boolean isFirst = true;
|
||||||
protected ENTITY mEntity;
|
protected ENTITY mEntity;
|
||||||
protected TASK mTask;
|
protected TASK mTask;
|
||||||
private boolean isConvertSpeed = false;
|
private boolean isConvertSpeed = false;
|
||||||
boolean isWait = false;
|
boolean isWait = false;
|
||||||
|
private long mLastSaveTime;
|
||||||
|
|
||||||
BaseDListener(TASK task, Handler outHandler) {
|
BaseDListener(TASK task, Handler outHandler) {
|
||||||
this.outHandler = new WeakReference<>(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);
|
final AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||||
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
|
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
|
||||||
mLastLen = mEntity.getCurrentProgress();
|
mLastLen = mEntity.getCurrentProgress();
|
||||||
|
mLastSaveTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onPre() {
|
@Override public void onPre() {
|
||||||
@@ -82,6 +85,11 @@ class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
|
|||||||
}
|
}
|
||||||
handleSpeed(speed);
|
handleSpeed(speed);
|
||||||
sendInState2Target(ISchedulers.RUNNING);
|
sendInState2Target(ISchedulers.RUNNING);
|
||||||
|
if (System.currentTimeMillis() - mLastSaveTime >= RUN_SAVE_INTERVAL){
|
||||||
|
saveData(IEntity.STATE_RUNNING, currentLocation);
|
||||||
|
mLastSaveTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
mLastLen = currentLocation;
|
mLastLen = currentLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@ import com.arialyy.aria.core.inf.IDownloadListener;
|
|||||||
import com.arialyy.aria.core.inf.IEntity;
|
import com.arialyy.aria.core.inf.IEntity;
|
||||||
import com.arialyy.aria.orm.DbEntity;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
|
import com.arialyy.aria.util.NetUtils;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -405,7 +406,8 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
|
|
||||||
DownloadTaskEntity taskEntity;
|
DownloadTaskEntity taskEntity;
|
||||||
DownloadEntity entity;
|
DownloadEntity entity;
|
||||||
|
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
|
||||||
|
private long mLastSaveTime;
|
||||||
long lastLen = 0;
|
long lastLen = 0;
|
||||||
|
|
||||||
ChildDownloadListener(DownloadTaskEntity entity) {
|
ChildDownloadListener(DownloadTaskEntity entity) {
|
||||||
@@ -413,6 +415,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
this.entity = taskEntity.getEntity();
|
this.entity = taskEntity.getEntity();
|
||||||
lastLen = this.entity.getCurrentProgress();
|
lastLen = this.entity.getCurrentProgress();
|
||||||
this.entity.setFailNum(0);
|
this.entity.setFailNum(0);
|
||||||
|
mLastSaveTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onPre() {
|
@Override public void onPre() {
|
||||||
@@ -444,6 +447,10 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
entity.setCurrentProgress(currentLocation);
|
entity.setCurrentProgress(currentLocation);
|
||||||
handleSpeed(speed);
|
handleSpeed(speed);
|
||||||
mListener.onSubRunning(entity);
|
mListener.onSubRunning(entity);
|
||||||
|
if (System.currentTimeMillis() - mLastSaveTime >= RUN_SAVE_INTERVAL) {
|
||||||
|
saveData(IEntity.STATE_RUNNING, currentLocation);
|
||||||
|
mLastSaveTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
lastLen = currentLocation;
|
lastLen = currentLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,7 +498,8 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
*/
|
*/
|
||||||
private void reTry(boolean needRetry) {
|
private void reTry(boolean needRetry) {
|
||||||
synchronized (AriaManager.LOCK) {
|
synchronized (AriaManager.LOCK) {
|
||||||
if (entity.getFailNum() < 5 && isRunning && needRetry) {
|
if (entity.getFailNum() < 5 && isRunning && needRetry && NetUtils.isConnected(
|
||||||
|
AriaManager.APP)) {
|
||||||
reStartTask();
|
reStartTask();
|
||||||
} else {
|
} else {
|
||||||
mFailNum++;
|
mFailNum++;
|
||||||
|
@@ -19,10 +19,13 @@ import android.support.annotation.NonNull;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import com.arialyy.aria.core.AriaManager;
|
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.CancelCmd;
|
||||||
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
|
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
|
||||||
import com.arialyy.aria.core.common.RequestEnum;
|
import com.arialyy.aria.core.common.RequestEnum;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -199,6 +202,16 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
|||||||
.exe();
|
.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}如果任务已经完成,只删除任务数据库记录,
|
* {@code false}如果任务已经完成,只删除任务数据库记录,
|
||||||
*/
|
*/
|
||||||
public void cancel(boolean removeFile) {
|
public void cancel(boolean removeFile) {
|
||||||
CancelCmd cancelCmd =
|
CancelCmd cancelCmd = (CancelCmd) CommonUtil.createNormalCmd(mTargetName, mTaskEntity,
|
||||||
(CancelCmd) CommonUtil.createNormalCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CANCEL);
|
NormalCmdFactory.TASK_CANCEL);
|
||||||
cancelCmd.removeFile = removeFile;
|
cancelCmd.removeFile = removeFile;
|
||||||
AriaManager.getInstance(AriaManager.APP).setCmd(cancelCmd).exe();
|
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.UploadTask;
|
||||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||||
import com.arialyy.aria.util.CheckUtil;
|
import com.arialyy.aria.util.CheckUtil;
|
||||||
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,6 +40,7 @@ public abstract class AbsUploadTarget<TARGET extends AbsUploadTarget, ENTITY ext
|
|||||||
CheckUtil.checkDownloadUrl(uploadUrl);
|
CheckUtil.checkDownloadUrl(uploadUrl);
|
||||||
if (mEntity.getUrl().equals(uploadUrl)) return (TARGET) this;
|
if (mEntity.getUrl().equals(uploadUrl)) return (TARGET) this;
|
||||||
mEntity.setUrl(uploadUrl);
|
mEntity.setUrl(uploadUrl);
|
||||||
|
//mEntity.setUrl(CommonUtil.convertUrl(uploadUrl));
|
||||||
mEntity.update();
|
mEntity.update();
|
||||||
return (TARGET) this;
|
return (TARGET) this;
|
||||||
}
|
}
|
||||||
|
@@ -31,12 +31,14 @@ import java.lang.ref.WeakReference;
|
|||||||
class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
|
class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
|
||||||
implements IUploadListener {
|
implements IUploadListener {
|
||||||
private WeakReference<Handler> outHandler;
|
private WeakReference<Handler> outHandler;
|
||||||
|
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
|
||||||
private long mLastLen = 0; //上一次发送长度
|
private long mLastLen = 0; //上一次发送长度
|
||||||
private boolean isFirst = true;
|
private boolean isFirst = true;
|
||||||
protected ENTITY mEntity;
|
protected ENTITY mEntity;
|
||||||
protected TASK mTask;
|
protected TASK mTask;
|
||||||
private boolean isConvertSpeed = false;
|
private boolean isConvertSpeed = false;
|
||||||
boolean isWait = false;
|
boolean isWait = false;
|
||||||
|
private long mLastSaveTime;
|
||||||
|
|
||||||
BaseUListener(TASK task, Handler outHandler) {
|
BaseUListener(TASK task, Handler outHandler) {
|
||||||
this.outHandler = new WeakReference<>(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);
|
final AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||||
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
|
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
|
||||||
mLastLen = mEntity.getCurrentProgress();
|
mLastLen = mEntity.getCurrentProgress();
|
||||||
|
mLastSaveTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onPre() {
|
@Override public void onPre() {
|
||||||
@@ -71,6 +74,10 @@ class BaseUListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
|
|||||||
}
|
}
|
||||||
handleSpeed(speed);
|
handleSpeed(speed);
|
||||||
sendInState2Target(ISchedulers.RUNNING);
|
sendInState2Target(ISchedulers.RUNNING);
|
||||||
|
if (System.currentTimeMillis() - mLastSaveTime >= RUN_SAVE_INTERVAL) {
|
||||||
|
saveData(IEntity.STATE_RUNNING, currentLocation);
|
||||||
|
mLastSaveTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
mLastLen = currentLocation;
|
mLastLen = currentLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
## 开发日志
|
## 开发日志
|
||||||
|
+ v_3.3.2 新加reTry(),修复上一个版本不会回调失败事件的问题;增加running状态下5秒钟保存一次数据库的功能
|
||||||
|
+ v_3.3.1 增加网络事件,网络未连接,将不会重试下载,修复删除未开始任务,状态回调错误
|
||||||
+ v_3.3.0 增加任务组子任务暂停和开始控制功能、修复5.0系统以上数据库多生成两个字段的bug、去掉addSchedulerListener事件
|
+ v_3.3.0 增加任务组子任务暂停和开始控制功能、修复5.0系统以上数据库多生成两个字段的bug、去掉addSchedulerListener事件
|
||||||
+ v_3.2.26 修复任务组有时注解不起作用的问题
|
+ v_3.2.26 修复任务组有时注解不起作用的问题
|
||||||
+ v_3.2.25 修复删除任务组文件,记录无法删除的问题
|
+ v_3.2.25 修复删除任务组文件,记录无法删除的问题
|
||||||
|
@@ -44,7 +44,7 @@
|
|||||||
<maxTaskNum value="2"/>
|
<maxTaskNum value="2"/>
|
||||||
|
|
||||||
<!--设置上传失败,重试次数,默认为10-->
|
<!--设置上传失败,重试次数,默认为10-->
|
||||||
<reTryNum value="10"/>
|
<reTryNum value="2"/>
|
||||||
|
|
||||||
<!--设置重试间隔,单位为毫秒-->
|
<!--设置重试间隔,单位为毫秒-->
|
||||||
<reTryInterval value="2000"/>
|
<reTryInterval value="2000"/>
|
||||||
|
@@ -35,7 +35,7 @@ import java.io.File;
|
|||||||
* Ftp下载测试
|
* Ftp下载测试
|
||||||
*/
|
*/
|
||||||
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
|
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
|
||||||
private final String URL = "ftp://192.168.8.2:21/test.apk";
|
private final String URL = "ftp://172.18.104.147:21/haha/ftp_test.apk";
|
||||||
|
|
||||||
@Override protected void init(Bundle savedInstanceState) {
|
@Override protected void init(Bundle savedInstanceState) {
|
||||||
super.init(savedInstanceState);
|
super.init(savedInstanceState);
|
||||||
|
@@ -46,8 +46,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
private static final String DOWNLOAD_URL =
|
private static final String DOWNLOAD_URL =
|
||||||
//"http://kotlinlang.org/docs/kotlin-docs.pdf";
|
//"http://kotlinlang.org/docs/kotlin-docs.pdf";
|
||||||
//"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe";
|
//"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe";
|
||||||
//"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||||
"http://sitcac.daxincf.cn/wp-content/uploads/swift_vido/01/element.mp4_1";
|
//"http://sitcac.daxincf.cn/wp-content/uploads/swift_vido/01/element.mp4_1";
|
||||||
//"http://120.25.196.56:8000/filereq?id=15692406294&ipncid=105635&client=android&filename=20170819185541.avi";
|
//"http://120.25.196.56:8000/filereq?id=15692406294&ipncid=105635&client=android&filename=20170819185541.avi";
|
||||||
//"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt";
|
//"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt";
|
||||||
//"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815";
|
//"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815";
|
||||||
|
@@ -34,8 +34,8 @@ import com.arialyy.simple.databinding.ActivityFtpUploadBinding;
|
|||||||
* Ftp 文件上传demo
|
* Ftp 文件上传demo
|
||||||
*/
|
*/
|
||||||
public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
|
public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
|
||||||
private final String FILE_PATH = "/mnt/sdcard/Download/group_test_3/战斗吧剑灵.apk";
|
private final String FILE_PATH = "/mnt/sdcard/成都.mp3";
|
||||||
private final String URL = "ftp://172.18.104.66:21/upload/";
|
private final String URL = "ftp://172.18.104.229:21/upload/测试";
|
||||||
|
|
||||||
@Override protected void init(Bundle savedInstanceState) {
|
@Override protected void init(Bundle savedInstanceState) {
|
||||||
setTile("FTP 文件上传");
|
setTile("FTP 文件上传");
|
||||||
|
Reference in New Issue
Block a user