|
|
@ -35,6 +35,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { |
|
|
|
private final String TAG = "DownloadGroupUtil"; |
|
|
|
private final String TAG = "DownloadGroupUtil"; |
|
|
|
private ExecutorService mInfoPool; |
|
|
|
private ExecutorService mInfoPool; |
|
|
|
private int mInitCompleteNum, mInitFailNum; |
|
|
|
private int mInitCompleteNum, mInitFailNum; |
|
|
|
|
|
|
|
private boolean isStop = false; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 文件信息回调组 |
|
|
|
* 文件信息回调组 |
|
|
@ -53,6 +54,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { |
|
|
|
|
|
|
|
|
|
|
|
@Override public void onCancel() { |
|
|
|
@Override public void onCancel() { |
|
|
|
super.onCancel(); |
|
|
|
super.onCancel(); |
|
|
|
|
|
|
|
isStop = true; |
|
|
|
if (!mInfoPool.isShutdown()) { |
|
|
|
if (!mInfoPool.isShutdown()) { |
|
|
|
mInfoPool.shutdown(); |
|
|
|
mInfoPool.shutdown(); |
|
|
|
} |
|
|
|
} |
|
|
@ -60,6 +62,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { |
|
|
|
|
|
|
|
|
|
|
|
@Override protected void onStop() { |
|
|
|
@Override protected void onStop() { |
|
|
|
super.onStop(); |
|
|
|
super.onStop(); |
|
|
|
|
|
|
|
isStop = true; |
|
|
|
if (!mInfoPool.isShutdown()) { |
|
|
|
if (!mInfoPool.isShutdown()) { |
|
|
|
mInfoPool.shutdown(); |
|
|
|
mInfoPool.shutdown(); |
|
|
|
} |
|
|
|
} |
|
|
@ -67,6 +70,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { |
|
|
|
|
|
|
|
|
|
|
|
@Override protected void onStart() { |
|
|
|
@Override protected void onStart() { |
|
|
|
super.onStart(); |
|
|
|
super.onStart(); |
|
|
|
|
|
|
|
isStop = false; |
|
|
|
if (mCompleteNum == mGroupSize) { |
|
|
|
if (mCompleteNum == mGroupSize) { |
|
|
|
mListener.onComplete(); |
|
|
|
mListener.onComplete(); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -83,7 +87,9 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { |
|
|
|
if (taskEntity != null) { |
|
|
|
if (taskEntity != null) { |
|
|
|
if (taskEntity.getState() != IEntity.STATE_FAIL |
|
|
|
if (taskEntity.getState() != IEntity.STATE_FAIL |
|
|
|
&& taskEntity.getState() != IEntity.STATE_WAIT) { |
|
|
|
&& taskEntity.getState() != IEntity.STATE_WAIT) { |
|
|
|
|
|
|
|
mInitCompleteNum++; |
|
|
|
createChildDownload(taskEntity); |
|
|
|
createChildDownload(taskEntity); |
|
|
|
|
|
|
|
checkStartFlow(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mInfoPool.execute(createFileInfoThread(taskEntity)); |
|
|
|
mInfoPool.execute(createFileInfoThread(taskEntity)); |
|
|
|
} |
|
|
|
} |
|
|
@ -105,6 +111,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { |
|
|
|
int failNum = 0; |
|
|
|
int failNum = 0; |
|
|
|
|
|
|
|
|
|
|
|
@Override public void onComplete(String url, CompleteInfo info) { |
|
|
|
@Override public void onComplete(String url, CompleteInfo info) { |
|
|
|
|
|
|
|
if (isStop) return; |
|
|
|
DownloadTaskEntity te = mExeMap.get(url); |
|
|
|
DownloadTaskEntity te = mExeMap.get(url); |
|
|
|
if (te != null) { |
|
|
|
if (te != null) { |
|
|
|
if (isNeedLoadFileSize) { |
|
|
|
if (isNeedLoadFileSize) { |
|
|
@ -112,15 +119,13 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { |
|
|
|
} |
|
|
|
} |
|
|
|
createChildDownload(te); |
|
|
|
createChildDownload(te); |
|
|
|
} |
|
|
|
} |
|
|
|
mInitCompleteNum ++; |
|
|
|
mInitCompleteNum++; |
|
|
|
|
|
|
|
|
|
|
|
if (mInitCompleteNum + mInitFailNum >= mGroupSize || !isNeedLoadFileSize) { |
|
|
|
checkStartFlow(); |
|
|
|
startRunningFlow(); |
|
|
|
|
|
|
|
updateFileSize(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override public void onFail(String url, String errorMsg, boolean needRetry) { |
|
|
|
@Override public void onFail(String url, String errorMsg, boolean needRetry) { |
|
|
|
|
|
|
|
if (isStop) return; |
|
|
|
ALog.e(TAG, "任务【" + url + "】初始化失败。"); |
|
|
|
ALog.e(TAG, "任务【" + url + "】初始化失败。"); |
|
|
|
DownloadTaskEntity te = mExeMap.get(url); |
|
|
|
DownloadTaskEntity te = mExeMap.get(url); |
|
|
|
if (te != null) { |
|
|
|
if (te != null) { |
|
|
@ -136,14 +141,23 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { |
|
|
|
// mInitFailNum++;
|
|
|
|
// mInitFailNum++;
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
//failNum++;
|
|
|
|
//failNum++;
|
|
|
|
mInitFailNum ++; |
|
|
|
mInitFailNum++; |
|
|
|
if (mInitCompleteNum + mInitFailNum >= mGroupSize || !isNeedLoadFileSize) { |
|
|
|
checkStartFlow(); |
|
|
|
startRunningFlow(); |
|
|
|
|
|
|
|
updateFileSize(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
return new HttpFileInfoThread(taskEntity, callback); |
|
|
|
return new HttpFileInfoThread(taskEntity, callback); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 检查能否启动下载流程 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void checkStartFlow() { |
|
|
|
|
|
|
|
synchronized (DownloadGroupUtil.class) { |
|
|
|
|
|
|
|
if (mInitCompleteNum + mInitFailNum >= mGroupSize || !isNeedLoadFileSize) { |
|
|
|
|
|
|
|
startRunningFlow(); |
|
|
|
|
|
|
|
updateFileSize(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |