fix bug
This commit is contained in:
@@ -98,9 +98,9 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
|||||||
resumeEntity(te);
|
resumeEntity(te);
|
||||||
} else if (state == IEntity.STATE_WAIT || state == IEntity.STATE_FAIL) {
|
} else if (state == IEntity.STATE_WAIT || state == IEntity.STATE_FAIL) {
|
||||||
mWaitList.add(te);
|
mWaitList.add(te);
|
||||||
} else if (state == IEntity.STATE_RUNNING) {
|
} else {
|
||||||
if (!mQueue.taskIsRunning(te.getEntity().getKey())) {
|
if (!mQueue.taskIsRunning(te.getEntity().getKey())) {
|
||||||
resumeEntity(te);
|
mWaitList.add(te);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,9 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
|||||||
if (mQueue.getCurrentExePoolNum() < maxTaskNum) {
|
if (mQueue.getCurrentExePoolNum() < maxTaskNum) {
|
||||||
startTask(createTask(te));
|
startTask(createTask(te));
|
||||||
} else {
|
} else {
|
||||||
createTask(te);
|
te.getEntity().setState(IEntity.STATE_WAIT);
|
||||||
|
AbsTask task = createTask(te);
|
||||||
|
sendWaitState(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
|||||||
protected void fail(final long subCurrentLocation, String msg, Exception ex, boolean needRetry) {
|
protected void fail(final long subCurrentLocation, String msg, Exception ex, boolean needRetry) {
|
||||||
synchronized (AriaManager.LOCK) {
|
synchronized (AriaManager.LOCK) {
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
//ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex));
|
ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex));
|
||||||
} else {
|
} else {
|
||||||
ALog.e(TAG, msg);
|
ALog.e(TAG, msg);
|
||||||
}
|
}
|
||||||
@@ -322,12 +322,14 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
|||||||
* @param record 当前下载进度
|
* @param record 当前下载进度
|
||||||
*/
|
*/
|
||||||
protected void writeConfig(boolean isComplete, final long record) {
|
protected void writeConfig(boolean isComplete, final long record) {
|
||||||
if (mConfig.THREAD_RECORD != null) {
|
synchronized (AriaManager.LOCK) {
|
||||||
mConfig.THREAD_RECORD.isComplete = isComplete;
|
if (mConfig.THREAD_RECORD != null) {
|
||||||
if (0 < record && record < mConfig.END_LOCATION) {
|
mConfig.THREAD_RECORD.isComplete = isComplete;
|
||||||
mConfig.THREAD_RECORD.startLocation = record;
|
if (0 < record && record < mConfig.END_LOCATION) {
|
||||||
|
mConfig.THREAD_RECORD.startLocation = record;
|
||||||
|
}
|
||||||
|
mConfig.THREAD_RECORD.update();
|
||||||
}
|
}
|
||||||
mConfig.THREAD_RECORD.update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,6 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
public void startSubTask(String url) {
|
public void startSubTask(String url) {
|
||||||
if (!checkSubTask(url, "开始")) return;
|
if (!checkSubTask(url, "开始")) return;
|
||||||
if (!isRunning) {
|
if (!isRunning) {
|
||||||
isRunning = true;
|
|
||||||
startTimer();
|
startTimer();
|
||||||
}
|
}
|
||||||
Downloader d = getDownloader(url, false);
|
Downloader d = getDownloader(url, false);
|
||||||
@@ -165,7 +164,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
mFailMap.remove(det.getKey());
|
mFailMap.remove(det.getKey());
|
||||||
mGroupSize--;
|
mGroupSize--;
|
||||||
if (mGroupSize == 0) {
|
if (mGroupSize == 0) {
|
||||||
closeTimer(false);
|
closeTimer();
|
||||||
mListener.onCancel();
|
mListener.onCancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,7 +225,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
|
|
||||||
@Override public void cancel() {
|
@Override public void cancel() {
|
||||||
isCancel = true;
|
isCancel = true;
|
||||||
closeTimer(false);
|
closeTimer();
|
||||||
onCancel();
|
onCancel();
|
||||||
if (!mExePool.isShutdown()) {
|
if (!mExePool.isShutdown()) {
|
||||||
mExePool.shutdown();
|
mExePool.shutdown();
|
||||||
@@ -249,7 +248,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
|
|
||||||
@Override public void stop() {
|
@Override public void stop() {
|
||||||
isStop = true;
|
isStop = true;
|
||||||
closeTimer(false);
|
closeTimer();
|
||||||
onStop();
|
onStop();
|
||||||
if (!mExePool.isShutdown()) {
|
if (!mExePool.isShutdown()) {
|
||||||
mExePool.shutdown();
|
mExePool.shutdown();
|
||||||
@@ -297,11 +296,9 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
|
|
||||||
@Override public void start() {
|
@Override public void start() {
|
||||||
if (isStop || isCancel) {
|
if (isStop || isCancel) {
|
||||||
isRunning = false;
|
closeTimer();
|
||||||
closeTimer(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isRunning = true;
|
|
||||||
clearState();
|
clearState();
|
||||||
onStart();
|
onStart();
|
||||||
}
|
}
|
||||||
@@ -323,8 +320,8 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
mFailMap.clear();
|
mFailMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeTimer(boolean isRunning) {
|
void closeTimer() {
|
||||||
this.isRunning = isRunning;
|
isRunning = false;
|
||||||
if (mTimer != null) {
|
if (mTimer != null) {
|
||||||
mTimer.purge();
|
mTimer.purge();
|
||||||
mTimer.cancel();
|
mTimer.cancel();
|
||||||
@@ -336,7 +333,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
* 开始进度流程
|
* 开始进度流程
|
||||||
*/
|
*/
|
||||||
void startRunningFlow() {
|
void startRunningFlow() {
|
||||||
closeTimer(true);
|
closeTimer();
|
||||||
mListener.onPostPre(mTotalLen);
|
mListener.onPostPre(mTotalLen);
|
||||||
if (mCurrentLocation > 0) {
|
if (mCurrentLocation > 0) {
|
||||||
mListener.onResume(mCurrentLocation);
|
mListener.onResume(mCurrentLocation);
|
||||||
@@ -347,11 +344,12 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startTimer() {
|
private void startTimer() {
|
||||||
|
isRunning = true;
|
||||||
mTimer = new Timer(true);
|
mTimer = new Timer(true);
|
||||||
mTimer.schedule(new TimerTask() {
|
mTimer.schedule(new TimerTask() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
if (!isRunning) {
|
if (!isRunning) {
|
||||||
closeTimer(false);
|
closeTimer();
|
||||||
} else if (mCurrentLocation >= 0) {
|
} else if (mCurrentLocation >= 0) {
|
||||||
long t = 0;
|
long t = 0;
|
||||||
for (DownloadTaskEntity te : mGTEntity.getSubTaskEntities()) {
|
for (DownloadTaskEntity te : mGTEntity.getSubTaskEntities()) {
|
||||||
@@ -455,7 +453,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
synchronized (AbsGroupUtil.LOCK) {
|
synchronized (AbsGroupUtil.LOCK) {
|
||||||
mStopNum++;
|
mStopNum++;
|
||||||
if (mStopNum + mCompleteNum + mFailMap.size() == mGroupSize && !isStop) {
|
if (mStopNum + mCompleteNum + mFailMap.size() == mGroupSize && !isStop) {
|
||||||
closeTimer(false);
|
closeTimer();
|
||||||
mListener.onStop(mCurrentLocation);
|
mListener.onStop(mCurrentLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -476,13 +474,13 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
mCompleteNum++;
|
mCompleteNum++;
|
||||||
//如果子任务完成的数量和总任务数一致,表示任务组任务已经完成
|
//如果子任务完成的数量和总任务数一致,表示任务组任务已经完成
|
||||||
if (mCompleteNum == mGroupSize) {
|
if (mCompleteNum == mGroupSize) {
|
||||||
closeTimer(false);
|
closeTimer();
|
||||||
mListener.onComplete();
|
mListener.onComplete();
|
||||||
} else if (mFailMap.size() > 0
|
} else if (mFailMap.size() > 0
|
||||||
&& mStopNum + mCompleteNum + mFailMap.size() >= mGroupSize
|
&& mStopNum + mCompleteNum + mFailMap.size() >= mGroupSize
|
||||||
&& !isStop) {
|
&& !isStop) {
|
||||||
//如果子任务完成数量加上失败的数量和总任务数一致,则任务组停止下载
|
//如果子任务完成数量加上失败的数量和总任务数一致,则任务组停止下载
|
||||||
closeTimer(false);
|
closeTimer();
|
||||||
mListener.onStop(mCurrentLocation);
|
mListener.onStop(mCurrentLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -511,7 +509,7 @@ public abstract class AbsGroupUtil implements IUtil {
|
|||||||
mFailMap.put(subTaskEntity.getUrl(), subTaskEntity);
|
mFailMap.put(subTaskEntity.getUrl(), subTaskEntity);
|
||||||
mListener.onSubFail(subEntity);
|
mListener.onSubFail(subEntity);
|
||||||
if (mFailMap.size() == mExeMap.size() || mFailMap.size() + mCompleteNum == mGroupSize) {
|
if (mFailMap.size() == mExeMap.size() || mFailMap.size() + mCompleteNum == mGroupSize) {
|
||||||
closeTimer(false);
|
closeTimer();
|
||||||
}
|
}
|
||||||
if (mFailMap.size() == mGroupSize) {
|
if (mFailMap.size() == mGroupSize) {
|
||||||
mListener.onFail(true);
|
mListener.onFail(true);
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
|||||||
private void checkStartFlow() {
|
private void checkStartFlow() {
|
||||||
synchronized (DownloadGroupUtil.class) {
|
synchronized (DownloadGroupUtil.class) {
|
||||||
if (mInitFailNum == mExeNum) {
|
if (mInitFailNum == mExeNum) {
|
||||||
closeTimer(false);
|
closeTimer();
|
||||||
mListener.onFail(true);
|
mListener.onFail(true);
|
||||||
}
|
}
|
||||||
if (!isStart && mInitCompleteNum + mInitFailNum == mExeNum || !isNeedLoadFileSize) {
|
if (!isStart && mInitCompleteNum + mInitFailNum == mExeNum || !isNeedLoadFileSize) {
|
||||||
|
|||||||
@@ -207,34 +207,39 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
if (isBreak()) {
|
if (isBreak()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//支持断点的处理
|
|
||||||
if (mConfig.SUPPORT_BP) {
|
if (mChildCurrentLocation == mConfig.END_LOCATION) {
|
||||||
ALog.i(TAG,
|
//支持断点的处理
|
||||||
String.format("任务【%s】线程__%s__下载完毕", mConfig.TEMP_FILE.getName(), mConfig.THREAD_ID));
|
if (mConfig.SUPPORT_BP) {
|
||||||
writeConfig(true, mConfig.END_LOCATION);
|
ALog.i(TAG,
|
||||||
STATE.COMPLETE_THREAD_NUM++;
|
String.format("任务【%s】线程__%s__下载完毕", mConfig.TEMP_FILE.getName(), mConfig.THREAD_ID));
|
||||||
if (STATE.isComplete()) {
|
writeConfig(true, mConfig.END_LOCATION);
|
||||||
if (isBlock) {
|
STATE.COMPLETE_THREAD_NUM++;
|
||||||
boolean success = mergeFile();
|
if (STATE.isComplete()) {
|
||||||
if (!success) {
|
if (isBlock) {
|
||||||
ALog.e(TAG, String.format("任务【%s】分块文件合并失败", mConfig.TEMP_FILE.getName()));
|
boolean success = mergeFile();
|
||||||
STATE.isRunning = false;
|
if (!success) {
|
||||||
mListener.onFail(false);
|
ALog.e(TAG, String.format("任务【%s】分块文件合并失败", mConfig.TEMP_FILE.getName()));
|
||||||
return;
|
STATE.isRunning = false;
|
||||||
|
mListener.onFail(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
STATE.TASK_RECORD.deleteData();
|
||||||
|
STATE.isRunning = false;
|
||||||
|
mListener.onComplete();
|
||||||
}
|
}
|
||||||
STATE.TASK_RECORD.deleteData();
|
if (STATE.isFail()) {
|
||||||
|
STATE.isRunning = false;
|
||||||
|
mListener.onFail(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ALog.i(TAG, "任务下载完成");
|
||||||
STATE.isRunning = false;
|
STATE.isRunning = false;
|
||||||
mListener.onComplete();
|
mListener.onComplete();
|
||||||
}
|
}
|
||||||
if (STATE.isFail()) {
|
|
||||||
STATE.isRunning = false;
|
|
||||||
mListener.onFail(false);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ALog.i(TAG, "任务下载完成");
|
STATE.FAIL_NUM++;
|
||||||
STATE.isRunning = false;
|
|
||||||
mListener.onComplete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,8 +70,12 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
|
|||||||
mCachePool.clear();
|
mCachePool.clear();
|
||||||
for (String key : mExecutePool.getAllTask().keySet()) {
|
for (String key : mExecutePool.getAllTask().keySet()) {
|
||||||
TASK task = mExecutePool.getAllTask().get(key);
|
TASK task = mExecutePool.getAllTask().get(key);
|
||||||
if (task != null && (task.isRunning() || task.getState() == IEntity.STATE_FAIL)) {
|
if (task != null) {
|
||||||
task.stop();
|
int state = task.getState();
|
||||||
|
if (task.isRunning() || (state != IEntity.STATE_COMPLETE
|
||||||
|
&& state != IEntity.STATE_CANCEL)) {
|
||||||
|
task.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ task clean(type: Delete) {
|
|||||||
ext {
|
ext {
|
||||||
userOrg = 'arialyy'
|
userOrg = 'arialyy'
|
||||||
groupId = 'com.arialyy.aria'
|
groupId = 'com.arialyy.aria'
|
||||||
publishVersion = '3.4.4_dev2'
|
publishVersion = '3.4.4_dev4'
|
||||||
// publishVersion = '1.0.3' //FTP插件
|
// publishVersion = '1.0.3' //FTP插件
|
||||||
repoName='maven'
|
repoName='maven'
|
||||||
desc = 'android 下载框架'
|
desc = 'android 下载框架'
|
||||||
|
|||||||
Reference in New Issue
Block a user