|
|
@ -15,7 +15,6 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package com.arialyy.aria.core.common; |
|
|
|
package com.arialyy.aria.core.common; |
|
|
|
|
|
|
|
|
|
|
|
import android.os.Build; |
|
|
|
|
|
|
|
import com.arialyy.aria.core.AriaManager; |
|
|
|
import com.arialyy.aria.core.AriaManager; |
|
|
|
import com.arialyy.aria.core.inf.AbsNormalEntity; |
|
|
|
import com.arialyy.aria.core.inf.AbsNormalEntity; |
|
|
|
import com.arialyy.aria.core.inf.AbsTaskEntity; |
|
|
|
import com.arialyy.aria.core.inf.AbsTaskEntity; |
|
|
@ -29,8 +28,6 @@ import com.arialyy.aria.util.NetUtils; |
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Timer; |
|
|
|
|
|
|
|
import java.util.TimerTask; |
|
|
|
|
|
|
|
import java.util.concurrent.Callable; |
|
|
|
import java.util.concurrent.Callable; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.concurrent.Executors; |
|
|
@ -58,7 +55,6 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY |
|
|
|
protected ENTITY mEntity; |
|
|
|
protected ENTITY mEntity; |
|
|
|
protected TASK_ENTITY mTaskEntity; |
|
|
|
protected TASK_ENTITY mTaskEntity; |
|
|
|
private int mFailTimes = 0; |
|
|
|
private int mFailTimes = 0; |
|
|
|
private Timer mFailTimer; |
|
|
|
|
|
|
|
private long mLastSaveTime; |
|
|
|
private long mLastSaveTime; |
|
|
|
private ExecutorService mConfigThreadPool; |
|
|
|
private ExecutorService mConfigThreadPool; |
|
|
|
protected int mConnectTimeOut; //连接超时时间
|
|
|
|
protected int mConnectTimeOut; //连接超时时间
|
|
|
@ -126,10 +122,11 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 设置最大下载速度 |
|
|
|
* 设置最大下载速度 |
|
|
|
|
|
|
|
* |
|
|
|
* @param speed 单位为:kb |
|
|
|
* @param speed 单位为:kb |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setMaxSpeed(int speed){ |
|
|
|
public void setMaxSpeed(int speed) { |
|
|
|
if (mSpeedBandUtil != null){ |
|
|
|
if (mSpeedBandUtil != null) { |
|
|
|
mSpeedBandUtil.setMaxRate(speed / mThreadNum); |
|
|
|
mSpeedBandUtil.setMaxRate(speed / mThreadNum); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -166,6 +163,10 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY |
|
|
|
return STATE.isRunning; |
|
|
|
return STATE.isRunning; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isInterrupted() { |
|
|
|
|
|
|
|
return Thread.currentThread().isInterrupted(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取线程配置信息 |
|
|
|
* 获取线程配置信息 |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -173,10 +174,6 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY |
|
|
|
return mConfig; |
|
|
|
return mConfig; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean filterVersion() { |
|
|
|
|
|
|
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override protected void finalize() throws Throwable { |
|
|
|
@Override protected void finalize() throws Throwable { |
|
|
|
super.finalize(); |
|
|
|
super.finalize(); |
|
|
|
if (mConfigThreadPool != null) { |
|
|
|
if (mConfigThreadPool != null) { |
|
|
@ -333,10 +330,6 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY |
|
|
|
* @param needRetry 是否可以重试 |
|
|
|
* @param needRetry 是否可以重试 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void retryThis(boolean needRetry) { |
|
|
|
private void retryThis(boolean needRetry) { |
|
|
|
if (mFailTimer != null) { |
|
|
|
|
|
|
|
mFailTimer.purge(); |
|
|
|
|
|
|
|
mFailTimer.cancel(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!NetUtils.isConnected(AriaManager.APP) && !isNotNetRetry) { |
|
|
|
if (!NetUtils.isConnected(AriaManager.APP) && !isNotNetRetry) { |
|
|
|
ALog.w(TAG, String.format("任务【%s】thread__%s__重试失败,网络未连接", mConfig.TEMP_FILE.getName(), |
|
|
|
ALog.w(TAG, String.format("任务【%s】thread__%s__重试失败,网络未连接", mConfig.TEMP_FILE.getName(), |
|
|
|
mConfig.THREAD_ID)); |
|
|
|
mConfig.THREAD_ID)); |
|
|
@ -345,19 +338,9 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY |
|
|
|
|| isNotNetRetry) && !isBreak()) { |
|
|
|
|| isNotNetRetry) && !isBreak()) { |
|
|
|
ALog.w(TAG, |
|
|
|
ALog.w(TAG, |
|
|
|
String.format("任务【%s】thread__%s__正在重试", mConfig.TEMP_FILE.getName(), mConfig.THREAD_ID)); |
|
|
|
String.format("任务【%s】thread__%s__正在重试", mConfig.TEMP_FILE.getName(), mConfig.THREAD_ID)); |
|
|
|
mFailTimer = new Timer(true); |
|
|
|
mFailTimes++; |
|
|
|
mFailTimer.schedule(new TimerTask() { |
|
|
|
handleRetryRecord(); |
|
|
|
@Override public void run() { |
|
|
|
ThreadTaskManager.getInstance().retryThread(AbsThreadTask.this); |
|
|
|
if (isBreak()) { |
|
|
|
|
|
|
|
handleFailState(false); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mFailTimes++; |
|
|
|
|
|
|
|
handleRetryRecord(); |
|
|
|
|
|
|
|
ThreadTaskManager.getInstance().retryThread(AbsThreadTask.this); |
|
|
|
|
|
|
|
//AbsThreadTask.this.run();
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, 3000); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
handleFailState(!isBreak()); |
|
|
|
handleFailState(!isBreak()); |
|
|
|
} |
|
|
|
} |
|
|
|