任务组bug 修复
This commit is contained in:
@ -63,7 +63,9 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
if (mod.equals(QueueMod.NOW.getTag())) {
|
||||
mQueue.startTask(task);
|
||||
} else if (mod.equals(QueueMod.WAIT.getTag())) {
|
||||
if (mQueue.getCurrentExePoolNum() < maxTaskNum || task.getState() == IEntity.STATE_STOP) {
|
||||
if (mQueue.getCurrentExePoolNum() < maxTaskNum
|
||||
|| task.getState() == IEntity.STATE_STOP
|
||||
|| task.getState() == IEntity.STATE_COMPLETE) {
|
||||
mQueue.startTask(task);
|
||||
}
|
||||
}
|
||||
|
@ -128,6 +128,12 @@ final class DListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
|
||||
private void saveData(int state, long location) {
|
||||
if (state == IEntity.STATE_CANCEL) {
|
||||
entity.deleteData();
|
||||
} else if (state == IEntity.STATE_COMPLETE) {
|
||||
entity.setState(state);
|
||||
entity.setComplete(true);
|
||||
entity.setCompleteTime(System.currentTimeMillis());
|
||||
entity.setCurrentProgress(entity.getFileSize());
|
||||
entity.update();
|
||||
} else {
|
||||
entity.setState(state);
|
||||
if (location != -1) {
|
||||
|
@ -18,6 +18,7 @@ package com.arialyy.aria.core.download;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTarget;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.orm.DbUtil;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.io.File;
|
||||
@ -131,6 +132,7 @@ public class DownloadGroupTarget
|
||||
throw new NullPointerException("任务组文件夹保存路径不能为null");
|
||||
}
|
||||
|
||||
isSetDirPathed = true;
|
||||
if (mEntity.getDirPath().equals(groupDirPath)) return this;
|
||||
|
||||
File file = new File(groupDirPath);
|
||||
@ -148,12 +150,11 @@ public class DownloadGroupTarget
|
||||
mEntity.setSubTasks(createSubTask());
|
||||
}
|
||||
mEntity.update();
|
||||
isSetDirPathed = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 改变任务组文件夹路径
|
||||
* 改变任务组文件夹路径,修改文件夹路径会将子任务所有路径更换
|
||||
*
|
||||
* @param newDirPath 新的文件夹路径
|
||||
*/
|
||||
@ -161,8 +162,17 @@ public class DownloadGroupTarget
|
||||
List<DownloadEntity> subTask = mEntity.getSubTask();
|
||||
if (subTask != null && !subTask.isEmpty()) {
|
||||
for (DownloadEntity entity : subTask) {
|
||||
File file = new File(entity.getDownloadPath());
|
||||
file.renameTo(new File(newDirPath, entity.getFileName()));
|
||||
String oldPath = entity.getDownloadPath();
|
||||
String newPath = newDirPath + "/" + entity.getFileName();
|
||||
File file = new File(oldPath);
|
||||
file.renameTo(new File(newPath));
|
||||
DbEntity.exeSql("UPDATE DownloadEntity SET downloadPath='"
|
||||
+ newPath
|
||||
+ "' WHERE downloadPath='"
|
||||
+ oldPath
|
||||
+ "'");
|
||||
DbEntity.exeSql(
|
||||
"UPDATE DownloadTaskEntity SET key='" + newPath + "' WHERE key='" + oldPath + "'");
|
||||
}
|
||||
} else {
|
||||
mEntity.setSubTasks(createSubTask());
|
||||
@ -170,9 +180,9 @@ public class DownloadGroupTarget
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置子任务文件名,该方法如果在{@link #setDownloadDirPath(String)}之前调用,则不生效
|
||||
* 设置子任务文件名,该方法必须在{@link #setDownloadDirPath(String)}之后调用,否则不生效
|
||||
*/
|
||||
public DownloadGroupTarget setSubtaskFileName(List<String> subTaskFileName) {
|
||||
public DownloadGroupTarget setSubTaskFileName(List<String> subTaskFileName) {
|
||||
if (subTaskFileName == null || subTaskFileName.isEmpty()) return this;
|
||||
mSubTaskFileName.addAll(subTaskFileName);
|
||||
if (mUrls.size() != subTaskFileName.size()) {
|
||||
@ -182,13 +192,33 @@ public class DownloadGroupTarget
|
||||
List<DownloadEntity> entities = mEntity.getSubTask();
|
||||
int i = 0;
|
||||
for (DownloadEntity entity : entities) {
|
||||
entity.setFileName(mSubTaskFileName.get(i));
|
||||
entity.update();
|
||||
String newName = mSubTaskFileName.get(i);
|
||||
updateSubFileName(entity, newName);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新子任务文件名
|
||||
*/
|
||||
private void updateSubFileName(DownloadEntity entity, String newName) {
|
||||
if (!newName.equals(entity.getFileName())) {
|
||||
String oldPath = mEntity.getDirPath() + "/" + entity.getFileName();
|
||||
String newPath = mEntity.getDirPath() + "/" + newName;
|
||||
File file = new File(oldPath);
|
||||
if (file.exists()) {
|
||||
file.renameTo(new File(newPath));
|
||||
}
|
||||
DbEntity.exeSql(
|
||||
"UPDATE DownloadTaskEntity SET key='" + newPath + "' WHERE key='" + oldPath + "'");
|
||||
entity.setDownloadPath(newPath);
|
||||
entity.setFileName(newName);
|
||||
entity.update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建子任务
|
||||
*/
|
||||
|
@ -180,7 +180,8 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
* 获取普通下载任务列表
|
||||
*/
|
||||
@Override public List<DownloadEntity> getSimpleTaskList() {
|
||||
return DownloadEntity.findDatas(DownloadEntity.class, "isGroupChild=?", "false");
|
||||
return DownloadEntity.findDatas(DownloadEntity.class, "isGroupChild=? and downloadPath!=''",
|
||||
"false");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,6 +105,7 @@ public class DownloadGroupUtil implements IDownloadUtil {
|
||||
if (entity.isComplete() && file.exists()) {
|
||||
mTotalSize += entity.getFileSize();
|
||||
mCompleteNum++;
|
||||
mInitNum++;
|
||||
} else {
|
||||
mExeMap.put(entity.getDownloadUrl(), createChildDownloadTask(entity));
|
||||
}
|
||||
@ -376,7 +377,12 @@ public class DownloadGroupUtil implements IDownloadUtil {
|
||||
private void saveData(int state, long location) {
|
||||
entity.setState(state);
|
||||
entity.setComplete(state == IEntity.STATE_COMPLETE);
|
||||
entity.setCurrentProgress(location);
|
||||
if (entity.isComplete()) {
|
||||
entity.setCompleteTime(System.currentTimeMillis());
|
||||
entity.setCurrentProgress(entity.getFileSize());
|
||||
} else {
|
||||
entity.setCurrentProgress(location);
|
||||
}
|
||||
entity.update();
|
||||
}
|
||||
}
|
||||
|
@ -93,11 +93,13 @@ class Downloader implements Runnable, IDownloadUtil {
|
||||
try {
|
||||
if (!mTaskEntity.isSupportBP) {
|
||||
mThreadNum = 1;
|
||||
mConstance.THREAD_NUM = mThreadNum;
|
||||
handleNoSupportBreakpointDownload();
|
||||
} else {
|
||||
mThreadNum = isNewTask ? (mEntity.getFileSize() <= SUB_LEN ? 1
|
||||
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum())
|
||||
: mRealThreadNum;
|
||||
mConstance.THREAD_NUM = mThreadNum;
|
||||
mFixedThreadPool = Executors.newFixedThreadPool(mThreadNum);
|
||||
handleBreakpoint();
|
||||
}
|
||||
@ -298,7 +300,6 @@ class Downloader implements Runnable, IDownloadUtil {
|
||||
entity.CONFIG_FILE_PATH = mConfigFile.getPath();
|
||||
entity.IS_SUPPORT_BREAK_POINT = mTaskEntity.isSupportBP;
|
||||
entity.DOWNLOAD_TASK_ENTITY = mTaskEntity;
|
||||
mConstance.THREAD_NUM = mThreadNum;
|
||||
SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity);
|
||||
mTask.put(i, task);
|
||||
}
|
||||
@ -390,7 +391,6 @@ class Downloader implements Runnable, IDownloadUtil {
|
||||
entity.CONFIG_FILE_PATH = mConfigFile.getPath();
|
||||
entity.IS_SUPPORT_BREAK_POINT = mTaskEntity.isSupportBP;
|
||||
entity.DOWNLOAD_TASK_ENTITY = mTaskEntity;
|
||||
mConstance.THREAD_NUM = mThreadNum;
|
||||
SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity);
|
||||
mTask.put(0, task);
|
||||
mFixedThreadPool.execute(task);
|
||||
|
@ -45,10 +45,6 @@ final class StateConstance {
|
||||
FAIL_NUM = 0;
|
||||
}
|
||||
|
||||
void setThreadNum(int threadNum) {
|
||||
THREAD_NUM = threadNum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有子线程是否都已经停止下载
|
||||
*/
|
||||
|
@ -20,8 +20,6 @@ package com.arialyy.aria.core.inf;
|
||||
*/
|
||||
public abstract class AbsNormalTask<ENTITY extends AbsEntity> extends AbsTask<ENTITY> {
|
||||
|
||||
private boolean isHeighestTask = false;
|
||||
|
||||
/**
|
||||
* 暂停任务,并让任务处于等待状态
|
||||
*/
|
||||
@ -42,7 +40,5 @@ public abstract class AbsNormalTask<ENTITY extends AbsEntity> extends AbsTask<EN
|
||||
isHeighestTask = isHighestPriority;
|
||||
}
|
||||
|
||||
public boolean isHighestPriorityTask() {
|
||||
return isHeighestTask;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,6 +33,17 @@ public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY>
|
||||
private String mTargetName;
|
||||
protected Context mContext;
|
||||
|
||||
protected boolean isHeighestTask = false;
|
||||
|
||||
/**
|
||||
* 任务是否完成
|
||||
*
|
||||
* @return {@code true} 已经完成,{@code false} 未完成
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
return mEntity.isComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前下载进度
|
||||
*/
|
||||
@ -154,4 +165,8 @@ public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY>
|
||||
@Override public void setTargetName(String targetName) {
|
||||
this.mTargetName = targetName;
|
||||
}
|
||||
|
||||
public boolean isHighestPriorityTask() {
|
||||
return isHeighestTask;
|
||||
}
|
||||
}
|
||||
|
@ -35,9 +35,18 @@ import java.util.Set;
|
||||
abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsEntity>
|
||||
implements ITaskQueue<TASK, TASK_ENTITY, ENTITY> {
|
||||
private final String TAG = "AbsTaskQueue";
|
||||
BaseCachePool<TASK> mCachePool = new BaseCachePool<>();
|
||||
BaseCachePool<TASK> mCachePool;
|
||||
BaseExecutePool<TASK> mExecutePool;
|
||||
|
||||
AbsTaskQueue() {
|
||||
mCachePool = setCachePool();
|
||||
mExecutePool = setExecutePool();
|
||||
}
|
||||
|
||||
abstract BaseCachePool<TASK> setCachePool();
|
||||
|
||||
abstract BaseExecutePool<TASK> setExecutePool();
|
||||
|
||||
@Override public boolean taskIsRunning(String key) {
|
||||
return mExecutePool.getTask(key) != null;
|
||||
}
|
||||
|
@ -22,7 +22,9 @@ import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTask;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
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.scheduler.DQueueMapping;
|
||||
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
|
||||
|
||||
@ -46,7 +48,14 @@ public class DownloadGroupTaskQueue
|
||||
}
|
||||
|
||||
private DownloadGroupTaskQueue() {
|
||||
mExecutePool = new BaseExecutePool<>(true);
|
||||
}
|
||||
|
||||
@Override BaseCachePool<DownloadGroupTask> setCachePool() {
|
||||
return DownloadSharePool.getInstance().cachePool;
|
||||
}
|
||||
|
||||
@Override BaseExecutePool<DownloadGroupTask> setExecutePool() {
|
||||
return DownloadSharePool.getInstance().executePool;
|
||||
}
|
||||
|
||||
@Override public DownloadGroupTask createTask(String targetName, DownloadGroupTaskEntity entity) {
|
||||
|
@ -22,7 +22,9 @@ import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.queue.pool.DownloadExecutePool;
|
||||
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.scheduler.DQueueMapping;
|
||||
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
||||
import java.util.LinkedHashSet;
|
||||
@ -48,7 +50,14 @@ public class DownloadTaskQueue
|
||||
}
|
||||
|
||||
private DownloadTaskQueue() {
|
||||
mExecutePool = new DownloadExecutePool(true);
|
||||
}
|
||||
|
||||
@Override BaseCachePool<DownloadTask> setCachePool() {
|
||||
return DownloadSharePool.getInstance().cachePool;
|
||||
}
|
||||
|
||||
@Override BaseExecutePool<DownloadTask> setExecutePool() {
|
||||
return DownloadSharePool.getInstance().executePool;
|
||||
}
|
||||
|
||||
@Override public String getKey(DownloadEntity entity) {
|
||||
|
@ -19,7 +19,9 @@ package com.arialyy.aria.core.queue;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.queue.pool.BaseCachePool;
|
||||
import com.arialyy.aria.core.queue.pool.BaseExecutePool;
|
||||
import com.arialyy.aria.core.queue.pool.UploadSharePool;
|
||||
import com.arialyy.aria.core.scheduler.UploadSchedulers;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.core.upload.UploadTask;
|
||||
@ -43,7 +45,14 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity,
|
||||
}
|
||||
|
||||
private UploadTaskQueue() {
|
||||
mExecutePool = new BaseExecutePool<>(false);
|
||||
}
|
||||
|
||||
@Override BaseCachePool<UploadTask> setCachePool() {
|
||||
return UploadSharePool.getInstance().cachePool;
|
||||
}
|
||||
|
||||
@Override BaseExecutePool<UploadTask> setExecutePool() {
|
||||
return UploadSharePool.getInstance().executePool;
|
||||
}
|
||||
|
||||
@Override public String getKey(UploadEntity entity) {
|
||||
|
@ -19,6 +19,7 @@ package com.arialyy.aria.core.queue.pool;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.ITask;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.HashMap;
|
||||
@ -32,7 +33,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* Created by lyy on 2016/8/14.
|
||||
* 任务缓存池,所有下载任务最先缓存在这个池中
|
||||
*/
|
||||
public class BaseCachePool<TASK extends ITask> implements IPool<TASK> {
|
||||
public class BaseCachePool<TASK extends AbsTask> implements IPool<TASK> {
|
||||
private static final String TAG = "BaseCachePool";
|
||||
private static final int MAX_NUM = Integer.MAX_VALUE; //最大下载任务数
|
||||
private static final long TIME_OUT = 1000;
|
||||
|
@ -19,6 +19,7 @@ package com.arialyy.aria.core.queue.pool;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.ITask;
|
||||
import com.arialyy.aria.core.scheduler.DQueueMapping;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@ -31,23 +32,28 @@ import java.util.concurrent.TimeUnit;
|
||||
* Created by lyy on 2016/8/15.
|
||||
* 任务执行池,所有当前下载任务都该任务池中,默认下载大小为2
|
||||
*/
|
||||
public class BaseExecutePool<TASK extends ITask> implements IPool<TASK> {
|
||||
public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
|
||||
private final String TAG = "BaseExecutePool";
|
||||
final long TIME_OUT = 1000;
|
||||
ArrayBlockingQueue<TASK> mExecuteQueue;
|
||||
Map<String, TASK> mExecuteMap;
|
||||
protected int mSize;
|
||||
int mSize;
|
||||
|
||||
public BaseExecutePool(boolean isDownload) {
|
||||
if (isDownload) {
|
||||
mSize = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
|
||||
} else {
|
||||
mSize = AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum();
|
||||
}
|
||||
BaseExecutePool() {
|
||||
mSize = getMaxSize();
|
||||
mExecuteQueue = new ArrayBlockingQueue<>(mSize);
|
||||
mExecuteMap = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最大任务数配置
|
||||
*
|
||||
* @return {@link AriaManager#getDownloadConfig()} {@link AriaManager#getUploadConfig()},如果不设置,默认返回2
|
||||
*/
|
||||
protected int getMaxSize() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有正在执行的任务
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ package com.arialyy.aria.core.queue.pool;
|
||||
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -26,14 +26,14 @@ import java.util.concurrent.TimeUnit;
|
||||
* Created by AriaL on 2017/6/29.
|
||||
* 单个下载任务的执行池
|
||||
*/
|
||||
public class DownloadExecutePool extends BaseExecutePool<DownloadTask> {
|
||||
public class DownloadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> {
|
||||
private final String TAG = "DownloadExecutePool";
|
||||
|
||||
public DownloadExecutePool(boolean isDownload) {
|
||||
super(isDownload);
|
||||
@Override protected int getMaxSize() {
|
||||
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
|
||||
}
|
||||
|
||||
@Override public boolean putTask(DownloadTask task) {
|
||||
@Override public boolean putTask(TASK task) {
|
||||
synchronized (AriaManager.LOCK) {
|
||||
if (task == null) {
|
||||
Log.e(TAG, "任务不能为空!!");
|
||||
@ -62,7 +62,7 @@ public class DownloadExecutePool extends BaseExecutePool<DownloadTask> {
|
||||
|
||||
@Override boolean pollFirstTask() {
|
||||
try {
|
||||
DownloadTask oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
|
||||
TASK oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
|
||||
if (oldTask == null) {
|
||||
Log.e(TAG, "移除任务失败");
|
||||
return false;
|
||||
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/7/17.
|
||||
* 下载任务池,该池子为简单任务和任务组共用
|
||||
*/
|
||||
public class DownloadSharePool {
|
||||
private static volatile DownloadSharePool INSTANCE;
|
||||
|
||||
public DownloadExecutePool executePool;
|
||||
public BaseCachePool cachePool;
|
||||
|
||||
private DownloadSharePool() {
|
||||
executePool = new DownloadExecutePool<>();
|
||||
cachePool = new BaseCachePool<>();
|
||||
}
|
||||
|
||||
public static DownloadSharePool getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (AriaManager.LOCK) {
|
||||
INSTANCE = new DownloadSharePool();
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
@ -16,13 +16,13 @@
|
||||
|
||||
package com.arialyy.aria.core.queue.pool;
|
||||
|
||||
import com.arialyy.aria.core.inf.ITask;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/8/14.
|
||||
* 任务池
|
||||
*/
|
||||
interface IPool<T extends ITask> {
|
||||
interface IPool<T extends AbsTask> {
|
||||
/**
|
||||
* 将下载任务添加到任务池中
|
||||
*/
|
||||
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 Aria.Lao on 2017/7/17.
|
||||
*/
|
||||
public class UploadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> {
|
||||
@Override protected int getMaxSize() {
|
||||
return AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum();
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/7/17.
|
||||
* 下载任务池,该池子为简单任务和任务组共用
|
||||
*/
|
||||
public class UploadSharePool {
|
||||
private static volatile UploadSharePool INSTANCE;
|
||||
|
||||
public UploadExecutePool executePool;
|
||||
public BaseCachePool cachePool;
|
||||
|
||||
private UploadSharePool() {
|
||||
executePool = new UploadExecutePool();
|
||||
cachePool = new BaseCachePool<>();
|
||||
}
|
||||
|
||||
public static UploadSharePool getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (AriaManager.LOCK) {
|
||||
INSTANCE = new UploadSharePool();
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
@ -36,6 +36,13 @@ public class DbEntity {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接执行sql语句
|
||||
*/
|
||||
public static void exeSql(String sql) {
|
||||
DbUtil.getInstance().exeSql(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有数据
|
||||
*
|
||||
|
@ -64,6 +64,13 @@ public class DbUtil {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行sql语句
|
||||
*/
|
||||
void exeSql(String sql) {
|
||||
mDb.execSQL(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除某条数据
|
||||
*/
|
||||
|
@ -541,9 +541,11 @@ public class CommonUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件 当文件不存在的时候就创建一个文件,否则直接返回文件
|
||||
* 创建文件
|
||||
* 当文件不存在的时候就创建一个文件。
|
||||
* 如果文件存在,先删除原文件,然后重新创建一个新文件
|
||||
*/
|
||||
public static File createFile(String path) {
|
||||
public static void createFile(String path) {
|
||||
File file = new File(path);
|
||||
if (!file.getParentFile().exists()) {
|
||||
Log.d(TAG, "目标文件所在路径不存在,准备创建……");
|
||||
@ -552,19 +554,18 @@ public class CommonUtil {
|
||||
}
|
||||
}
|
||||
// 创建目标文件
|
||||
if (file.exists()) {
|
||||
final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
|
||||
file.renameTo(to);
|
||||
to.delete();
|
||||
}
|
||||
try {
|
||||
if (!file.exists()) {
|
||||
if (file.createNewFile()) {
|
||||
Log.d(TAG, "创建文件成功:" + file.getAbsolutePath());
|
||||
}
|
||||
return file;
|
||||
} else {
|
||||
return file;
|
||||
if (file.createNewFile()) {
|
||||
Log.d(TAG, "创建文件成功:" + file.getAbsolutePath());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user