修复下载失败重试不起作用的问题
This commit is contained in:
@ -97,7 +97,6 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
|
|||||||
boolean s = mExecuteQueue.offer(newTask);
|
boolean s = mExecuteQueue.offer(newTask);
|
||||||
Log.w(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】"));
|
Log.w(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】"));
|
||||||
if (s) {
|
if (s) {
|
||||||
newTask.start();
|
|
||||||
mExecuteArray.put(CommonUtil.keyToHashKey(url), newTask);
|
mExecuteArray.put(CommonUtil.keyToHashKey(url), newTask);
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
@ -114,7 +113,6 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
oldTask.stop();
|
oldTask.stop();
|
||||||
// wait(200);
|
|
||||||
String key = CommonUtil.keyToHashKey(oldTask.getKey());
|
String key = CommonUtil.keyToHashKey(oldTask.getKey());
|
||||||
mExecuteArray.remove(key);
|
mExecuteArray.remove(key);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -94,8 +94,8 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
|
|||||||
startNextTask();
|
startNextTask();
|
||||||
break;
|
break;
|
||||||
case FAIL:
|
case FAIL:
|
||||||
mQueue.removeTask(entity);
|
//mQueue.removeTask(entity);
|
||||||
handleFailTask(entity);
|
handleFailTask(task);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -156,9 +156,9 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
|
|||||||
/**
|
/**
|
||||||
* 处理下载任务下载失败的情形
|
* 处理下载任务下载失败的情形
|
||||||
*
|
*
|
||||||
* @param entity 失败实体
|
* @param task 下载任务
|
||||||
*/
|
*/
|
||||||
private void handleFailTask(final DownloadEntity entity) {
|
private void handleFailTask(final DownloadTask task) {
|
||||||
final Configuration config = Configuration.getInstance();
|
final Configuration config = Configuration.getInstance();
|
||||||
CountDownTimer timer = new CountDownTimer(config.getReTryInterval(), 1000) {
|
CountDownTimer timer = new CountDownTimer(config.getReTryInterval(), 1000) {
|
||||||
@Override public void onTick(long millisUntilFinished) {
|
@Override public void onTick(long millisUntilFinished) {
|
||||||
@ -166,7 +166,8 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onFinish() {
|
@Override public void onFinish() {
|
||||||
if (entity.getFailNum() <= config.getReTryNum()) {
|
DownloadEntity entity = task.getDownloadEntity();
|
||||||
|
if (entity.getFailNum() < config.getReTryNum()) {
|
||||||
DownloadTask task = mQueue.getTask(entity);
|
DownloadTask task = mQueue.getTask(entity);
|
||||||
mQueue.reTryStart(task);
|
mQueue.reTryStart(task);
|
||||||
try {
|
try {
|
||||||
@ -175,6 +176,7 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
mQueue.removeTask(entity);
|
||||||
startNextTask();
|
startNextTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,10 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
* 上传任务调度器
|
* 上传任务调度器
|
||||||
*/
|
*/
|
||||||
public class UploadSchedulers implements ISchedulers<UploadTask> {
|
public class UploadSchedulers implements ISchedulers<UploadTask> {
|
||||||
private static final String TAG = "UploadSchedulers";
|
private static final String TAG =
|
||||||
private static final Object LOCK = new Object();
|
"UploadSchedulers";
|
||||||
|
private static final Object LOCK =
|
||||||
|
new Object();
|
||||||
private static volatile UploadSchedulers INSTANCE = null;
|
private static volatile UploadSchedulers INSTANCE = null;
|
||||||
private Map<String, OnSchedulerListener<UploadTask>> mSchedulerListeners =
|
private Map<String, OnSchedulerListener<UploadTask>> mSchedulerListeners =
|
||||||
new ConcurrentHashMap<>();
|
new ConcurrentHashMap<>();
|
||||||
@ -68,7 +70,7 @@ public class UploadSchedulers implements ISchedulers<UploadTask> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleFailTask(final UploadEntity entity) {
|
private void handleFailTask(final UploadTask task) {
|
||||||
final Configuration config = Configuration.getInstance();
|
final Configuration config = Configuration.getInstance();
|
||||||
CountDownTimer timer = new CountDownTimer(config.getReTryInterval(), 1000) {
|
CountDownTimer timer = new CountDownTimer(config.getReTryInterval(), 1000) {
|
||||||
@Override public void onTick(long millisUntilFinished) {
|
@Override public void onTick(long millisUntilFinished) {
|
||||||
@ -76,6 +78,7 @@ public class UploadSchedulers implements ISchedulers<UploadTask> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onFinish() {
|
@Override public void onFinish() {
|
||||||
|
UploadEntity entity = task.getUploadEntity();
|
||||||
if (entity.getFailNum() <= config.getReTryNum()) {
|
if (entity.getFailNum() <= config.getReTryNum()) {
|
||||||
UploadTask task = mQueue.getTask(entity);
|
UploadTask task = mQueue.getTask(entity);
|
||||||
mQueue.reTryStart(task);
|
mQueue.reTryStart(task);
|
||||||
@ -85,6 +88,7 @@ public class UploadSchedulers implements ISchedulers<UploadTask> {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
mQueue.removeTask(entity);
|
||||||
startNextTask();
|
startNextTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,8 +180,7 @@ public class UploadSchedulers implements ISchedulers<UploadTask> {
|
|||||||
startNextTask();
|
startNextTask();
|
||||||
break;
|
break;
|
||||||
case FAIL:
|
case FAIL:
|
||||||
mQueue.removeTask(entity);
|
handleFailTask(task);
|
||||||
handleFailTask(entity);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -178,7 +178,7 @@ public class UploadUtil implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
outputStream.close();
|
//outputStream.close();
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
writer.append(LINE_END);
|
writer.append(LINE_END);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".download.DownloadActivity"/>
|
||||||
<activity android:name=".upload.UploadActivity"/>
|
<activity android:name=".upload.UploadActivity"/>
|
||||||
<activity android:name=".download.SingleTaskActivity"/>
|
<activity android:name=".download.SingleTaskActivity"/>
|
||||||
<activity android:name=".download.multi_download.MultiTaskActivity"/>
|
<activity android:name=".download.multi_download.MultiTaskActivity"/>
|
||||||
|
@ -52,7 +52,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://1_static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||||
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb;
|
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb;
|
||||||
@Bind(R.id.start) Button mStart;
|
@Bind(R.id.start) Button mStart;
|
||||||
@Bind(R.id.stop) Button mStop;
|
@Bind(R.id.stop) Button mStop;
|
||||||
|
@ -141,12 +141,12 @@ public class UploadActivity extends BaseActivity<ActivityUploadMeanBinding> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.upload) void upload() {
|
@OnClick(R.id.upload) void upload() {
|
||||||
//Aria.upload(this)
|
Aria.upload(this)
|
||||||
// .load(FILE_PATH)
|
.load(FILE_PATH)
|
||||||
// .setUploadUrl("http://172.18.104.50:8080/upload/sign_file")
|
.setUploadUrl("http://192.168.1.8:8080/upload/sign_file")
|
||||||
// .setAttachment("file")
|
.setAttachment("file")
|
||||||
// .start();
|
.start();
|
||||||
test();
|
//test();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.stop) void stop() {
|
@OnClick(R.id.stop) void stop() {
|
||||||
|
Reference in New Issue
Block a user