pull/330/head
laoyuyu 7 years ago
parent b2f1141247
commit 60f575c803
  1. 8
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  2. 4
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  3. 28
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  4. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  5. 5
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  6. 6
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  7. 2
      build.gradle

@ -98,9 +98,9 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
resumeEntity(te);
} else if (state == IEntity.STATE_WAIT || state == IEntity.STATE_FAIL) {
mWaitList.add(te);
} else if (state == IEntity.STATE_RUNNING) {
} else {
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) {
startTask(createTask(te));
} 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) {
synchronized (AriaManager.LOCK) {
if (ex != null) {
//ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex));
ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex));
} else {
ALog.e(TAG, msg);
}
@ -322,6 +322,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
* @param record 当前下载进度
*/
protected void writeConfig(boolean isComplete, final long record) {
synchronized (AriaManager.LOCK) {
if (mConfig.THREAD_RECORD != null) {
mConfig.THREAD_RECORD.isComplete = isComplete;
if (0 < record && record < mConfig.END_LOCATION) {
@ -331,3 +332,4 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
}
}
}
}

@ -126,7 +126,6 @@ public abstract class AbsGroupUtil implements IUtil {
public void startSubTask(String url) {
if (!checkSubTask(url, "开始")) return;
if (!isRunning) {
isRunning = true;
startTimer();
}
Downloader d = getDownloader(url, false);
@ -165,7 +164,7 @@ public abstract class AbsGroupUtil implements IUtil {
mFailMap.remove(det.getKey());
mGroupSize--;
if (mGroupSize == 0) {
closeTimer(false);
closeTimer();
mListener.onCancel();
}
}
@ -226,7 +225,7 @@ public abstract class AbsGroupUtil implements IUtil {
@Override public void cancel() {
isCancel = true;
closeTimer(false);
closeTimer();
onCancel();
if (!mExePool.isShutdown()) {
mExePool.shutdown();
@ -249,7 +248,7 @@ public abstract class AbsGroupUtil implements IUtil {
@Override public void stop() {
isStop = true;
closeTimer(false);
closeTimer();
onStop();
if (!mExePool.isShutdown()) {
mExePool.shutdown();
@ -297,11 +296,9 @@ public abstract class AbsGroupUtil implements IUtil {
@Override public void start() {
if (isStop || isCancel) {
isRunning = false;
closeTimer(false);
closeTimer();
return;
}
isRunning = true;
clearState();
onStart();
}
@ -323,8 +320,8 @@ public abstract class AbsGroupUtil implements IUtil {
mFailMap.clear();
}
void closeTimer(boolean isRunning) {
this.isRunning = isRunning;
void closeTimer() {
isRunning = false;
if (mTimer != null) {
mTimer.purge();
mTimer.cancel();
@ -336,7 +333,7 @@ public abstract class AbsGroupUtil implements IUtil {
* 开始进度流程
*/
void startRunningFlow() {
closeTimer(true);
closeTimer();
mListener.onPostPre(mTotalLen);
if (mCurrentLocation > 0) {
mListener.onResume(mCurrentLocation);
@ -347,11 +344,12 @@ public abstract class AbsGroupUtil implements IUtil {
}
private void startTimer() {
isRunning = true;
mTimer = new Timer(true);
mTimer.schedule(new TimerTask() {
@Override public void run() {
if (!isRunning) {
closeTimer(false);
closeTimer();
} else if (mCurrentLocation >= 0) {
long t = 0;
for (DownloadTaskEntity te : mGTEntity.getSubTaskEntities()) {
@ -455,7 +453,7 @@ public abstract class AbsGroupUtil implements IUtil {
synchronized (AbsGroupUtil.LOCK) {
mStopNum++;
if (mStopNum + mCompleteNum + mFailMap.size() == mGroupSize && !isStop) {
closeTimer(false);
closeTimer();
mListener.onStop(mCurrentLocation);
}
}
@ -476,13 +474,13 @@ public abstract class AbsGroupUtil implements IUtil {
mCompleteNum++;
//如果子任务完成的数量和总任务数一致,表示任务组任务已经完成
if (mCompleteNum == mGroupSize) {
closeTimer(false);
closeTimer();
mListener.onComplete();
} else if (mFailMap.size() > 0
&& mStopNum + mCompleteNum + mFailMap.size() >= mGroupSize
&& !isStop) {
//如果子任务完成数量加上失败的数量和总任务数一致,则任务组停止下载
closeTimer(false);
closeTimer();
mListener.onStop(mCurrentLocation);
}
}
@ -511,7 +509,7 @@ public abstract class AbsGroupUtil implements IUtil {
mFailMap.put(subTaskEntity.getUrl(), subTaskEntity);
mListener.onSubFail(subEntity);
if (mFailMap.size() == mExeMap.size() || mFailMap.size() + mCompleteNum == mGroupSize) {
closeTimer(false);
closeTimer();
}
if (mFailMap.size() == mGroupSize) {
mListener.onFail(true);

@ -164,7 +164,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
private void checkStartFlow() {
synchronized (DownloadGroupUtil.class) {
if (mInitFailNum == mExeNum) {
closeTimer(false);
closeTimer();
mListener.onFail(true);
}
if (!isStart && mInitCompleteNum + mInitFailNum == mExeNum || !isNeedLoadFileSize) {

@ -207,6 +207,8 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
if (isBreak()) {
return;
}
if (mChildCurrentLocation == mConfig.END_LOCATION) {
//支持断点的处理
if (mConfig.SUPPORT_BP) {
ALog.i(TAG,
@ -236,5 +238,8 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
STATE.isRunning = false;
mListener.onComplete();
}
} else {
STATE.FAIL_NUM++;
}
}
}

@ -70,11 +70,15 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
mCachePool.clear();
for (String key : mExecutePool.getAllTask().keySet()) {
TASK task = mExecutePool.getAllTask().get(key);
if (task != null && (task.isRunning() || task.getState() == IEntity.STATE_FAIL)) {
if (task != null) {
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 {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
publishVersion = '3.4.4_dev2'
publishVersion = '3.4.4_dev4'
// publishVersion = '1.0.3' //FTP插件
repoName='maven'
desc = 'android 下载框架'

Loading…
Cancel
Save