修复普通下载任务、组合任务共享执行队列、缓存池的问题

修复组合任务启动失败时,`DownloadGroupEntity`的状态变为执行中的问题
fix bug https://github.com/AriaLyy/Aria/issues/441
v3.6.6
laoyuyu 5 years ago
parent 1fb9f13dae
commit 558c9e1223
  1. 6
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  2. 6
      Aria/src/main/java/com/arialyy/aria/core/common/ThreadStateManager.java
  3. 13
      Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupUtil.java
  4. 6
      Aria/src/main/java/com/arialyy/aria/core/download/group/DGroupUtil.java
  5. 4
      Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java
  6. 10
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  7. 31
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadExecutePool.java
  8. 16
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadSharePool.java
  9. 4
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadExecutePool.java
  10. 41
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadSharePool.java
  11. 4
      Aria/src/main/java/com/arialyy/aria/orm/DelegateCommon.java
  12. 15
      Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java
  13. 12
      Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java
  14. 21
      Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
  15. 4
      app/src/main/assets/aria_config.xml
  16. 8
      app/src/main/java/com/arialyy/simple/core/download/multi_download/MultiDownloadActivity.java
  17. 21
      app/src/main/res/values/strings.xml
  18. 2
      build.gradle

@ -201,10 +201,12 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAPPER
* @param state {@link IThreadState#STATE_STOP}..
* @param bundle 而外数据
*/
void sendState(int state, @Nullable Bundle bundle) {
synchronized void sendState(int state, @Nullable Bundle bundle) {
Message msg = mStateHandler.obtainMessage();
msg.what = state;
msg.obj = this;
if (state != IThreadState.STATE_UPDATE_PROGRESS) {
msg.obj = this;
}
if ((state == IThreadState.STATE_COMPLETE || state == IThreadState.STATE_FAIL)
&& (mTaskWrapper.getRequestType() == AbsTaskWrapper.M3U8_VOD

@ -96,12 +96,14 @@ public class ThreadStateManager implements IThreadState {
}
break;
case STATE_RUNNING:
mProgress += (long) msg.obj;
if (msg.obj instanceof Long) {
mProgress += (long) msg.obj;
}
break;
case STATE_UPDATE_PROGRESS:
if (msg.obj == null) {
mProgress = updateBlockProgress();
} else {
} else if (msg.obj instanceof Long) {
mProgress = (long) msg.obj;
}
break;

@ -211,12 +211,19 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
closeTimer();
return;
}
onStart();
startRunningFlow();
if (onStart()) {
startRunningFlow();
}
}
protected void onStart() {
/**
* 处理启动前的检查获取组合任务大小
*
* @return {@code false} 将不再走后续流程任务介绍
*/
protected boolean onStart() {
return false;
}
synchronized void closeTimer() {

@ -68,8 +68,7 @@ public class DGroupUtil extends AbsGroupUtil implements IUtil {
return false;
}
@Override protected void onStart() {
super.onStart();
@Override protected boolean onStart() {
if (mState.getCompleteNum() == mState.getSubSize()) {
mListener.onComplete();
} else {
@ -84,6 +83,7 @@ public class DGroupUtil extends AbsGroupUtil implements IUtil {
} catch (InterruptedException e) {
e.printStackTrace();
}
return getLenComplete;
} else {
for (DTaskWrapper wrapper : mGTWrapper.getSubTaskWrapper()) {
if (wrapper.getState() != IEntity.STATE_COMPLETE) {
@ -92,6 +92,7 @@ public class DGroupUtil extends AbsGroupUtil implements IUtil {
}
}
}
return true;
}
/**
@ -137,6 +138,7 @@ public class DGroupUtil extends AbsGroupUtil implements IUtil {
*/
private void checkGetSizeComplete(int count, int failCount) {
if (failCount == mGTWrapper.getSubTaskWrapper().size()) {
mState.isRunning = false;
mListener.onFail(false, new AriaIOException(TAG, "获取子任务长度失败"));
notifyLock();
return;

@ -38,8 +38,7 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
return FTP_DIR;
}
@Override protected void onStart() {
super.onStart();
@Override protected boolean onStart() {
if (mGTWrapper.getEntity().getFileSize() > 1) {
startDownload();
} else {
@ -57,6 +56,7 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
});
new Thread(infoThread).start();
}
return true;
}
private void startDownload() {

@ -26,7 +26,8 @@ import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.core.queue.pool.BaseCachePool;
import com.arialyy.aria.core.queue.pool.BaseExecutePool;
import com.arialyy.aria.core.queue.pool.DownloadSharePool;
import com.arialyy.aria.core.queue.pool.DGLoadSharePool;
import com.arialyy.aria.core.queue.pool.DLoadSharePool;
import com.arialyy.aria.core.queue.pool.UploadSharePool;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.util.ALog;
@ -47,9 +48,12 @@ public abstract class AbsTaskQueue<TASK extends AbsTask, TASK_WRAPPER extends Ab
AbsTaskQueue() {
switch (getQueueType()) {
case TYPE_D_QUEUE:
mCachePool = DLoadSharePool.getInstance().cachePool;
mExecutePool = DLoadSharePool.getInstance().executePool;
break;
case TYPE_DG_QUEUE:
mCachePool = DownloadSharePool.getInstance().cachePool;
mExecutePool = DownloadSharePool.getInstance().executePool;
mCachePool = DGLoadSharePool.getInstance().cachePool;
mExecutePool = DGLoadSharePool.getInstance().executePool;
break;
case TYPE_U_QUEUE:
mCachePool = UploadSharePool.getInstance().cachePool;

@ -0,0 +1,31 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.queue.pool;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsTask;
/**
* Created by AriaL on 2017/6/29.
* 单个下载任务的执行池
*/
class DGLoadExecutePool<TASK extends AbsTask> extends DLoadExecutePool<TASK> {
private final String TAG = "DGLoadExecutePool";
@Override protected int getMaxSize() {
return AriaManager.getInstance(AriaManager.APP).getDGroupConfig().getMaxTaskNum();
}
}

@ -19,21 +19,21 @@ package com.arialyy.aria.core.queue.pool;
* Created by Aria.Lao on 2017/7/17.
* 下载任务池该池子为简单任务和任务组共用
*/
public class DownloadSharePool {
private static volatile DownloadSharePool INSTANCE;
public class DGLoadSharePool {
private static volatile DGLoadSharePool INSTANCE;
public DownloadExecutePool executePool;
public DGLoadExecutePool executePool;
public BaseCachePool cachePool;
private DownloadSharePool() {
executePool = new DownloadExecutePool<>();
private DGLoadSharePool() {
executePool = new DGLoadExecutePool<>();
cachePool = new BaseCachePool<>();
}
public static DownloadSharePool getInstance() {
public static DGLoadSharePool getInstance() {
if (INSTANCE == null) {
synchronized (DownloadSharePool.class) {
INSTANCE = new DownloadSharePool();
synchronized (DGLoadSharePool.class) {
INSTANCE = new DGLoadSharePool();
}
}
return INSTANCE;

@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit;
* Created by AriaL on 2017/6/29.
* 单个下载任务的执行池
*/
class DownloadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> {
class DLoadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> {
private final String TAG = "DownloadExecutePool";
@Override protected int getMaxSize() {
@ -34,7 +34,7 @@ class DownloadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> {
}
@Override public boolean putTask(TASK task) {
synchronized (DownloadExecutePool.class) {
synchronized (DLoadExecutePool.class) {
if (task == null) {
ALog.e(TAG, "任务不能为空!!");
return false;

@ -0,0 +1,41 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.queue.pool;
/**
* Created by Aria.Lao on 2017/7/17.
* 下载任务池该池子为简单任务和任务组共用
*/
public class DLoadSharePool {
private static volatile DLoadSharePool INSTANCE;
public DLoadExecutePool executePool;
public BaseCachePool cachePool;
private DLoadSharePool() {
executePool = new DLoadExecutePool<>();
cachePool = new BaseCachePool<>();
}
public static DLoadSharePool getInstance() {
if (INSTANCE == null) {
synchronized (DLoadSharePool.class) {
INSTANCE = new DLoadSharePool();
}
}
return INSTANCE;
}
}

@ -106,7 +106,9 @@ class DelegateCommon extends AbsDelegate {
*/
boolean checkDataExist(SQLiteDatabase db, Class clazz, String... expression) {
db = checkDb(db);
CheckUtil.checkSqlExpression(expression);
if (!CheckUtil.checkSqlExpression(expression)) {
return false;
}
String sql = String.format("SELECT rowid, * FROM %s WHERE %s ", CommonUtil.getClassName(clazz),
expression[0]);
sql = sql.replace("?", "%s");

@ -15,7 +15,6 @@
*/
package com.arialyy.aria.orm;
import android.annotation.SuppressLint;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;
@ -30,10 +29,8 @@ import java.lang.reflect.Field;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Created by laoyuyu on 2018/3/22.
@ -201,7 +198,9 @@ class DelegateFind extends AbsDelegate {
.append(cTableName.concat(".").concat(m.entityColumn()));
String sql;
if (expression != null && expression.length > 0) {
CheckUtil.checkSqlExpression(expression);
if (!CheckUtil.checkSqlExpression(expression)) {
return null;
}
sb.append(" WHERE ").append(expression[0]).append(" ");
sql = sb.toString();
sql = sql.replace("?", "%s");
@ -321,7 +320,9 @@ class DelegateFind extends AbsDelegate {
*/
<T extends DbEntity> List<T> findData(SQLiteDatabase db, Class<T> clazz, String... expression) {
db = checkDb(db);
CheckUtil.checkSqlExpression(expression);
if (!CheckUtil.checkSqlExpression(expression)) {
return null;
}
String sql = String.format("SELECT rowid, * FROM %s WHERE %s", CommonUtil.getClassName(clazz),
expression[0]);
String[] params = new String[expression.length - 1];
@ -339,7 +340,9 @@ class DelegateFind extends AbsDelegate {
return null;
}
db = checkDb(db);
CheckUtil.checkSqlExpression(expression);
if (!CheckUtil.checkSqlExpression(expression)) {
return null;
}
String sql = String.format("SELECT rowid, * FROM %s WHERE %s LIMIT %s,%s",
CommonUtil.getClassName(clazz),
expression[0], (page - 1) * num, num);

@ -34,13 +34,15 @@ class DelegateUpdate extends AbsDelegate {
private DelegateUpdate() {
}
/**
/**
* 删除某条数据
*/
synchronized <T extends DbEntity> void delData(SQLiteDatabase db, Class<T> clazz,
String... expression) {
db = checkDb(db);
CheckUtil.checkSqlExpression(expression);
if (!CheckUtil.checkSqlExpression(expression)) {
return;
}
String sql = "DELETE FROM " + CommonUtil.getClassName(clazz) + " WHERE " + expression[0] + " ";
sql = sql.replace("?", "%s");
@ -60,7 +62,7 @@ class DelegateUpdate extends AbsDelegate {
ContentValues values = createValues(dbEntity);
if (values != null) {
db.update(CommonUtil.getClassName(dbEntity), values, "rowid=?",
new String[] {String.valueOf(dbEntity.rowID)});
new String[] { String.valueOf(dbEntity.rowID) });
} else {
ALog.e(TAG, "更新记录失败,记录没有属性字段");
}
@ -69,7 +71,7 @@ class DelegateUpdate extends AbsDelegate {
/**
* 更新多条记录
*/
synchronized <T extends DbEntity> void updateManyData(SQLiteDatabase db, List<T> dbEntities) {
synchronized <T extends DbEntity> void updateManyData(SQLiteDatabase db, List<T> dbEntities) {
db = checkDb(db);
db.beginTransaction();
try {
@ -84,7 +86,7 @@ class DelegateUpdate extends AbsDelegate {
if (value == null) {
ALog.e(TAG, "更新记录失败,记录没有属性字段");
} else {
db.update(table, value, "rowid=?", new String[] {String.valueOf(entity.rowID)});
db.update(table, value, "rowid=?", new String[] { String.valueOf(entity.rowID) });
}
}
db.setTransactionSuccessful();

@ -24,6 +24,7 @@ import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.ParamException;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -68,17 +69,22 @@ public class CheckUtil {
/**
* 检查sql的expression是否合法
*
* @return false 不合法
*/
public static void checkSqlExpression(String... expression) {
public static boolean checkSqlExpression(String... expression) {
if (expression.length == 0) {
throw new IllegalArgumentException("sql语句表达式不能为null");
ALog.e(TAG, "sql语句表达式不能为null");
return false;
}
if (expression.length == 1) {
throw new IllegalArgumentException("表达式需要写入参数");
ALog.e(TAG, String.format("表达式需要写入参数,参数信息:%s", Arrays.toString(expression)));
return false;
}
String where = expression[0];
if (!where.contains("?")) {
throw new IllegalArgumentException("请在where语句的'='后编写?");
ALog.e(TAG, String.format("请在where语句的'='后编写?,参数信息:%s", Arrays.toString(expression)));
return false;
}
Pattern pattern = Pattern.compile("\\?");
Matcher matcher = pattern.matcher(where);
@ -87,11 +93,14 @@ public class CheckUtil {
count++;
}
if (count < expression.length - 1) {
throw new IllegalArgumentException("条件语句的?个数不能小于参数个数");
ALog.e(TAG, String.format("条件语句的?个数不能小于参数个数,参数信息:%s", Arrays.toString(expression)));
return false;
}
if (count > expression.length - 1) {
throw new IllegalArgumentException("条件语句的?个数不能大于参数个数");
ALog.e(TAG, String.format("条件语句的?个数不能大于参数个数, 参数信息:%s", Arrays.toString(expression)));
return false;
}
return true;
}
/**

@ -113,7 +113,7 @@
<dGroup>
<!--组合任务下载队列最大任务数, 默认为2-->
<maxTaskNum value="1"/>
<maxTaskNum value="2"/>
<!--设置下载失败,重试次数,默认为10-->
<reTryNum value="1"/>
@ -131,7 +131,7 @@
<!-- =============================以下为子任务的配置====================================-->
<!--能同时下载的子任务最大任务数,默认3-->
<subMaxTaskNum value="1"/>
<subMaxTaskNum value="5"/>
<!--子任务下载失败时的重试次数,默认为5-->
<subReTryNum value="5"/>

@ -76,7 +76,7 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
Log.d(TAG, task.getTaskName() + ", " + task.getState());
}
@Download.onWait void onWait(DownloadTask task){
@Download.onWait void onWait(DownloadTask task) {
mAdapter.updateState(task.getEntity());
}
@ -139,8 +139,10 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
}
@DownloadGroup.onTaskFail void groupTaskFail(DownloadGroupTask task) {
ALog.d(TAG, String.format("group【%s】fail", task.getTaskName()));
mAdapter.updateState(task.getEntity());
if (task != null) {
ALog.d(TAG, String.format("group【%s】fail", task.getTaskName()));
mAdapter.updateState(task.getEntity());
}
}
@DownloadGroup.onTaskComplete void groupTaskComplete(DownloadGroupTask task) {

@ -106,16 +106,13 @@
</string-array>
<string-array name="group_urls">
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a65d84b914e6a6fef697637578b6db2eb1056d50b09cf1dcf289d4045df7ef95746e498e3d6a848ab84c89b77aa60194e2c48e5a7cb748265.apk</item>-->
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a52034c72752e8475414630ebc69318b84ef584115ebf5eaaab945ae07b7fe3596afc72a7940ff328d4a9553f6ae92d6c09ba4bfb533137f6.apk</item>-->
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a426f06bfc69034d69c44ae1a01da180cab8e59bd1a5e1a784bac46ba0c64579d14f0e80a4ce4f068af89b0369a393456f4f449a8829cad5c.apk</item>-->
<item>http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk</item>
<!--<item>http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk</item>-->
<item>https://downs.muzhiwan.com/2019/06/19/com.and.games505.TerrariaPaid5d0a074e451c0.gpk</item>
<item>https://downs.muzhiwan.com/2017/03/28/com.xyzstudio_58da07426e959.apk</item>
</string-array>
<string-array name="group_urls_1">
<item>http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk</item>
<item>https://atom-installer.github.com/v1.13.0/AtomSetup.exe1</item>
<!--<item>https://atom-installer.github.com/v1.13.0/AtomSetup.exe1</item>-->
<item>http://hzdown.muzhiwan.com/2017/09/05/com.mir.iphone.empire83jie.mzw_59ae6d5a3638d.apk</item>
</string-array>
@ -125,8 +122,8 @@
</string-array>
<string-array name="group_urls_3">
<item>http://apk500.bce.baidu-mgame.com/game/883000/883227/20170828102306_oem_5502845.apk?r=1</item>
<item>http://static.gaoshouyou.com/d/92/12/5592a647b8126755647abbe8074fde39.apk</item>
<item>https://downs.muzhiwan.com/2019/07/23/com.amazid.me_5d36bade614d9.apk</item>
<item>https://downs.muzhiwan.com/2019/07/30/com.counter.terrorist.attack.fps.sniper.fight_5d3fe8f0a7edf.apk</item>
</string-array>
<string-array name="group_url4">
@ -135,8 +132,8 @@
</string-array>
<string-array name="group_names">
<item>王者荣耀.apk</item>
<item>战斗吧剑灵.apk</item>
<item>泰拉瑞亚.apk</item>
<item>疯狂屁股.apk</item>
<!--<item>天魔幻想.apk</item>-->
</string-array>
@ -151,8 +148,8 @@
</string-array>
<string-array name="group_names_3">
<item>部落冲突.apk</item>
<item>城堡争霸.apk</item>
<item>神奇的绳索英雄.apk</item>
<item>自由火力反击.apk</item>
</string-array>
</resources>

@ -43,7 +43,7 @@ task clean(type: Delete) {
ext {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
publishVersion = '3.6.6_beta_1'
publishVersion = '3.6.6_beta_3'
// publishVersion = '1.0.4' //FTP插件
repoName='maven'
desc = 'android 下载框架'

Loading…
Cancel
Save