Permalink
Browse files

3.1.2代码合并

  • Loading branch information...
AriaLyy committed May 31, 2017
2 parents d1d40f5 + e9d6baa commit 810b87aa99fd090a19b61431dfe4e25f494b9662
@@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 311
versionName "3.1.1"
versionCode 312
versionName "3.1.2"
}
buildTypes {
release {
@@ -100,7 +100,11 @@
/**
* 下载实体
*/
public static final String ENTITY = "DOWNLOAD_ENTITY";
public static final String DOWNLOAD_ENTITY = "DOWNLOAD_ENTITY";
/**
* 上传实体
*/
public static final String UPLOAD_ENTITY = "UPLOAD_ENTITY";
/**
* 位置
*/
@@ -86,7 +86,7 @@ public BaseConfig setMaxTaskNum(int maxTaskNum) {
oldMaxTaskNum = this.maxTaskNum;
this.maxTaskNum = maxTaskNum;
saveKey("maxTaskNum", maxTaskNum + "");
DownloadTaskQueue.getInstance().setDownloadNum(maxTaskNum);
DownloadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum);
return this;
}
@@ -69,6 +69,7 @@ public int getFailNum() {
return failNum;
}
@Override
public void setFailNum(int failNum) {
this.failNum = failNum;
}
@@ -208,7 +208,7 @@ public String getTargetName() {
// 发送停止下载的广播
Intent intent = CommonUtil.createIntent(mContext.getPackageName(), Aria.ACTION_STOP);
intent.putExtra(Aria.CURRENT_LOCATION, mEntity.getCurrentProgress());
intent.putExtra(Aria.ENTITY, mEntity);
intent.putExtra(Aria.DOWNLOAD_ENTITY, mEntity);
mContext.sendBroadcast(intent);
}
}
@@ -227,7 +227,7 @@ public String getTargetName() {
}
//发送取消下载的广播
Intent intent = CommonUtil.createIntent(mContext.getPackageName(), Aria.ACTION_CANCEL);
intent.putExtra(Aria.ENTITY, mEntity);
intent.putExtra(Aria.DOWNLOAD_ENTITY, mEntity);
mContext.sendBroadcast(intent);
}
}
@@ -285,7 +285,7 @@ public DownloadTask build() {
this.task = wTask.get();
this.downloadEntity = this.task.getDownloadEntity();
sendIntent = CommonUtil.createIntent(context.getPackageName(), Aria.ACTION_RUNNING);
sendIntent.putExtra(Aria.ENTITY, downloadEntity);
sendIntent.putExtra(Aria.DOWNLOAD_ENTITY, downloadEntity);
final AriaManager manager = AriaManager.getInstance(context);
isOpenBroadCast = manager.getDownloadConfig().isOpenBreadCast();
isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
@@ -406,7 +406,7 @@ private void sendIntent(String action, long location) {
downloadEntity.update();
if (!isOpenBroadCast) return;
Intent intent = CommonUtil.createIntent(context.getPackageName(), action);
intent.putExtra(Aria.ENTITY, downloadEntity);
intent.putExtra(Aria.DOWNLOAD_ENTITY, downloadEntity);
if (location != -1) {
intent.putExtra(Aria.CURRENT_LOCATION, location);
}
@@ -40,6 +40,13 @@
protected TASK_ENTITY taskEntity;
protected String targetName;
/**
* 将该任务优先级提到最高
*/
protected void setToFirst(){
}
/**
* 重定向后,新url的key,默认为location
*/
@@ -60,4 +60,6 @@
@Ignore public static final int STATE_CANCEL = 7;
public int getState();
public void setFailNum(int failNum);
}
@@ -16,6 +16,7 @@
package com.arialyy.aria.core.queue;
import android.util.Log;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.ITaskEntity;
@@ -24,8 +25,89 @@
/**
* Created by Aria.Lao on 2017/2/23.
* 任务队列
*/
abstract class AbsTaskQueue<TASK extends ITask, TASK_ENTITY extends ITaskEntity, ENTITY extends IEntity>
implements ITaskQueue<TASK, TASK_ENTITY, ENTITY> {
private final String TAG = "AbsTaskQueue";
CachePool<TASK> mCachePool = new CachePool<>();
ExecutePool<TASK> mExecutePool = null;
/**
* 获取任务执行池
*/
public ExecutePool getExecutePool() {
return mExecutePool;
}
/**
* 获取缓存池
*/
public CachePool getCachePool() {
return mCachePool;
}
/**
* 获取缓存任务数
*
* @return 获取缓存的任务数
*/
@Override public int cachePoolSize() {
return mCachePool.size();
}
/**
* 获取当前运行的任务数
*
* @return 当前正在执行的任务数
*/
@Override public int executePoolSize() {
return mExecutePool.size();
}
@Override public TASK getTask(String url) {
TASK task = mExecutePool.getTask(url);
if (task == null) {
task = mCachePool.getTask(url);
}
return task;
}
@Override public void startTask(TASK task) {
if (mExecutePool.putTask(task)) {
mCachePool.removeTask(task);
task.getEntity().setFailNum(0);
task.start();
}
}
@Override public void stopTask(TASK task) {
if (!task.isRunning()) Log.w(TAG, "停止任务失败,【任务已经停止】");
if (mExecutePool.removeTask(task)) {
task.stop();
} else {
task.stop();
Log.w(TAG, "停止任务失败,【任务已经停止】");
}
}
@Override public void reTryStart(TASK task) {
if (task == null) {
Log.w(TAG, "重试下载失败,task 为null");
return;
}
if (!task.isRunning()) {
task.start();
} else {
Log.w(TAG, "任务没有完全停止,重试下载失败");
}
}
@Override public void cancelTask(TASK task) {
task.cancel();
}
@Override public TASK getNextTask() {
return mCachePool.pollTask();
}
}
@@ -23,7 +23,6 @@
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.queue.pool.CachePool;
import com.arialyy.aria.core.queue.pool.ExecutePool;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
@@ -36,7 +35,6 @@
private static final String TAG = "DownloadTaskQueue";
private static volatile DownloadTaskQueue INSTANCE = null;
private static final Object LOCK = new Object();
private ExecutePool<DownloadTask> mExecutePool = new ExecutePool<>(true);
public static DownloadTaskQueue getInstance() {
if (INSTANCE == null) {
@@ -48,79 +46,10 @@ public static DownloadTaskQueue getInstance() {
}
private DownloadTaskQueue() {
mExecutePool = new ExecutePool<>(true);
}
/**
* 获取任务执行池
*/
public ExecutePool getExecutePool() {
return mExecutePool;
}
/**
* 获取缓存池
*/
public CachePool getCachePool() {
return mCachePool;
}
/**
* 获取当前运行的任务数
*
* @return 当前正在执行的任务数
*/
public int getCurrentTaskNum() {
return mExecutePool.size();
}
/**
* 获取缓存任务数
*
* @return 获取缓存的任务数
*/
public int getCacheTaskNum() {
return mCachePool.size();
}
@Override public void startTask(DownloadTask task) {
if (mExecutePool.putTask(task)) {
mCachePool.removeTask(task);
task.getDownloadEntity().setFailNum(0);
task.start();
}
}
@Override public void stopTask(DownloadTask task) {
if (!task.isRunning()) Log.w(TAG, "停止任务失败,【任务已经停止】");
if (mExecutePool.removeTask(task)) {
task.stop();
} else {
task.stop();
Log.w(TAG, "停止任务失败,【任务已经停止】");
}
}
@Override public void cancelTask(DownloadTask task) {
task.cancel();
}
@Override public void reTryStart(DownloadTask task) {
if (task == null) {
Log.w(TAG, "重试下载失败,task 为null");
return;
}
if (!task.isRunning()) {
task.start();
} else {
Log.w(TAG, "任务没有完全停止,重试下载失败");
}
}
@Override public int size() {
return mExecutePool.size();
}
@Override public void setDownloadNum(int downloadNum) {
@Override public void setMaxTaskNum(int downloadNum) {
//原始长度
int size = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum;
int diff = downloadNum - size;
@@ -164,14 +93,6 @@ public int getCacheTaskNum() {
return getTask(entity.getDownloadUrl());
}
@Override public DownloadTask getTask(String url) {
DownloadTask task = mExecutePool.getTask(url);
if (task == null) {
task = mCachePool.getTask(url);
}
return task;
}
@Override public void removeTask(DownloadEntity entity) {
DownloadTask task = mExecutePool.getTask(entity.getDownloadUrl());
if (task != null) {
@@ -183,7 +104,4 @@ public int getCacheTaskNum() {
}
}
@Override public DownloadTask getNextTask() {
return mCachePool.pollTask();
}
}
Oops, something went wrong.

0 comments on commit 810b87a

Please sign in to comment.