添加没有网络也会重试的开关;修复多次删除记录的bug
This commit is contained in:
@@ -77,8 +77,8 @@ import org.xml.sax.SAXException;
|
||||
private Configuration.AppConfig mAConfig;
|
||||
|
||||
private AriaManager(Context context) {
|
||||
DelegateWrapper.init(context.getApplicationContext());
|
||||
APP = context.getApplicationContext();
|
||||
initDb(APP);
|
||||
regAppLifeCallback(context);
|
||||
initConfig();
|
||||
initAria();
|
||||
@@ -100,6 +100,20 @@ import org.xml.sax.SAXException;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private void initDb(Context context) {
|
||||
String dbBase = context.getFilesDir().getPath() + context.getPackageName() + "/databases/";
|
||||
File db = new File(dbBase + "AriaLyyDb");
|
||||
File dbConfig = new File(dbBase + "AriaLyyDb-journal");
|
||||
if (db.exists()) {
|
||||
db.renameTo(new File(dbBase + "AndroidAria.db"));
|
||||
// 如果数据库是在/data/data/{packagename}/databases/下面,journal文件因权限问题将无法删除和重命名
|
||||
if (dbConfig.exists()) {
|
||||
dbConfig.delete();
|
||||
}
|
||||
}
|
||||
DelegateWrapper.init(context.getApplicationContext());
|
||||
}
|
||||
|
||||
private void initAria() {
|
||||
if (mAConfig.getUseAriaCrashHandler()) {
|
||||
Thread.setDefaultUncaughtExceptionHandler(new AriaCrashHandler());
|
||||
|
||||
@@ -97,6 +97,9 @@ class ConfigHelper extends DefaultHandler {
|
||||
case "updateInterval":
|
||||
loadUpdateInterval(value);
|
||||
break;
|
||||
case "notNetRetry":
|
||||
loadNotNetRetry(value);
|
||||
break;
|
||||
}
|
||||
} else if (isAppConfig) {
|
||||
String value = attributes.getValue("value");
|
||||
@@ -111,6 +114,15 @@ class ConfigHelper extends DefaultHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadNotNetRetry(String value) {
|
||||
if (isDownloadConfig) {
|
||||
mDownloadConfig.notNetRetry = checkBoolean(value) ? Boolean.valueOf(value) : false;
|
||||
}
|
||||
if (isUploadConfig) {
|
||||
mUploadConfig.notNetRetry = checkBoolean(value) ? Boolean.valueOf(value) : false;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadLogLevel(String value) {
|
||||
int level;
|
||||
try {
|
||||
@@ -210,6 +222,10 @@ class ConfigHelper extends DefaultHandler {
|
||||
if (isDownloadConfig) {
|
||||
mDownloadConfig.buffSize = buffSize;
|
||||
}
|
||||
|
||||
if (isUploadConfig){
|
||||
mUploadConfig.buffSize = buffSize;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadIOTimeout(String value) {
|
||||
@@ -222,6 +238,10 @@ class ConfigHelper extends DefaultHandler {
|
||||
if (isDownloadConfig) {
|
||||
mDownloadConfig.iOTimeOut = time;
|
||||
}
|
||||
|
||||
if (isUploadConfig) {
|
||||
mUploadConfig.iOTimeOut = time;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConnectTime(String value) {
|
||||
|
||||
@@ -118,7 +118,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
mStartThreadNum = 1;
|
||||
handleNoSupportBP();
|
||||
} else {
|
||||
// TODO: 2018/5/11 如果不是新任务,就有问题
|
||||
mTotalThreadNum =
|
||||
mTaskEntity.isNewTask() ? (mStartThreadNum = setNewTaskThreadNum()) : mTotalThreadNum;
|
||||
handleBreakpoint();
|
||||
@@ -200,7 +199,6 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
CommonUtil.delTaskRecord(mRecord, mTaskEntity.isRemoveFile(), mTaskEntity.getEntity());
|
||||
}
|
||||
|
||||
@Override public void stop() {
|
||||
@@ -254,6 +252,10 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
if (mRecord.threadRecords == null || mRecord.threadRecords.isEmpty()) {
|
||||
initRecord();
|
||||
mTaskEntity.setNewTask(true);
|
||||
} else if (mTempFile.length() == 0) {
|
||||
mRecord.deleteData();
|
||||
initRecord();
|
||||
mTaskEntity.setNewTask(true);
|
||||
} else {
|
||||
for (ThreadRecord tr : mRecord.threadRecords) {
|
||||
if (tr.isComplete) {
|
||||
@@ -263,6 +265,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
}
|
||||
}
|
||||
mTotalThreadNum = mRecord.threadRecords.size();
|
||||
mTaskEntity.setNewTask(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,8 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTI
|
||||
charSet = mTaskEntity.getCharSet();
|
||||
}
|
||||
client.setControlEncoding(charSet);
|
||||
client.setDataTimeout(10 * 1000);
|
||||
client.setDataTimeout(mReadTimeOut);
|
||||
client.setConnectTimeout(mConnectTimeOut);
|
||||
client.enterLocalPassiveMode();
|
||||
client.setFileType(FTP.BINARY_FILE_TYPE);
|
||||
client.setControlKeepAliveTimeout(5000);
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.ErrorHelp;
|
||||
import com.arialyy.aria.util.NetUtils;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Timer;
|
||||
@@ -59,6 +58,10 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
||||
private Timer mFailTimer;
|
||||
private long mLastSaveTime;
|
||||
private ExecutorService mConfigThreadPool;
|
||||
protected int mConnectTimeOut; //连接超时时间
|
||||
protected int mReadTimeOut; //流读取的超时时间
|
||||
protected boolean isNotNetRetry = false; //断网情况是否重试
|
||||
|
||||
private Thread mConfigThread = new Thread(new Runnable() {
|
||||
@Override public void run() {
|
||||
final long currentTemp = mChildCurrentLocation;
|
||||
@@ -72,16 +75,11 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
||||
|
||||
protected AbsThreadTask(StateConstance constance, IEventListener listener,
|
||||
SubThreadConfig<TASK_ENTITY> info) {
|
||||
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||
STATE = constance;
|
||||
STATE.CONNECT_TIME_OUT = manager.getDownloadConfig().getConnectTimeOut();
|
||||
STATE.READ_TIME_OUT = manager.getDownloadConfig().getIOTimeOut();
|
||||
mListener = listener;
|
||||
mConfig = info;
|
||||
mTaskEntity = mConfig.TASK_ENTITY;
|
||||
mEntity = mTaskEntity.getEntity();
|
||||
mBufSize = manager.getDownloadConfig().getBuffSize();
|
||||
setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxSpeed());
|
||||
mTaskType = getTaskType();
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
mConfigThreadPool = Executors.newCachedThreadPool();
|
||||
@@ -219,13 +217,14 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
||||
mFailTimer.purge();
|
||||
mFailTimer.cancel();
|
||||
}
|
||||
if (!NetUtils.isConnected(AriaManager.APP)) {
|
||||
if (!NetUtils.isConnected(AriaManager.APP) && !isNotNetRetry) {
|
||||
ALog.w(TAG,
|
||||
"任务【" + mConfig.TEMP_FILE.getName() + "】thread__" + mConfig.THREAD_ID + "__重试失败,网络未连接");
|
||||
}
|
||||
if (mFailNum < RETRY_NUM
|
||||
&& needRetry
|
||||
&& NetUtils.isConnected(AriaManager.APP)
|
||||
&& !isNotNetRetry
|
||||
&& !STATE.isCancel
|
||||
&& !STATE.isStop) {
|
||||
mFailTimer = new Timer(true);
|
||||
@@ -258,7 +257,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
||||
if (mConfig.THREAD_RECORD != null) {
|
||||
mConfig.THREAD_RECORD.isComplete = isComplete;
|
||||
if (0 < record && record < mConfig.END_LOCATION) {
|
||||
mConfig.START_LOCATION = record;
|
||||
mConfig.THREAD_RECORD.startLocation = record;
|
||||
}
|
||||
mConfig.THREAD_RECORD.update();
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@ public class StateConstance {
|
||||
public int CANCEL_NUM = 0;
|
||||
public int STOP_NUM = 0;
|
||||
public int FAIL_NUM = 0;
|
||||
public int CONNECT_TIME_OUT; //连接超时时间
|
||||
public int READ_TIME_OUT; //流读取的超时时间
|
||||
public int COMPLETE_THREAD_NUM = 0;
|
||||
public int START_THREAD_NUM; //启动的线程数
|
||||
public long CURRENT_LOCATION = 0;
|
||||
|
||||
@@ -17,12 +17,16 @@ package com.arialyy.aria.core.download;
|
||||
|
||||
import android.os.Handler;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.TaskRecord;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsGroupEntity;
|
||||
import com.arialyy.aria.core.inf.AbsNormalEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulers;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
@@ -154,7 +158,16 @@ class BaseDListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
|
||||
mEntity.setState(state);
|
||||
mEntity.setComplete(state == IEntity.STATE_COMPLETE);
|
||||
if (state == IEntity.STATE_CANCEL) {
|
||||
mEntity.deleteData();
|
||||
if (mEntity instanceof AbsNormalEntity) {
|
||||
TaskRecord record =
|
||||
DbEntity.findFirst(TaskRecord.class, "TaskRecord.filePath=?", mTaskEntity.getKey());
|
||||
if (record != null) {
|
||||
CommonUtil.delTaskRecord(record, mTaskEntity.isRemoveFile(), (AbsNormalEntity) mEntity);
|
||||
}
|
||||
} else if (mEntity instanceof AbsGroupEntity) {
|
||||
CommonUtil.delGroupTaskRecord(mTaskEntity.isRemoveFile(), ((AbsGroupEntity) mEntity));
|
||||
}
|
||||
//mEntity.deleteData();
|
||||
return;
|
||||
} else if (mEntity.isComplete()) {
|
||||
mEntity.setCompleteTime(System.currentTimeMillis());
|
||||
|
||||
@@ -137,10 +137,11 @@ public class DownloadTask extends AbsNormalTask<DownloadTaskEntity> {
|
||||
* 取消下载
|
||||
*/
|
||||
@Override public void cancel() {
|
||||
if (!mUtil.isRunning()) {
|
||||
if (mUtil.isRunning()) {
|
||||
mUtil.cancel();
|
||||
} else {
|
||||
mListener.onCancel();
|
||||
}
|
||||
mUtil.cancel();
|
||||
}
|
||||
|
||||
@Override public String getTaskName() {
|
||||
|
||||
@@ -234,7 +234,6 @@ public abstract class AbsGroupUtil implements IUtil {
|
||||
}
|
||||
}
|
||||
clearState();
|
||||
CommonUtil.delGroupTaskRecord(mGTEntity.isRemoveFile(), mGTEntity.getEntity());
|
||||
mListener.onCancel();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.BufferedRandomAccessFile;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@@ -40,6 +39,7 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
||||
|
||||
Downloader(IDownloadListener listener, DownloadTaskEntity taskEntity) {
|
||||
super(listener, taskEntity);
|
||||
mTempFile = new File(mEntity.getDownloadPath());
|
||||
setUpdateInterval(
|
||||
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getUpdateInterval());
|
||||
}
|
||||
@@ -51,13 +51,6 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
||||
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum();
|
||||
}
|
||||
|
||||
@Override protected void checkTask() {
|
||||
super.checkTask();
|
||||
mTempFile = new File(mEntity.getDownloadPath());
|
||||
mTaskEntity.setNewTask(!mTempFile.exists()
|
||||
|| DbEntity.findFirst(DownloadEntity.class, "url=?", mEntity.getUrl()) == null);
|
||||
}
|
||||
|
||||
@Override protected boolean handleNewTask() {
|
||||
CommonUtil.createFile(mTempFile.getPath());
|
||||
BufferedRandomAccessFile file = null;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.download.downloader;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.AbsFtpThreadTask;
|
||||
import com.arialyy.aria.core.common.StateConstance;
|
||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
@@ -38,6 +39,12 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
|
||||
FtpThreadTask(StateConstance constance, IDownloadListener listener,
|
||||
SubThreadConfig<DownloadTaskEntity> downloadInfo) {
|
||||
super(constance, listener, downloadInfo);
|
||||
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||
mConnectTimeOut = manager.getDownloadConfig().getConnectTimeOut();
|
||||
mReadTimeOut = manager.getDownloadConfig().getIOTimeOut();
|
||||
mBufSize = manager.getDownloadConfig().getBuffSize();
|
||||
isNotNetRetry = manager.getDownloadConfig().isNotNetRetry();
|
||||
setMaxSpeed(manager.getDownloadConfig().getMaxSpeed());
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.download.downloader;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.AbsThreadTask;
|
||||
import com.arialyy.aria.core.common.StateConstance;
|
||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
@@ -42,6 +43,12 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
||||
HttpThreadTask(StateConstance constance, IDownloadListener listener,
|
||||
SubThreadConfig<DownloadTaskEntity> downloadInfo) {
|
||||
super(constance, listener, downloadInfo);
|
||||
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||
mConnectTimeOut = manager.getDownloadConfig().getConnectTimeOut();
|
||||
mReadTimeOut = manager.getDownloadConfig().getIOTimeOut();
|
||||
mBufSize = manager.getDownloadConfig().getBuffSize();
|
||||
isNotNetRetry = manager.getDownloadConfig().isNotNetRetry();
|
||||
setMaxSpeed(manager.getDownloadConfig().getMaxSpeed());
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
@@ -70,8 +77,8 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
||||
ALog.w(TAG, "该下载不支持断点");
|
||||
}
|
||||
conn = ConnectionHelp.setConnectParam(mConfig.TASK_ENTITY, conn);
|
||||
conn.setConnectTimeout(STATE.CONNECT_TIME_OUT);
|
||||
conn.setReadTimeout(STATE.READ_TIME_OUT); //设置读取流的等待时间,必须设置该参数
|
||||
conn.setConnectTimeout(mConnectTimeOut);
|
||||
conn.setReadTimeout(mReadTimeOut); //设置读取流的等待时间,必须设置该参数
|
||||
|
||||
is = new BufferedInputStream(ConnectionHelp.convertInputStream(conn));
|
||||
//创建可设置位置的文件
|
||||
@@ -117,7 +124,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
||||
*
|
||||
* @deprecated 暂时先这样处理,无chun
|
||||
*/
|
||||
private void readChunk(InputStream is, RandomAccessFile file)
|
||||
private void readChunk(InputStream is, BufferedRandomAccessFile file)
|
||||
throws IOException, InterruptedException {
|
||||
readNormal(is, file);
|
||||
}
|
||||
@@ -125,7 +132,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
||||
/**
|
||||
* 读取普通的文件流
|
||||
*/
|
||||
private void readNormal(InputStream is, RandomAccessFile file)
|
||||
private void readNormal(InputStream is, BufferedRandomAccessFile file)
|
||||
throws IOException, InterruptedException {
|
||||
byte[] buffer = new byte[mBufSize];
|
||||
int len;
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.arialyy.aria.core.common.OnFileInfoCallback;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.util.ErrorHelp;
|
||||
|
||||
/**
|
||||
@@ -93,7 +94,8 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
|
||||
mListener.onPre();
|
||||
if (mTaskEntity.getEntity().getFileSize() <= 1
|
||||
|| mTaskEntity.isRefreshInfo()
|
||||
|| mTaskEntity.getRequestType() == AbsTaskEntity.D_FTP) {
|
||||
|| mTaskEntity.getRequestType() == AbsTaskEntity.D_FTP
|
||||
|| mTaskEntity.getState() == IEntity.STATE_FAIL) {
|
||||
new Thread(createInfoThread()).start();
|
||||
} else {
|
||||
mDownloader.start();
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
package com.arialyy.aria.core.queue;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.queue.pool.BaseCachePool;
|
||||
import com.arialyy.aria.core.queue.pool.BaseExecutePool;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.NetUtils;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/2/23.
|
||||
@@ -195,10 +193,10 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
|
||||
ALog.e(TAG, "任务重试失败,原因:task 为null");
|
||||
return;
|
||||
}
|
||||
if (!NetUtils.isConnected(AriaManager.APP)) {
|
||||
ALog.e(TAG, "任务【" + task.getTaskName() + "】重试失败,原因:网络未连接");
|
||||
return;
|
||||
}
|
||||
//if (!NetUtils.isConnected(AriaManager.APP)) {
|
||||
// ALog.e(TAG, "任务【" + task.getTaskName() + "】重试失败,原因:网络未连接");
|
||||
// return;
|
||||
//}
|
||||
if (!task.isRunning()) {
|
||||
task.start();
|
||||
} else {
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.core.queue.ITaskQueue;
|
||||
import com.arialyy.aria.core.upload.UploadTask;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.NetUtils;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -181,7 +182,9 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
|
||||
if (what == CANCEL || what == COMPLETE) {
|
||||
TEManager.getInstance().removeTEntity(task.getKey());
|
||||
} else {
|
||||
TEManager.getInstance().putTEntity(task.getKey(), task.getTaskEntity());
|
||||
if (what != RUNNING) {
|
||||
TEManager.getInstance().putTEntity(task.getKey(), task.getTaskEntity());
|
||||
}
|
||||
}
|
||||
if (what != FAIL) {
|
||||
callback(what, task);
|
||||
@@ -260,16 +263,21 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
|
||||
}
|
||||
long interval = 2000;
|
||||
int num = 10;
|
||||
boolean isNotNetRetry = false;
|
||||
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||
if (task instanceof DownloadTask || task instanceof DownloadGroupTask) {
|
||||
interval = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getReTryInterval();
|
||||
num = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getReTryNum();
|
||||
interval = manager.getDownloadConfig().getReTryInterval();
|
||||
num = manager.getDownloadConfig().getReTryNum();
|
||||
isNotNetRetry = manager.getDownloadConfig().isNotNetRetry();
|
||||
} else if (task instanceof UploadTask) {
|
||||
interval = AriaManager.getInstance(AriaManager.APP).getUploadConfig().getReTryInterval();
|
||||
num = AriaManager.getInstance(AriaManager.APP).getUploadConfig().getReTryNum();
|
||||
interval = manager.getUploadConfig().getReTryInterval();
|
||||
num = manager.getUploadConfig().getReTryNum();
|
||||
isNotNetRetry = manager.getUploadConfig().isNotNetRetry();
|
||||
}
|
||||
|
||||
final int reTryNum = num;
|
||||
if (task.getTaskEntity().getEntity().getFailNum() > reTryNum) {
|
||||
if ((!NetUtils.isConnected(AriaManager.APP) && !isNotNetRetry)
|
||||
|| task.getTaskEntity().getEntity().getFailNum() > reTryNum) {
|
||||
callback(FAIL, task);
|
||||
mQueue.removeTaskFormQueue(task.getKey());
|
||||
startNextTask();
|
||||
@@ -284,6 +292,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
|
||||
@Override public void onFinish() {
|
||||
AbsEntity entity = task.getTaskEntity().getEntity();
|
||||
if (entity.getFailNum() <= reTryNum) {
|
||||
ALog.d(TAG, "任务【" + task.getTaskName() + "】开始重试");
|
||||
TASK task = mQueue.getTask(entity.getKey());
|
||||
mQueue.reTryStart(task);
|
||||
} else {
|
||||
|
||||
@@ -17,12 +17,16 @@ package com.arialyy.aria.core.upload;
|
||||
|
||||
import android.os.Handler;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.TaskRecord;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsGroupEntity;
|
||||
import com.arialyy.aria.core.inf.AbsNormalEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.inf.IUploadListener;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulers;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
@@ -140,7 +144,15 @@ class BaseUListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<
|
||||
mEntity.setState(state);
|
||||
mEntity.setComplete(state == IEntity.STATE_COMPLETE);
|
||||
if (state == IEntity.STATE_CANCEL) {
|
||||
mEntity.deleteData();
|
||||
if (mEntity instanceof AbsNormalEntity) {
|
||||
TaskRecord record =
|
||||
DbEntity.findFirst(TaskRecord.class, "TaskRecord.filePath=?", mTaskEntity.getKey());
|
||||
if (record != null) {
|
||||
CommonUtil.delTaskRecord(record, mTaskEntity.isRemoveFile(), (AbsNormalEntity) mEntity);
|
||||
}
|
||||
} else if (mEntity instanceof AbsGroupEntity) {
|
||||
CommonUtil.delGroupTaskRecord(mTaskEntity.isRemoveFile(), ((AbsGroupEntity) mEntity));
|
||||
}
|
||||
return;
|
||||
} else if (mEntity.isComplete()) {
|
||||
mEntity.setCompleteTime(System.currentTimeMillis());
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.upload.uploader;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.AbsFtpThreadTask;
|
||||
import com.arialyy.aria.core.common.StateConstance;
|
||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
@@ -40,6 +41,11 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
|
||||
FtpThreadTask(StateConstance constance, IEventListener listener,
|
||||
SubThreadConfig<UploadTaskEntity> info) {
|
||||
super(constance, listener, info);
|
||||
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||
mConnectTimeOut = manager.getUploadConfig().getConnectTimeOut();
|
||||
mReadTimeOut = manager.getUploadConfig().getIOTimeOut();
|
||||
mBufSize = manager.getUploadConfig().getBuffSize();
|
||||
isNotNetRetry = manager.getUploadConfig().isNotNetRetry();
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.upload.uploader;
|
||||
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.AbsThreadTask;
|
||||
import com.arialyy.aria.core.common.StateConstance;
|
||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
@@ -52,6 +52,11 @@ class HttpThreadTask extends AbsThreadTask<UploadEntity, UploadTaskEntity> {
|
||||
HttpThreadTask(StateConstance constance, IUploadListener listener,
|
||||
SubThreadConfig<UploadTaskEntity> uploadInfo) {
|
||||
super(constance, listener, uploadInfo);
|
||||
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||
mConnectTimeOut = manager.getUploadConfig().getConnectTimeOut();
|
||||
mReadTimeOut = manager.getUploadConfig().getIOTimeOut();
|
||||
mBufSize = manager.getUploadConfig().getBuffSize();
|
||||
isNotNetRetry = manager.getUploadConfig().isNotNetRetry();
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
@@ -74,10 +79,11 @@ class HttpThreadTask extends AbsThreadTask<UploadEntity, UploadTaskEntity> {
|
||||
mHttpConn.setRequestProperty("Content-Type",
|
||||
mTaskEntity.getContentType() + "; boundary=" + BOUNDARY);
|
||||
mHttpConn.setRequestProperty("User-Agent", mTaskEntity.getUserAgent());
|
||||
mHttpConn.setConnectTimeout(5000);
|
||||
mHttpConn.setConnectTimeout(mConnectTimeOut);
|
||||
mHttpConn.setReadTimeout(mReadTimeOut);
|
||||
//mHttpConn.setRequestProperty("Range", "bytes=" + 0 + "-" + "100");
|
||||
//内部缓冲区---分段上传防止oom
|
||||
mHttpConn.setChunkedStreamingMode(1024);
|
||||
mHttpConn.setChunkedStreamingMode(mBufSize);
|
||||
|
||||
//添加Http请求头部
|
||||
Set<String> keys = mTaskEntity.getHeaders().keySet();
|
||||
|
||||
@@ -39,13 +39,6 @@ class Uploader extends AbsFileer<UploadEntity, UploadTaskEntity> {
|
||||
AriaManager.getInstance(AriaManager.APP).getUploadConfig().getUpdateInterval());
|
||||
}
|
||||
|
||||
protected void checkTask() {
|
||||
super.checkTask();
|
||||
mTaskEntity.setNewTask(
|
||||
DbEntity.findFirst(UploadEntity.class, "filePath=?", mEntity.getFilePath())
|
||||
== null);
|
||||
}
|
||||
|
||||
@Override protected boolean handleNewTask() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class DBConfig {
|
||||
|
||||
static {
|
||||
if (TextUtils.isEmpty(DB_NAME)) {
|
||||
DB_NAME = "AriaLyyDb";
|
||||
DB_NAME = "AndroidAria.db";
|
||||
}
|
||||
if (VERSION == -1) {
|
||||
VERSION = 1;
|
||||
|
||||
@@ -400,7 +400,7 @@ public class CommonUtil {
|
||||
/**
|
||||
* 删除任务记录
|
||||
*
|
||||
* @param removeFile {@code true} 不仅删除任务数据库记录,还会删除已经下载完成的文件
|
||||
* @param removeFile {@code true} 不仅删除任务数据库记录,还会删除已经完成的文件
|
||||
* {@code false}如果任务已经完成,只删除任务数据库记录
|
||||
*/
|
||||
public static void delTaskRecord(TaskRecord record, boolean removeFile,
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
## 开发日志
|
||||
+ v_3.4.1
|
||||
- 移除记录配置文件,改用数据库记录任务记录
|
||||
- 上传配置添加io超时时间、缓存大小配置
|
||||
- 添加没有网络也会重试的开关
|
||||
- 修复多次删除记录的bug
|
||||
+ v_3.4
|
||||
- 优化大量代码
|
||||
- 重构Aria的ORM模型,提高了数据读取的可靠性和读写速度
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
<!--注意,修改该配置文件中的属性会覆盖代码中所设置的属性-->
|
||||
<download>
|
||||
|
||||
<!--断网的时候是否重试,true:断网也重试;false:断网不重试,直接走失败的回调-->
|
||||
<notNetRetry value="true"/>
|
||||
|
||||
<!--设置下载线程,线程下载数改变后,新的下载任务才会生效,如果任务大小小于1m,该设置也不会生效-->
|
||||
<threadNum value="3"/>
|
||||
|
||||
@@ -48,6 +51,16 @@
|
||||
</download>
|
||||
|
||||
<upload>
|
||||
|
||||
<!--断网的时候是否重试,true:断网也重试;false:断网不重试,直接走失败的回调-->
|
||||
<notNetRetry value="false"/>
|
||||
|
||||
<!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒-->
|
||||
<iOTimeOut value="10000"/>
|
||||
|
||||
<!--设置写文件buff大小,该数值大小不能小于2048,数值变小,速度会变慢-->
|
||||
<buffSize value="8192"/>
|
||||
|
||||
<!--是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度-->
|
||||
<convertSpeed value="true"/>
|
||||
|
||||
@@ -55,7 +68,7 @@
|
||||
<maxTaskNum value="2"/>
|
||||
|
||||
<!--设置上传失败,重试次数,默认为10-->
|
||||
<reTryNum value="2"/>
|
||||
<reTryNum value="3"/>
|
||||
|
||||
<!--设置重试间隔,单位为毫秒-->
|
||||
<reTryInterval value="2000"/>
|
||||
|
||||
@@ -18,7 +18,9 @@ public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
|
||||
AnyRunnModule module;
|
||||
String[] urls;
|
||||
int index = 0;
|
||||
String URL = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
||||
//String URL = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
||||
String URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||
//String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_test;
|
||||
@@ -47,8 +49,7 @@ public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
|
||||
case R.id.stop:
|
||||
//List<AbsEntity> list = Aria.download(this).getTotalTaskList();
|
||||
//
|
||||
////module.stop();
|
||||
//module.stop(URL);
|
||||
module.stop(URL);
|
||||
|
||||
break;
|
||||
case R.id.cancel:
|
||||
|
||||
@@ -69,7 +69,7 @@ public class AnyRunnModule {
|
||||
.load(url)
|
||||
.addHeader("Accept-Encoding", "gzip")
|
||||
.setRequestMode(RequestEnum.GET)
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1234.apk")
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg123456.apk")
|
||||
.resetState()
|
||||
.start();
|
||||
}
|
||||
|
||||
@@ -192,6 +192,12 @@ class Configuration {
|
||||
* 通用任务配置
|
||||
*/
|
||||
abstract static class BaseTaskConfig extends BaseConfig {
|
||||
|
||||
/**
|
||||
* 设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢
|
||||
*/
|
||||
int buffSize = 8192;
|
||||
|
||||
/**
|
||||
* 进度刷新间隔,默认1秒
|
||||
*/
|
||||
@@ -231,6 +237,16 @@ class Configuration {
|
||||
*/
|
||||
String queueMod = "wait";
|
||||
|
||||
/**
|
||||
* 断网的时候是否重试,{@code true}断网也重试;{@code false}断网不重试,直接走失败的回调
|
||||
*/
|
||||
boolean notNetRetry = false;
|
||||
|
||||
/**
|
||||
* 设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒
|
||||
*/
|
||||
int iOTimeOut = 20 * 1000;
|
||||
|
||||
public long getUpdateInterval() {
|
||||
return updateInterval;
|
||||
}
|
||||
@@ -303,20 +319,43 @@ class Configuration {
|
||||
saveKey("connectTimeOut", String.valueOf(connectTimeOut));
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isNotNetRetry() {
|
||||
return notNetRetry;
|
||||
}
|
||||
|
||||
public BaseTaskConfig setNotNetRetry(boolean notNetRetry) {
|
||||
this.notNetRetry = notNetRetry;
|
||||
saveKey("notNetRetry", String.valueOf(notNetRetry));
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getIOTimeOut() {
|
||||
return iOTimeOut;
|
||||
}
|
||||
|
||||
public BaseTaskConfig setIOTimeOut(int iOTimeOut) {
|
||||
this.iOTimeOut = iOTimeOut;
|
||||
saveKey("iOTimeOut", String.valueOf(iOTimeOut));
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getBuffSize() {
|
||||
return buffSize;
|
||||
}
|
||||
|
||||
public BaseTaskConfig setBuffSize(int buffSize) {
|
||||
this.buffSize = buffSize;
|
||||
saveKey("buffSize", String.valueOf(buffSize));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载配置
|
||||
*/
|
||||
public static class DownloadConfig extends BaseTaskConfig {
|
||||
/**
|
||||
* 设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒
|
||||
*/
|
||||
int iOTimeOut = 20 * 1000;
|
||||
/**
|
||||
* 设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢
|
||||
*/
|
||||
int buffSize = 8192;
|
||||
|
||||
/**
|
||||
* 设置https ca 证书信息;path 为assets目录下的CA证书完整路径
|
||||
*/
|
||||
@@ -343,10 +382,6 @@ class Configuration {
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getIOTimeOut() {
|
||||
return iOTimeOut;
|
||||
}
|
||||
|
||||
public int getMaxSpeed() {
|
||||
return maxSpeed;
|
||||
}
|
||||
@@ -363,22 +398,6 @@ class Configuration {
|
||||
saveKey("threadNum", String.valueOf(threadNum));
|
||||
}
|
||||
|
||||
public DownloadConfig setIOTimeOut(int iOTimeOut) {
|
||||
this.iOTimeOut = iOTimeOut;
|
||||
saveKey("iOTimeOut", String.valueOf(iOTimeOut));
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getBuffSize() {
|
||||
return buffSize;
|
||||
}
|
||||
|
||||
public DownloadConfig setBuffSize(int buffSize) {
|
||||
this.buffSize = buffSize;
|
||||
saveKey("buffSize", String.valueOf(buffSize));
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCaPath() {
|
||||
return caPath;
|
||||
}
|
||||
|
||||
@@ -68,10 +68,11 @@ public class UploadTask extends AbsNormalTask<UploadTaskEntity> {
|
||||
}
|
||||
|
||||
@Override public void cancel() {
|
||||
if (!mUtil.isRunning()) {
|
||||
if (mUtil.isRunning()) {
|
||||
mUtil.cancel();
|
||||
} else {
|
||||
mListener.onCancel();
|
||||
}
|
||||
mUtil.cancel();
|
||||
}
|
||||
|
||||
@Override public String getTaskName() {
|
||||
|
||||
Reference in New Issue
Block a user