AriaLyy 7 years ago
parent 0959e7c67c
commit 3386b14dfc
  1. 6
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  2. 3
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java
  3. 3
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  4. 3
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java
  5. 89
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DQueueMapping.java
  6. 21
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadGroupSchedulers.java
  7. 23
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
  8. 6
      app/src/main/assets/aria_config.xml

@ -19,15 +19,9 @@ package com.arialyy.aria.core.command.normal;
import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.QueueMod;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.scheduler.DQueueMapping;
import com.arialyy.aria.orm.Primary;
/**
* Created by lyy on 2016/8/22.

@ -25,7 +25,6 @@ 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;
/**
@ -65,8 +64,6 @@ public class DownloadGroupTaskQueue
.createTask(targetName, entity, DownloadGroupSchedulers.getInstance());
entity.key = entity.getEntity().getGroupName();
mCachePool.putTask(task);
DQueueMapping.getInstance().addType(task.getKey(), DQueueMapping.QUEUE_TYPE_DOWNLOAD_GROUP);
} else {
Log.e(TAG, "target name 为 null!!");
}

@ -25,7 +25,6 @@ import com.arialyy.aria.core.download.DownloadTaskEntity;
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;
import java.util.Map;
@ -130,8 +129,6 @@ public class DownloadTaskQueue
.createTask(target, entity, DownloadSchedulers.getInstance());
entity.key = entity.getEntity().getDownloadPath();
mCachePool.putTask(task);
DQueueMapping.getInstance().addType(task.getKey(), DQueueMapping.QUEUE_TYPE_DOWNLOAD);
} else {
Log.e(TAG, "target name 为 null!!");
}

@ -21,7 +21,6 @@ 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;
import java.util.HashMap;
import java.util.Map;
@ -186,8 +185,6 @@ public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
String convertKey = CommonUtil.keyToHashKey(key);
TASK task = mExecuteMap.get(convertKey);
mExecuteMap.remove(convertKey);
DQueueMapping.getInstance().removeType(key);
return mExecuteQueue.remove(task);
}
}

@ -1,89 +0,0 @@
/*
* 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.scheduler;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Created by Aria.Lao on 2017/7/13.
* 下载任务和队列的映射表
*/
public class DQueueMapping {
public static final int QUEUE_TYPE_DOWNLOAD = 0xa1;
public static final int QUEUE_TYPE_DOWNLOAD_GROUP = 0xa2;
public static final int QUEUE_NONE = 0xab2;
private LinkedHashMap<String, Integer> types = new LinkedHashMap<>();
private static volatile DQueueMapping instance = null;
private DQueueMapping() {
}
public static DQueueMapping getInstance() {
if (instance == null) {
synchronized (AriaManager.LOCK) {
instance = new DQueueMapping();
}
}
return instance;
}
/**
* map中增加类型
*
* @param key 任务的key
* @param type {@link #QUEUE_TYPE_DOWNLOAD}{@link #QUEUE_TYPE_DOWNLOAD}
*/
public void addType(String key, int type) {
types.put(key, type);
}
/**
* @param key 任务的key
*/
public void removeType(String key) {
types.remove(key);
}
/**
* 获取下一个任务类型
*
* @return {@link #QUEUE_TYPE_DOWNLOAD}{@link #QUEUE_TYPE_DOWNLOAD}
*/
public int nextType() {
Iterator<Map.Entry<String, Integer>> iter = types.entrySet().iterator();
if (iter.hasNext()) {
Map.Entry<String, Integer> next = iter.next();
int type = next.getValue();
iter.remove();
return type;
}
return QUEUE_NONE;
}
public boolean canStart() {
return DownloadTaskQueue.getInstance().getCurrentExePoolNum()
+ DownloadGroupTaskQueue.getInstance().getCurrentExePoolNum() >= AriaManager.getInstance(
AriaManager.APP).getDownloadConfig().getMaxTaskNum();
}
}

@ -50,25 +50,4 @@ public class DownloadGroupSchedulers extends
@Override String getProxySuffix() {
return "$$DownloadGroupListenerProxy";
}
@Override protected void startNextTask() {
if (getExeTaskNum() + DownloadSchedulers.getInstance().getExeTaskNum()
>= AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum()) {
return;
}
if (!DownloadSchedulers.getInstance().hasNextTask()) {
nextSelf();
} else {
Integer nextType = DQueueMapping.getInstance().nextType();
if (nextType == DQueueMapping.QUEUE_TYPE_DOWNLOAD) {
DownloadSchedulers.getInstance().nextSelf();
} else {
nextSelf();
}
}
}
void nextSelf() {
super.startNextTask();
}
}

@ -16,13 +16,11 @@
package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask;
import java.nio.MappedByteBuffer;
/**
* Created by lyy on 2016/8/16.
@ -54,25 +52,4 @@ public class DownloadSchedulers
@Override String getProxySuffix() {
return "$$DownloadListenerProxy";
}
@Override protected void startNextTask() {
if (getExeTaskNum() + DownloadGroupSchedulers.getInstance().getExeTaskNum()
>= AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum()) {
return;
}
if (!DownloadGroupSchedulers.getInstance().hasNextTask()) {
nextSelf();
} else {
Integer nextType = DQueueMapping.getInstance().nextType();
if (nextType == DQueueMapping.QUEUE_TYPE_DOWNLOAD_GROUP) {
DownloadGroupSchedulers.getInstance().nextSelf();
} else {
nextSelf();
}
}
}
void nextSelf() {
super.startNextTask();
}
}

@ -8,10 +8,10 @@
<threadNum value="4"/>
<!--设置下载队列最大任务数, 默认为2-->
<maxTaskNum value="2"/>
<maxTaskNum value="4"/>
<!--设置下载失败,重试次数,默认为10-->
<reTryNum value="2"/>
<reTryNum value="10"/>
<!--设置重试间隔,单位为毫秒,默认2000毫秒-->
<reTryInterval value="5000"/>
@ -20,7 +20,7 @@
<connectTimeOut value="1000"/>
<!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒-->
<iOTimeOut value="200"/>
<iOTimeOut value="10000"/>
<!--设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢-->
<buffSize value="8192"/>

Loading…
Cancel
Save