修复失败重试间隔不起作用的bug
This commit is contained in:
@ -89,21 +89,15 @@ public class DownloadTaskQueue implements ITaskQueue {
|
|||||||
|
|
||||||
@Override public void stopTask(Task task) {
|
@Override public void stopTask(Task task) {
|
||||||
if (!task.isDownloading()) Log.w(TAG, "停止任务失败,【任务已经停止】");
|
if (!task.isDownloading()) Log.w(TAG, "停止任务失败,【任务已经停止】");
|
||||||
|
if (mExecutePool.removeTask(task)) {
|
||||||
task.stop();
|
task.stop();
|
||||||
//if (task.isDownloading()) {
|
} else {
|
||||||
// if (mExecutePool.removeTask(task)) {
|
task.stop();
|
||||||
// task.stop();
|
Log.w(TAG, "停止任务失败,【任务已经停止】");
|
||||||
// }
|
}
|
||||||
//} else {
|
|
||||||
// task.stop();
|
|
||||||
// Log.w(TAG, "停止任务失败,【任务已经停止】");
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void cancelTask(Task task) {
|
@Override public void cancelTask(Task task) {
|
||||||
//if (mExecutePool.removeTask(task) || mCachePool.removeTask(task)) {
|
|
||||||
// task.cancel();
|
|
||||||
//}
|
|
||||||
task.cancel();
|
task.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,10 +113,6 @@ public class DownloadTaskQueue implements ITaskQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Override public IDownloadSchedulers getDownloadSchedulers() {
|
|
||||||
// return mSchedulers;
|
|
||||||
//}
|
|
||||||
|
|
||||||
@Override public int size() {
|
@Override public int size() {
|
||||||
return mExecutePool.size();
|
return mExecutePool.size();
|
||||||
}
|
}
|
||||||
@ -159,12 +149,10 @@ public class DownloadTaskQueue implements ITaskQueue {
|
|||||||
@Override public Task createTask(String target, DownloadEntity entity) {
|
@Override public Task createTask(String target, DownloadEntity entity) {
|
||||||
Task task;
|
Task task;
|
||||||
if (TextUtils.isEmpty(target)) {
|
if (TextUtils.isEmpty(target)) {
|
||||||
//task = TaskFactory.getInstance().createTask(mContext, entity, mSchedulers);
|
|
||||||
task =
|
task =
|
||||||
TaskFactory.getInstance().createTask(mContext, entity, DownloadSchedulers.getInstance());
|
TaskFactory.getInstance().createTask(mContext, entity, DownloadSchedulers.getInstance());
|
||||||
} else {
|
} else {
|
||||||
task = TaskFactory.getInstance()
|
task = TaskFactory.getInstance()
|
||||||
//.createTask(target.getClass().getName(), mContext, entity, mSchedulers);
|
|
||||||
.createTask(target, mContext, entity, DownloadSchedulers.getInstance());
|
.createTask(target, mContext, entity, DownloadSchedulers.getInstance());
|
||||||
}
|
}
|
||||||
mCachePool.putTask(task);
|
mCachePool.putTask(task);
|
||||||
@ -197,29 +185,15 @@ public class DownloadTaskQueue implements ITaskQueue {
|
|||||||
return mCachePool.pollTask();
|
return mCachePool.pollTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Override public void setScheduler(IDownloadSchedulers schedulers) {
|
|
||||||
// mSchedulers = schedulers;
|
|
||||||
//}
|
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
Context context;
|
Context context;
|
||||||
IDownloadSchedulers schedulers;
|
|
||||||
|
|
||||||
public Builder(Context context) {
|
public Builder(Context context) {
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
//public Builder setDownloadSchedulers(IDownloadSchedulers schedulers) {
|
|
||||||
// this.schedulers = schedulers;
|
|
||||||
// return this;
|
|
||||||
//}
|
|
||||||
|
|
||||||
public DownloadTaskQueue build() {
|
public DownloadTaskQueue build() {
|
||||||
DownloadTaskQueue queue = new DownloadTaskQueue(context);
|
DownloadTaskQueue queue = new DownloadTaskQueue(context);
|
||||||
//if (schedulers == null) {
|
|
||||||
// schedulers = DownloadSchedulers.getInstance();
|
|
||||||
//}
|
|
||||||
//queue.setScheduler(schedulers);
|
|
||||||
return queue;
|
return queue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,11 +73,4 @@ public interface ITaskQueue extends IDownloader {
|
|||||||
* @return 下载任务 or null
|
* @return 下载任务 or null
|
||||||
*/
|
*/
|
||||||
public Task getNextTask();
|
public Task getNextTask();
|
||||||
|
|
||||||
///**
|
|
||||||
// * 设置下载调度器
|
|
||||||
// *
|
|
||||||
// * @param schedulers 下载调度器{@link IDownloadSchedulers}
|
|
||||||
// */
|
|
||||||
//public void setScheduler(IDownloadSchedulers schedulers);
|
|
||||||
}
|
}
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.arialyy.aria.core.scheduler;
|
package com.arialyy.aria.core.scheduler;
|
||||||
|
|
||||||
|
import android.os.CountDownTimer;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -154,10 +155,8 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
|||||||
|
|
||||||
private void callback(int state, Task task, OnSchedulerListener listener) {
|
private void callback(int state, Task task, OnSchedulerListener listener) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
//Task task = mQueue.getTask(entity);
|
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
//Log.e(TAG, "队列中没有下载链接【" + entity.getDownloadUrl() + "】的任务");
|
Log.e(TAG, "TASK 为null,回调失败");
|
||||||
Log.e(TAG, "传递的下载任务");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (state) {
|
switch (state) {
|
||||||
@ -195,9 +194,13 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
|||||||
* @param entity 失败实体
|
* @param entity 失败实体
|
||||||
*/
|
*/
|
||||||
@Override public void handleFailTask(final DownloadEntity entity) {
|
@Override public void handleFailTask(final DownloadEntity entity) {
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override public void run() {
|
|
||||||
final Configuration config = Configuration.getInstance();
|
final Configuration config = Configuration.getInstance();
|
||||||
|
CountDownTimer timer = new CountDownTimer(config.getReTryInterval(), 1000) {
|
||||||
|
@Override public void onTick(long millisUntilFinished) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onFinish() {
|
||||||
if (entity.getFailNum() <= config.getReTryNum()) {
|
if (entity.getFailNum() <= config.getReTryNum()) {
|
||||||
Task task = mQueue.getTask(entity);
|
Task task = mQueue.getTask(entity);
|
||||||
mQueue.reTryStart(task);
|
mQueue.reTryStart(task);
|
||||||
@ -210,7 +213,8 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
|||||||
startNextTask(entity);
|
startNextTask(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
};
|
||||||
|
timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -242,12 +242,16 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
|||||||
handleBreakpoint(conn);
|
handleBreakpoint(conn);
|
||||||
} else if (code == HttpURLConnection.HTTP_OK || len < 0) {
|
} else if (code == HttpURLConnection.HTTP_OK || len < 0) {
|
||||||
//在conn.setRequestProperty("Range", "bytes=" + 0 + "-");下,200为不支持断点状态
|
//在conn.setRequestProperty("Range", "bytes=" + 0 + "-");下,200为不支持断点状态
|
||||||
|
if (len < 0){
|
||||||
|
failDownload("任务【" + mDownloadEntity.getDownloadUrl() + "】下载失败,文件长度小于0");
|
||||||
|
return;
|
||||||
|
}
|
||||||
isSupportBreakpoint = false;
|
isSupportBreakpoint = false;
|
||||||
mListener.supportBreakpoint(false);
|
mListener.supportBreakpoint(false);
|
||||||
Log.w(TAG, "该下载链接不支持断点下载");
|
Log.w(TAG, "该下载链接不支持断点下载");
|
||||||
handleBreakpoint(conn);
|
handleBreakpoint(conn);
|
||||||
} else {
|
} else {
|
||||||
failDownload("下载失败,返回码:" + code);
|
failDownload("任务【" + mDownloadEntity.getDownloadUrl() + "】下载失败,返回码:" + code);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
failDownload("下载失败【downloadUrl:"
|
failDownload("下载失败【downloadUrl:"
|
||||||
|
@ -113,7 +113,6 @@ public class DbUtil {
|
|||||||
params[i] = "'" + expression[i + 1] + "'";
|
params[i] = "'" + expression[i + 1] + "'";
|
||||||
}
|
}
|
||||||
sql = String.format(sql, params);
|
sql = String.format(sql, params);
|
||||||
Log.d(TAG, sql);
|
|
||||||
print(DEL_DATA, sql);
|
print(DEL_DATA, sql);
|
||||||
mDb.execSQL(sql);
|
mDb.execSQL(sql);
|
||||||
close();
|
close();
|
||||||
@ -185,7 +184,6 @@ public class DbUtil {
|
|||||||
params[i] = "'" + expression[i + 1] + "'";
|
params[i] = "'" + expression[i + 1] + "'";
|
||||||
}
|
}
|
||||||
sql = String.format(sql, params);
|
sql = String.format(sql, params);
|
||||||
Log.d(TAG, sql);
|
|
||||||
print(FIND_DATA, sql);
|
print(FIND_DATA, sql);
|
||||||
Cursor cursor = mDb.rawQuery(sql, null);
|
Cursor cursor = mDb.rawQuery(sql, null);
|
||||||
return cursor.getCount() > 0 ? newInstanceEntity(clazz, cursor) : null;
|
return cursor.getCount() > 0 ? newInstanceEntity(clazz, cursor) : null;
|
||||||
|
Reference in New Issue
Block a user