|
|
@ -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); |
|
|
|