修复失败重试间隔不起作用的bug

pull/9/head
AriaLyy 8 years ago
parent db13ce4707
commit 3a744201b5
  1. 36
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  2. 7
      Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
  3. 16
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
  4. 6
      Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java
  5. 2
      Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java

@ -89,21 +89,15 @@ public class DownloadTaskQueue implements ITaskQueue {
@Override public void stopTask(Task task) {
if (!task.isDownloading()) Log.w(TAG, "停止任务失败,【任务已经停止】");
if (mExecutePool.removeTask(task)) {
task.stop();
//if (task.isDownloading()) {
// if (mExecutePool.removeTask(task)) {
// task.stop();
// }
//} else {
// task.stop();
// Log.w(TAG, "停止任务失败,【任务已经停止】");
//}
} else {
task.stop();
Log.w(TAG, "停止任务失败,【任务已经停止】");
}
}
@Override public void cancelTask(Task task) {
//if (mExecutePool.removeTask(task) || mCachePool.removeTask(task)) {
// task.cancel();
//}
task.cancel();
}
@ -119,10 +113,6 @@ public class DownloadTaskQueue implements ITaskQueue {
}
}
//@Override public IDownloadSchedulers getDownloadSchedulers() {
// return mSchedulers;
//}
@Override public int size() {
return mExecutePool.size();
}
@ -159,12 +149,10 @@ public class DownloadTaskQueue implements ITaskQueue {
@Override public Task createTask(String target, DownloadEntity entity) {
Task task;
if (TextUtils.isEmpty(target)) {
//task = TaskFactory.getInstance().createTask(mContext, entity, mSchedulers);
task =
TaskFactory.getInstance().createTask(mContext, entity, DownloadSchedulers.getInstance());
} else {
task = TaskFactory.getInstance()
//.createTask(target.getClass().getName(), mContext, entity, mSchedulers);
.createTask(target, mContext, entity, DownloadSchedulers.getInstance());
}
mCachePool.putTask(task);
@ -197,29 +185,15 @@ public class DownloadTaskQueue implements ITaskQueue {
return mCachePool.pollTask();
}
//@Override public void setScheduler(IDownloadSchedulers schedulers) {
// mSchedulers = schedulers;
//}
public static class Builder {
Context context;
IDownloadSchedulers schedulers;
public Builder(Context context) {
this.context = context.getApplicationContext();
}
//public Builder setDownloadSchedulers(IDownloadSchedulers schedulers) {
// this.schedulers = schedulers;
// return this;
//}
public DownloadTaskQueue build() {
DownloadTaskQueue queue = new DownloadTaskQueue(context);
//if (schedulers == null) {
// schedulers = DownloadSchedulers.getInstance();
//}
//queue.setScheduler(schedulers);
return queue;
}
}

@ -73,11 +73,4 @@ public interface ITaskQueue extends IDownloader {
* @return 下载任务 or null
*/
public Task getNextTask();
///**
// * 设置下载调度器
// *
// * @param schedulers 下载调度器{@link IDownloadSchedulers}
// */
//public void setScheduler(IDownloadSchedulers schedulers);
}

@ -16,6 +16,7 @@
package com.arialyy.aria.core.scheduler;
import android.os.CountDownTimer;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
@ -154,10 +155,8 @@ public class DownloadSchedulers implements IDownloadSchedulers {
private void callback(int state, Task task, OnSchedulerListener listener) {
if (listener != null) {
//Task task = mQueue.getTask(entity);
if (task == null) {
//Log.e(TAG, "队列中没有下载链接【" + entity.getDownloadUrl() + "】的任务");
Log.e(TAG, "传递的下载任务");
Log.e(TAG, "TASK 为null,回调失败");
return;
}
switch (state) {
@ -195,9 +194,13 @@ public class DownloadSchedulers implements IDownloadSchedulers {
* @param entity 失败实体
*/
@Override public void handleFailTask(final DownloadEntity entity) {
new Thread(new Runnable() {
@Override public void run() {
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()) {
Task task = mQueue.getTask(entity);
mQueue.reTryStart(task);
@ -210,7 +213,8 @@ public class DownloadSchedulers implements IDownloadSchedulers {
startNextTask(entity);
}
}
}).start();
};
timer.start();
}
/**

@ -242,12 +242,16 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
handleBreakpoint(conn);
} else if (code == HttpURLConnection.HTTP_OK || len < 0) {
//在conn.setRequestProperty("Range", "bytes=" + 0 + "-");下,200为不支持断点状态
if (len < 0){
failDownload("任务【" + mDownloadEntity.getDownloadUrl() + "】下载失败,文件长度小于0");
return;
}
isSupportBreakpoint = false;
mListener.supportBreakpoint(false);
Log.w(TAG, "该下载链接不支持断点下载");
handleBreakpoint(conn);
} else {
failDownload("下载失败,返回码:" + code);
failDownload("任务【" + mDownloadEntity.getDownloadUrl() + "】下载失败,返回码:" + code);
}
} catch (IOException e) {
failDownload("下载失败【downloadUrl:"

@ -113,7 +113,6 @@ public class DbUtil {
params[i] = "'" + expression[i + 1] + "'";
}
sql = String.format(sql, params);
Log.d(TAG, sql);
print(DEL_DATA, sql);
mDb.execSQL(sql);
close();
@ -185,7 +184,6 @@ public class DbUtil {
params[i] = "'" + expression[i + 1] + "'";
}
sql = String.format(sql, params);
Log.d(TAG, sql);
print(FIND_DATA, sql);
Cursor cursor = mDb.rawQuery(sql, null);
return cursor.getCount() > 0 ? newInstanceEntity(clazz, cursor) : null;

Loading…
Cancel
Save