Skip to content
Permalink
Browse files

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

修复组合任务启动失败时,`DownloadGroupEntity`的状态变为执行中的问题
fix bug #441
  • Loading branch information...
AriaLyy committed Aug 5, 2019
1 parent 1fb9f13 commit 558c9e1223bc5ed2b0d8d2c6fe9a6207b2c30eaa
@@ -201,10 +201,12 @@ void breakTask() {
* @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 @@
}
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 @@ protected boolean onPreStop() {
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 DGroupUtil(IDGroupListener listener, DGTaskWrapper taskWrapper) {
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 DGroupUtil(IDGroupListener listener, DGTaskWrapper taskWrapper) {
} catch (InterruptedException e) {
e.printStackTrace();
}
return getLenComplete;
} else {
for (DTaskWrapper wrapper : mGTWrapper.getSubTaskWrapper()) {
if (wrapper.getState() != IEntity.STATE_COMPLETE) {
@@ -92,6 +92,7 @@ public DGroupUtil(IDGroupListener listener, DGTaskWrapper taskWrapper) {
}
}
}
return true;
}

/**
@@ -137,6 +138,7 @@ private void getGroupSize() {
*/
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 FtpDirDownloadUtil(IDGroupListener listener, DGTaskWrapper taskEntity) {
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 FtpDirDownloadUtil(IDGroupListener listener, DGTaskWrapper taskEntity) {
});
new Thread(infoThread).start();
}
return true;
}

private void startDownload() {
@@ -26,7 +26,8 @@
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 @@
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 @@
* 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,15 +26,15 @@
* 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() {
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
}

@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 @@ boolean tableExists(SQLiteDatabase db, String tableName) {
*/
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.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 @@ private DelegateFind() {
.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 @@ private DelegateFind() {
*/
<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 @@ private DelegateFind() {
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 @@
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 @@ synchronized void updateData(SQLiteDatabase db, DbEntity dbEntity) {
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 @@ synchronized void updateData(SQLiteDatabase db, DbEntity dbEntity) {
/**
* 更新多条记录
*/
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 @@ synchronized void updateData(SQLiteDatabase db, DbEntity dbEntity) {
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();

0 comments on commit 558c9e1

Please sign in to comment.
You can’t perform that action at this time.