新增taskEntityManager
This commit is contained in:
@@ -69,14 +69,7 @@ import org.xml.sax.SAXException;
|
||||
public static final String DOWNLOAD_TEMP_DIR = "/Aria/temp/download/";
|
||||
public static final String UPLOAD_TEMP_DIR = "/Aria/temp/upload/";
|
||||
|
||||
public static final int LOG_LEVEL_VERBOSE = 2;
|
||||
public static final int LOG_LEVEL_DEBUG = 3;
|
||||
public static final int LOG_LEVEL_INFO = 4;
|
||||
public static final int LOG_LEVEL_WARN = 5;
|
||||
public static final int LOG_LEVEL_ERROR = 6;
|
||||
public static final int LOG_LEVEL_ASSERT = 7;
|
||||
public static final int LOG_CLOSE = 8;
|
||||
public static final int LOG_DEFAULT = LOG_LEVEL_DEBUG;
|
||||
|
||||
|
||||
@SuppressLint("StaticFieldLeak") private static volatile AriaManager INSTANCE = null;
|
||||
private Map<String, AbsReceiver> mReceivers = new ConcurrentHashMap<>();
|
||||
@@ -108,7 +101,7 @@ import org.xml.sax.SAXException;
|
||||
/**
|
||||
* 设置Aria 日志级别
|
||||
*
|
||||
* @param level {@link #LOG_LEVEL_VERBOSE}
|
||||
* @param level {@link ALog#LOG_LEVEL_VERBOSE}
|
||||
*/
|
||||
public void setLogLevel(int level) {
|
||||
ALog.LOG_LEVEL = level;
|
||||
|
@@ -23,6 +23,7 @@ import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||
@@ -161,6 +162,7 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
|
||||
* @return 创建的任务
|
||||
*/
|
||||
AbsTask createTask(AbsTaskEntity taskEntity) {
|
||||
TEManager.getInstance().addTEntity(taskEntity);
|
||||
return mQueue.createTask(mTargetName, taskEntity);
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package com.arialyy.aria.core.command.normal;
|
||||
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
|
@@ -24,6 +24,7 @@ import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||
|
@@ -367,6 +367,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
mFixedThreadPool.execute(task);
|
||||
}
|
||||
}
|
||||
mTaskEntity.isNewTask = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -83,11 +83,12 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
|
||||
failDownload("文件不存在,任务链接【" + mTaskEntity.urlEntity.url + "】", false);
|
||||
FTPFile[] files1 = client.listFiles();
|
||||
if (files1.length > 0) {
|
||||
ALog.i(TAG, "路径【" + setRemotePath() + "】该下文件列表 ===================================");
|
||||
ALog.i(TAG, "路径【" + setRemotePath() + "】下的文件列表 ===================================");
|
||||
for (FTPFile file : files1) {
|
||||
ALog.d(TAG, file.toString());
|
||||
}
|
||||
ALog.i(TAG, "================================= --end-- ===================================");
|
||||
ALog.i(TAG,
|
||||
"================================= --end-- ===================================");
|
||||
}
|
||||
client.disconnect();
|
||||
return;
|
||||
@@ -206,7 +207,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
|
||||
client.setDataTimeout(10 * 1000);
|
||||
client.enterLocalPassiveMode();
|
||||
client.setFileType(FTP.BINARY_FILE_TYPE);
|
||||
client.setControlKeepAliveTimeout(5);
|
||||
client.setConnectTimeout(mConnectTimeOut);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@@ -107,8 +107,8 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
||||
+ mConfig.TEMP_FILE.getName()
|
||||
+ "】thread__"
|
||||
+ mConfig.THREAD_ID
|
||||
+ "__停止, stop location ==> "
|
||||
+ currentTemp);
|
||||
+ "__停止【停止位置: "
|
||||
+ currentTemp + "】");
|
||||
writeConfig(false, currentTemp);
|
||||
if (STATE.isStop()) {
|
||||
ALog.i(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】已停止");
|
||||
|
@@ -16,10 +16,10 @@
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.SubTaskManager;
|
||||
import com.arialyy.aria.core.inf.AbsDownloadTarget;
|
||||
import com.arialyy.aria.core.inf.AbsTarget;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTarget;
|
||||
import com.arialyy.aria.core.manager.SubTaskManager;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.io.File;
|
||||
@@ -45,20 +45,6 @@ abstract class BaseGroupTarget<TARGET extends AbsTarget, TASK_ENTITY extends Abs
|
||||
|
||||
private SubTaskManager mSubTaskManager;
|
||||
|
||||
/**
|
||||
* 查询任务组实体,如果数据库不存在该实体,则新创建一个新的任务组实体
|
||||
*/
|
||||
DownloadGroupEntity getDownloadGroupEntity() {
|
||||
DownloadGroupEntity entity =
|
||||
DbEntity.findFirst(DownloadGroupEntity.class, "groupName=?", mGroupName);
|
||||
if (entity == null) {
|
||||
entity = new DownloadGroupEntity();
|
||||
entity.setGroupName(mGroupName);
|
||||
entity.setUrls(mUrls);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子任务管理器
|
||||
*
|
||||
|
@@ -54,7 +54,7 @@ public class DownloadGroupEntity extends AbsGroupEntity {
|
||||
this.dirPath = dirPath;
|
||||
}
|
||||
|
||||
void setGroupName(String key) {
|
||||
public void setGroupName(String key) {
|
||||
this.groupName = key;
|
||||
}
|
||||
|
||||
|
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@@ -35,24 +34,23 @@ public class DownloadGroupTarget
|
||||
if (groupEntity.getUrls() != null && !groupEntity.getUrls().isEmpty()) {
|
||||
this.mUrls.addAll(groupEntity.getUrls());
|
||||
}
|
||||
init(groupEntity.getGroupName());
|
||||
mGroupName = CommonUtil.getMd5Code(groupEntity.getUrls());
|
||||
mTaskEntity = TEManager.getInstance()
|
||||
.getTEntity(DownloadGroupTaskEntity.class, mGroupName);
|
||||
if (mTaskEntity == null) {
|
||||
mTaskEntity =
|
||||
TEManager.getInstance().createTEntity(DownloadGroupTaskEntity.class, groupEntity);
|
||||
}
|
||||
mEntity = mTaskEntity.entity;
|
||||
}
|
||||
|
||||
DownloadGroupTarget(List<String> urls, String targetName) {
|
||||
this.mTargetName = targetName;
|
||||
this.mUrls = urls;
|
||||
init(CommonUtil.getMd5Code(urls));
|
||||
}
|
||||
|
||||
private void init(String key) {
|
||||
mGroupName = key;
|
||||
mTaskEntity = DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", key);
|
||||
mGroupName = CommonUtil.getMd5Code(urls);
|
||||
mTaskEntity = TEManager.getInstance().getTEntity(DownloadGroupTaskEntity.class, mGroupName);
|
||||
if (mTaskEntity == null) {
|
||||
mTaskEntity = new DownloadGroupTaskEntity();
|
||||
mTaskEntity.save(getDownloadGroupEntity());
|
||||
}
|
||||
if (mTaskEntity.entity == null || TextUtils.isEmpty(mTaskEntity.entity.getKey())) {
|
||||
mTaskEntity.save(getDownloadGroupEntity());
|
||||
mTaskEntity = TEManager.getInstance().createGTEntity(DownloadGroupTaskEntity.class, mUrls);
|
||||
}
|
||||
mEntity = mTaskEntity.entity;
|
||||
}
|
||||
|
@@ -17,8 +17,9 @@ package com.arialyy.aria.core.download;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.inf.AbsDownloadTarget;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@@ -39,7 +40,11 @@ public class DownloadTarget
|
||||
DownloadTarget(DownloadEntity entity, String targetName, boolean refreshInfo) {
|
||||
this.url = entity.getUrl();
|
||||
mTargetName = targetName;
|
||||
initTask(entity);
|
||||
mTaskEntity = TEManager.getInstance().getTEntity(DownloadTaskEntity.class, url);
|
||||
if (mTaskEntity == null) {
|
||||
mTaskEntity = TEManager.getInstance().createTEntity(DownloadTaskEntity.class, entity);
|
||||
}
|
||||
mEntity = mTaskEntity.entity;
|
||||
mTaskEntity.refreshInfo = refreshInfo;
|
||||
}
|
||||
|
||||
@@ -50,44 +55,12 @@ public class DownloadTarget
|
||||
DownloadTarget(String url, String targetName, boolean refreshInfo) {
|
||||
this.url = url;
|
||||
mTargetName = targetName;
|
||||
initTask(getEntity(url));
|
||||
mTaskEntity.refreshInfo = refreshInfo;
|
||||
}
|
||||
|
||||
private void initTask(DownloadEntity entity) {
|
||||
mTaskEntity =
|
||||
DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false' and url=?",
|
||||
entity.getDownloadPath(), entity.getUrl());
|
||||
mTaskEntity = TEManager.getInstance().getTEntity(DownloadTaskEntity.class, url);
|
||||
if (mTaskEntity == null) {
|
||||
mTaskEntity = new DownloadTaskEntity();
|
||||
mTaskEntity.save(entity);
|
||||
} else if (mTaskEntity.entity == null || TextUtils.isEmpty(mTaskEntity.entity.getUrl())) {
|
||||
mTaskEntity.save(entity);
|
||||
} else if (!mTaskEntity.entity.getUrl().equals(entity.getUrl())) { //处理地址切换而保存路径不变
|
||||
mTaskEntity.save(entity);
|
||||
mTaskEntity = TEManager.getInstance().createTEntity(DownloadTaskEntity.class, url);
|
||||
}
|
||||
mEntity = entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果任务存在,但是下载实体不存在,则通过下载地址获取下载实体
|
||||
*
|
||||
* @param downloadUrl 下载地址
|
||||
*/
|
||||
private DownloadEntity getEntity(String downloadUrl) {
|
||||
DownloadEntity entity =
|
||||
DownloadEntity.findFirst(DownloadEntity.class, "url=? and isGroupChild='false'",
|
||||
downloadUrl);
|
||||
if (entity == null) {
|
||||
entity = new DownloadEntity();
|
||||
entity.setUrl(downloadUrl);
|
||||
entity.setGroupChild(false);
|
||||
}
|
||||
File file = new File(entity.getDownloadPath());
|
||||
if (!file.exists()) {
|
||||
entity.setState(IEntity.STATE_WAIT);
|
||||
}
|
||||
return entity;
|
||||
mEntity = mTaskEntity.entity;
|
||||
mTaskEntity.refreshInfo = refreshInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +101,8 @@ public class DownloadTarget
|
||||
throw new IllegalArgumentException("保存路径不能为文件夹,路径需要是完整的文件路径,如:/mnt/sdcard/game.zip");
|
||||
}
|
||||
if (!downloadPath.equals(mEntity.getDownloadPath())) {
|
||||
if (!mTaskEntity.refreshInfo && DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=?", downloadPath)) {
|
||||
if (!mTaskEntity.refreshInfo && DbEntity.checkDataExist(DownloadEntity.class,
|
||||
"downloadPath=?", downloadPath)) {
|
||||
throw new IllegalArgumentException("保存路径【" + downloadPath + "】已经被其它任务占用,请设置其它保存路径");
|
||||
}
|
||||
File oldFile = new File(mEntity.getDownloadPath());
|
||||
|
@@ -18,6 +18,7 @@ package com.arialyy.aria.core.download;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.IUtil;
|
||||
import com.arialyy.aria.core.download.downloader.SimpleDownloadUtil;
|
||||
|
@@ -17,9 +17,8 @@ package com.arialyy.aria.core.download;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/7/26.
|
||||
@@ -30,22 +29,17 @@ public class FtpDirDownloadTarget
|
||||
private final String TAG = "FtpDirDownloadTarget";
|
||||
|
||||
FtpDirDownloadTarget(String url, String targetName) {
|
||||
init(url);
|
||||
mTargetName = targetName;
|
||||
mTaskEntity.urlEntity = CommonUtil.getFtpUrlInfo(url);
|
||||
mTaskEntity.requestType = AbsTaskEntity.FTP_DIR;
|
||||
init(url);
|
||||
}
|
||||
|
||||
private void init(String key) {
|
||||
mGroupName = key;
|
||||
mTaskEntity = DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", key);
|
||||
mTaskEntity = TEManager.getInstance().getTEntity(DownloadGroupTaskEntity.class, key);
|
||||
if (mTaskEntity == null) {
|
||||
mTaskEntity = new DownloadGroupTaskEntity();
|
||||
mTaskEntity.save(getDownloadGroupEntity());
|
||||
}
|
||||
if (mTaskEntity.entity == null) {
|
||||
mTaskEntity.save(getDownloadGroupEntity());
|
||||
mTaskEntity = TEManager.getInstance().createTEntity(DownloadGroupTaskEntity.class, key);
|
||||
}
|
||||
mTaskEntity.requestType = AbsTaskEntity.FTP_DIR;
|
||||
mEntity = mTaskEntity.entity;
|
||||
}
|
||||
|
||||
|
@@ -42,6 +42,37 @@ public class FtpDownloadTarget extends DownloadTarget {
|
||||
mTaskEntity.requestType = AbsTaskEntity.FTP;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文件保存文件夹路径
|
||||
* 关于文件名:
|
||||
* 1、如果保存路径是该文件的保存路径,如:/mnt/sdcard/file.zip,则使用路径中的文件名file.zip
|
||||
* 2、如果保存路径是文件夹路径,如:/mnt/sdcard/,则使用FTP服务器该文件的文件名
|
||||
*
|
||||
* @param downloadPath 路径必须为文件路径,不能为文件夹路径
|
||||
*/
|
||||
@Override public FtpDownloadTarget setDownloadPath(@NonNull String downloadPath) {
|
||||
if (TextUtils.isEmpty(downloadPath)) {
|
||||
throw new IllegalArgumentException("文件保持路径不能为null");
|
||||
}
|
||||
File file = new File(downloadPath);
|
||||
if (file.isDirectory()) {
|
||||
downloadPath += mEntity.getFileName();
|
||||
}
|
||||
if (!downloadPath.equals(mEntity.getDownloadPath())) {
|
||||
File oldFile = new File(mEntity.getDownloadPath());
|
||||
File newFile = new File(downloadPath);
|
||||
if (TextUtils.isEmpty(mEntity.getDownloadPath()) || oldFile.renameTo(newFile)) {
|
||||
mEntity.setDownloadPath(downloadPath);
|
||||
mEntity.setFileName(newFile.getName());
|
||||
mTaskEntity.key = downloadPath;
|
||||
mEntity.update();
|
||||
mTaskEntity.update();
|
||||
CommonUtil.renameDownloadConfig(oldFile.getName(), newFile.getName());
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置字符编码
|
||||
*/
|
||||
|
@@ -45,27 +45,6 @@ public abstract class AbsUploadTarget<TARGET extends AbsUploadTarget, ENTITY ext
|
||||
return (TARGET) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从数据中读取上传实体,如果数据库查不到,则新创建一个上传实体
|
||||
*
|
||||
* @param filePath 上传文件的文件路径
|
||||
*/
|
||||
protected UploadEntity getUploadEntity(String filePath) {
|
||||
UploadEntity entity = UploadEntity.findFirst(UploadEntity.class, "filePath=?", filePath);
|
||||
if (entity == null) {
|
||||
entity = new UploadEntity();
|
||||
//String regex = "[/|\\\\|//]";
|
||||
String regex = Regular.REG_FILE_NAME;
|
||||
Pattern p = Pattern.compile(regex);
|
||||
String[] strs = p.split(filePath);
|
||||
String fileName = strs[strs.length - 1];
|
||||
entity.setFileName(fileName);
|
||||
entity.setFilePath(filePath);
|
||||
entity.insert();
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载任务是否存在
|
||||
*/
|
||||
|
@@ -19,28 +19,33 @@ import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/11/1.
|
||||
* 任务实体工厂
|
||||
*/
|
||||
class DGTaskEntityFactory
|
||||
implements ITaskEntityFactory<DownloadGroupEntity, DownloadGroupTaskEntity> {
|
||||
private static final String TAG = "DTaskEntityFactory";
|
||||
private static volatile DGTaskEntityFactory INSTANCE = null;
|
||||
class DGTEntityFactory implements ITEntityFactory<DownloadGroupEntity, DownloadGroupTaskEntity>,
|
||||
IGTEntityFactory<DownloadGroupEntity, DownloadGroupTaskEntity> {
|
||||
private static final String TAG = "DTEntityFactory";
|
||||
private static volatile DGTEntityFactory INSTANCE = null;
|
||||
|
||||
private DGTaskEntityFactory() {
|
||||
private DGTEntityFactory() {
|
||||
}
|
||||
|
||||
public static DGTaskEntityFactory getInstance() {
|
||||
public static DGTEntityFactory getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (DGTaskEntityFactory.class) {
|
||||
INSTANCE = new DGTaskEntityFactory();
|
||||
synchronized (DGTEntityFactory.class) {
|
||||
INSTANCE = new DGTEntityFactory();
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过下载实体创建任务实体
|
||||
*/
|
||||
@Override public DownloadGroupTaskEntity create(DownloadGroupEntity entity) {
|
||||
DownloadGroupTaskEntity dgTaskEntity =
|
||||
DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", entity.getGroupName());
|
||||
@@ -53,4 +58,41 @@ class DGTaskEntityFactory
|
||||
}
|
||||
return dgTaskEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对于任务组,不能使用这个,可用于FTP文件夹下载
|
||||
*
|
||||
* @deprecated {@link #create(String, List)}
|
||||
*/
|
||||
@Override @Deprecated public DownloadGroupTaskEntity create(String key) {
|
||||
DownloadGroupTaskEntity dgTaskEntity =
|
||||
DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", key);
|
||||
if (dgTaskEntity == null) {
|
||||
dgTaskEntity = new DownloadGroupTaskEntity();
|
||||
dgTaskEntity.save(getDownloadGroupEntity(key, null));
|
||||
}
|
||||
if (dgTaskEntity.entity == null || TextUtils.isEmpty(dgTaskEntity.entity.getKey())) {
|
||||
dgTaskEntity.save(getDownloadGroupEntity(key, null));
|
||||
}
|
||||
dgTaskEntity.urlEntity = CommonUtil.getFtpUrlInfo(key);
|
||||
return dgTaskEntity;
|
||||
}
|
||||
|
||||
@Override public DownloadGroupTaskEntity create(String groupName, List<String> urls) {
|
||||
return create(getDownloadGroupEntity(groupName, urls));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询任务组实体,如果数据库不存在该实体,则新创建一个新的任务组实体
|
||||
*/
|
||||
private DownloadGroupEntity getDownloadGroupEntity(String groupName, List<String> urls) {
|
||||
DownloadGroupEntity entity =
|
||||
DbEntity.findFirst(DownloadGroupEntity.class, "groupName=?", groupName);
|
||||
if (entity == null) {
|
||||
entity = new DownloadGroupEntity();
|
||||
entity.setGroupName(groupName);
|
||||
entity.setUrls(urls);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
@@ -18,28 +18,33 @@ package com.arialyy.aria.core.manager;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/11/1.
|
||||
* 任务实体工厂
|
||||
*/
|
||||
class DTaskEntityFactory implements ITaskEntityFactory<DownloadEntity, DownloadTaskEntity> {
|
||||
private static final String TAG = "DTaskEntityFactory";
|
||||
private static volatile DTaskEntityFactory INSTANCE = null;
|
||||
class DTEntityFactory implements ITEntityFactory<DownloadEntity, DownloadTaskEntity> {
|
||||
private static final String TAG = "DTEntityFactory";
|
||||
private static volatile DTEntityFactory INSTANCE = null;
|
||||
|
||||
private DTaskEntityFactory() {
|
||||
private DTEntityFactory() {
|
||||
}
|
||||
|
||||
public static DTaskEntityFactory getInstance() {
|
||||
public static DTEntityFactory getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (DTaskEntityFactory.class) {
|
||||
INSTANCE = new DTaskEntityFactory();
|
||||
synchronized (DTEntityFactory.class) {
|
||||
INSTANCE = new DTEntityFactory();
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过下载实体创建任务实体
|
||||
*/
|
||||
@Override public DownloadTaskEntity create(DownloadEntity entity) {
|
||||
DownloadTaskEntity taskEntity =
|
||||
DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false' and url=?",
|
||||
@@ -54,4 +59,32 @@ class DTaskEntityFactory implements ITaskEntityFactory<DownloadEntity, DownloadT
|
||||
}
|
||||
return taskEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过下载地址创建任务实体
|
||||
*/
|
||||
@Override public DownloadTaskEntity create(String downloadUrl) {
|
||||
return create(getEntity(downloadUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果任务存在,但是下载实体不存在,则通过下载地址获取下载实体
|
||||
*
|
||||
* @param downloadUrl 下载地址
|
||||
*/
|
||||
private DownloadEntity getEntity(String downloadUrl) {
|
||||
DownloadEntity entity =
|
||||
DownloadEntity.findFirst(DownloadEntity.class, "url=? and isGroupChild='false'",
|
||||
downloadUrl);
|
||||
if (entity == null) {
|
||||
entity = new DownloadEntity();
|
||||
entity.setUrl(downloadUrl);
|
||||
entity.setGroupChild(false);
|
||||
}
|
||||
File file = new File(entity.getDownloadPath());
|
||||
if (!file.exists()) {
|
||||
entity.setState(IEntity.STATE_WAIT);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
@@ -17,18 +17,16 @@ package com.arialyy.aria.core.manager;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 任务组通过组创建任务
|
||||
* Created by Aria.Lao on 2017/11/1.
|
||||
*/
|
||||
interface IEntityFactory<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>> {
|
||||
/**
|
||||
* 通过信息实体创建任务实体
|
||||
*/
|
||||
TASK_ENTITY create(ENTITY entity);
|
||||
interface IGTEntityFactory<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>> {
|
||||
|
||||
/**
|
||||
* 通过key创建任务,只适应于单任务
|
||||
* 通过key创建任务
|
||||
*/
|
||||
TASK_ENTITY create(String key);
|
||||
TASK_ENTITY create(String groupName, List<String> urls);
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/11/1.
|
||||
*/
|
||||
interface IEntityFactory<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>> {
|
||||
interface ITEntityFactory<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>> {
|
||||
/**
|
||||
* 通过信息实体创建任务实体
|
||||
*/
|
||||
|
@@ -13,9 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.core;
|
||||
package com.arialyy.aria.core.manager;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.command.group.GroupCmdFactory;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
|
@@ -15,79 +15,194 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.manager;
|
||||
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/11/1.
|
||||
* 任务实体管理器,负责
|
||||
*/
|
||||
public class TaskEntityManager {
|
||||
public class TEManager {
|
||||
private static final String TAG = "TaskManager";
|
||||
private static volatile TaskEntityManager INSTANCE = null;
|
||||
private static volatile TEManager INSTANCE = null;
|
||||
private Map<String, AbsTaskEntity> map = new ConcurrentHashMap<>();
|
||||
private Lock lock;
|
||||
|
||||
public static TaskEntityManager getInstance() {
|
||||
public static TEManager getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (TaskEntityManager.class) {
|
||||
INSTANCE = new TaskEntityManager();
|
||||
synchronized (TEManager.class) {
|
||||
INSTANCE = new TEManager();
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过下载实体获取下载任务实体,如果查找不到任务实体,则重新创建任务实体
|
||||
*/
|
||||
public DownloadTaskEntity getDTEntity(DownloadEntity entity) {
|
||||
AbsTaskEntity tEntity = map.get(convertKey(entity.getKey()));
|
||||
if (tEntity == null || !(tEntity instanceof DownloadTaskEntity)) {
|
||||
tEntity = DTEntityFactory.getInstance().create(entity);
|
||||
map.put(convertKey(entity.getKey()), tEntity);
|
||||
}
|
||||
return (DownloadTaskEntity) tEntity;
|
||||
private TEManager() {
|
||||
lock = new ReentrantLock();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过下载实体获取下载任务组实体,如果查找不到任务组实体,则重新创建任务组实体
|
||||
* 通过key创建任务,只适应于单任务,不能用于HTTP任务组,可用于Ftp文件夹
|
||||
* 如果是任务组,请使用{@link #createGTEntity(Class, List)}
|
||||
*
|
||||
* @return 如果任务实体创建失败,返回null
|
||||
*/
|
||||
public DownloadGroupTaskEntity getDGTEntity(DownloadGroupEntity entity) {
|
||||
AbsTaskEntity tEntity = map.get(convertKey(entity.getKey()));
|
||||
if (tEntity == null || !(tEntity instanceof DownloadGroupTaskEntity)) {
|
||||
tEntity = DGTEntityFactory.getInstance().create(entity);
|
||||
map.put(convertKey(entity.getKey()), tEntity);
|
||||
public <TE extends AbsTaskEntity> TE createTEntity(Class<TE> clazz, String key) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
AbsTaskEntity tEntity = map.get(convertKey(key));
|
||||
if (tEntity == null || tEntity.getClass() != clazz) {
|
||||
ITEntityFactory factory = chooseFactory(clazz);
|
||||
if (factory == null) {
|
||||
ALog.e(TAG, "任务实体创建失败");
|
||||
return null;
|
||||
}
|
||||
tEntity = factory.create(key);
|
||||
map.put(convertKey(key), tEntity);
|
||||
}
|
||||
return (TE) tEntity;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return (DownloadGroupTaskEntity) tEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过下载实体获取下载任务组实体,如果查找不到任务组实体,则重新创建任务组实体
|
||||
* 创建任务组实体
|
||||
*
|
||||
* @return 如果任务实体创建失败,返回null
|
||||
*/
|
||||
public UploadTaskEntity getUTEntity(UploadEntity entity) {
|
||||
AbsTaskEntity tEntity = map.get(convertKey(entity.getKey()));
|
||||
if (tEntity == null || !(tEntity instanceof UploadTaskEntity)) {
|
||||
tEntity = UTEntityFactory.getInstance().create(entity);
|
||||
map.put(convertKey(entity.getKey()), tEntity);
|
||||
public <TE extends AbsTaskEntity> TE createGTEntity(Class<TE> clazz, List<String> urls) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
String groupName = CommonUtil.getMd5Code(urls);
|
||||
AbsTaskEntity tEntity = map.get(convertKey(groupName));
|
||||
if (tEntity == null || tEntity.getClass() != clazz) {
|
||||
IGTEntityFactory factory = chooseGroupFactory(clazz);
|
||||
if (factory == null) {
|
||||
ALog.e(TAG, "任务实体创建失败");
|
||||
return null;
|
||||
}
|
||||
tEntity = factory.create(groupName, urls);
|
||||
map.put(convertKey(groupName), tEntity);
|
||||
}
|
||||
return (TE) tEntity;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过实体创建任务
|
||||
*
|
||||
* @return 如果任务实体创建失败,返回null
|
||||
*/
|
||||
public <TE extends AbsTaskEntity> TE createTEntity(Class<TE> clazz, AbsEntity absEntity) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
AbsTaskEntity tEntity = map.get(convertKey(absEntity.getKey()));
|
||||
if (tEntity == null || tEntity.getClass() != clazz) {
|
||||
ITEntityFactory factory = chooseFactory(clazz);
|
||||
if (factory == null) {
|
||||
ALog.e(TAG, "任务实体创建失败");
|
||||
return null;
|
||||
}
|
||||
tEntity = factory.create(absEntity);
|
||||
map.put(convertKey(absEntity.getKey()), tEntity);
|
||||
}
|
||||
return (TE) tEntity;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private IGTEntityFactory chooseGroupFactory(Class clazz) {
|
||||
if (clazz == DownloadGroupTaskEntity.class) {
|
||||
return DGTEntityFactory.getInstance();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ITEntityFactory chooseFactory(Class clazz) {
|
||||
if (clazz == DownloadTaskEntity.class) {
|
||||
return DTEntityFactory.getInstance();
|
||||
} else if (clazz == UploadTaskEntity.class) {
|
||||
return UTEntityFactory.getInstance();
|
||||
} else if (clazz == DownloadGroupTaskEntity.class) {
|
||||
return DGTEntityFactory.getInstance();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从任务实体管理器中获取任务实体
|
||||
*/
|
||||
public <TE extends AbsTaskEntity> TE getTEntity(Class<TE> clazz, String key) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
AbsTaskEntity tEntity = map.get(convertKey(key));
|
||||
if (tEntity == null) {
|
||||
return null;
|
||||
} else {
|
||||
return (TE) tEntity;
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 向管理器中增加任务实体
|
||||
*
|
||||
* @return {@code false} 实体为null,添加失败
|
||||
*/
|
||||
public boolean addTEntity(AbsTaskEntity te) {
|
||||
if (te == null) {
|
||||
ALog.e(TAG, "任务实体添加失败");
|
||||
return false;
|
||||
}
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
return map.put(convertKey(te.key), te) != null;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return (UploadTaskEntity) tEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过key删除任务实体
|
||||
*/
|
||||
public AbsTaskEntity removeTEntity(String key) {
|
||||
return map.remove(convertKey(key));
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
return map.remove(convertKey(key));
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private String convertKey(String key) {
|
||||
return CommonUtil.encryptBASE64(key);
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
return CommonUtil.keyToHashKey(key);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -13,8 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.arialyy.aria.core;
|
||||
package com.arialyy.aria.core.manager;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@@ -26,14 +27,14 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* Created by Aria.Lao on 2017/9/1.
|
||||
* 任务管理器
|
||||
*/
|
||||
public class TaskManager {
|
||||
class TaskManager {
|
||||
private static final String TAG = "TaskManager";
|
||||
private static volatile TaskManager INSTANCE = null;
|
||||
private Map<String, AbsTask> map = new ConcurrentHashMap<>();
|
||||
|
||||
public static TaskManager getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (AriaManager.LOCK) {
|
||||
synchronized (TaskManager.class) {
|
||||
INSTANCE = new TaskManager();
|
||||
}
|
||||
}
|
||||
|
@@ -15,43 +15,67 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.manager;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.Regular;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/11/1.
|
||||
* 任务实体工厂
|
||||
*/
|
||||
class DTaskEntityFactory implements ITaskEntityFactory<DownloadEntity, DownloadTaskEntity> {
|
||||
private static final String TAG = "DTaskEntityFactory";
|
||||
private static volatile DTaskEntityFactory INSTANCE = null;
|
||||
class UTEntityFactory implements ITEntityFactory<UploadEntity, UploadTaskEntity> {
|
||||
private static final String TAG = "DTEntityFactory";
|
||||
private static volatile UTEntityFactory INSTANCE = null;
|
||||
|
||||
private DTaskEntityFactory() {
|
||||
private UTEntityFactory() {
|
||||
}
|
||||
|
||||
public static DTaskEntityFactory getInstance() {
|
||||
public static UTEntityFactory getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (DTaskEntityFactory.class) {
|
||||
INSTANCE = new DTaskEntityFactory();
|
||||
synchronized (UTEntityFactory.class) {
|
||||
INSTANCE = new UTEntityFactory();
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override public DownloadTaskEntity create(DownloadEntity entity) {
|
||||
DownloadTaskEntity taskEntity =
|
||||
DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false' and url=?",
|
||||
entity.getDownloadPath(), entity.getUrl());
|
||||
if (taskEntity == null) {
|
||||
taskEntity = new DownloadTaskEntity();
|
||||
taskEntity.save(entity);
|
||||
} else if (taskEntity.entity == null || TextUtils.isEmpty(taskEntity.entity.getUrl())) {
|
||||
taskEntity.save(entity);
|
||||
} else if (!taskEntity.entity.getUrl().equals(entity.getUrl())) { //处理地址切换而保存路径不变
|
||||
taskEntity.save(entity);
|
||||
@Override public UploadTaskEntity create(UploadEntity entity) {
|
||||
UploadTaskEntity uTaskEntity =
|
||||
DbEntity.findFirst(UploadTaskEntity.class, "key=?", entity.getFilePath());
|
||||
if (uTaskEntity == null) {
|
||||
uTaskEntity = new UploadTaskEntity();
|
||||
uTaskEntity.entity = entity;
|
||||
}
|
||||
return taskEntity;
|
||||
if (uTaskEntity.entity == null) {
|
||||
uTaskEntity.entity = entity;
|
||||
}
|
||||
return uTaskEntity;
|
||||
}
|
||||
|
||||
@Override public UploadTaskEntity create(String key) {
|
||||
return create(getUploadEntity(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从数据中读取上传实体,如果数据库查不到,则新创建一个上传实体
|
||||
*
|
||||
* @param filePath 上传文件的文件路径
|
||||
*/
|
||||
private UploadEntity getUploadEntity(String filePath) {
|
||||
UploadEntity entity = UploadEntity.findFirst(UploadEntity.class, "filePath=?", filePath);
|
||||
if (entity == null) {
|
||||
entity = new UploadEntity();
|
||||
//String regex = "[/|\\\\|//]";
|
||||
String regex = Regular.REG_FILE_NAME;
|
||||
Pattern p = Pattern.compile(regex);
|
||||
String[] strs = p.split(filePath);
|
||||
String fileName = strs[strs.length - 1];
|
||||
entity.setFileName(fileName);
|
||||
entity.setFilePath(filePath);
|
||||
entity.insert();
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.core.queue.pool.BaseCachePool;
|
||||
import com.arialyy.aria.core.queue.pool.BaseExecutePool;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
@@ -164,6 +165,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
|
||||
}
|
||||
|
||||
@Override public void removeTaskFormQueue(String key) {
|
||||
//TEManager.getInstance().removeTEntity(key);
|
||||
TASK task = mExecutePool.getTask(key);
|
||||
if (task != null) {
|
||||
ALog.d(TAG, "从执行池删除任务,删除" + (mExecutePool.removeTask(task) ? "成功" : "失败"));
|
||||
@@ -172,6 +174,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
|
||||
if (task != null) {
|
||||
ALog.d(TAG, "从缓存池删除任务,删除" + (mCachePool.removeTask(task) ? "成功" : "失败"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override public void reTryStart(TASK task) {
|
||||
|
@@ -17,7 +17,6 @@ package com.arialyy.aria.core.scheduler;
|
||||
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
@@ -26,6 +25,7 @@ import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.GroupSendParams;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.core.queue.ITaskQueue;
|
||||
import com.arialyy.aria.core.upload.UploadTask;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
@@ -175,6 +175,9 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
|
||||
handleFailTask(task);
|
||||
break;
|
||||
}
|
||||
if (what == CANCEL || what == COMPLETE) {
|
||||
TEManager.getInstance().removeTEntity(task.getKey());
|
||||
}
|
||||
callback(what, task);
|
||||
}
|
||||
|
||||
@@ -269,6 +272,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
|
||||
} else {
|
||||
mQueue.removeTaskFormQueue(task.getKey());
|
||||
startNextTask();
|
||||
TEManager.getInstance().removeTEntity(task.getKey());
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -281,7 +285,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
|
||||
private void startNextTask() {
|
||||
TASK newTask = mQueue.getNextTask();
|
||||
if (newTask == null) {
|
||||
ALog.d(TAG, "没有下一任务");
|
||||
ALog.i(TAG, "没有下一任务");
|
||||
return;
|
||||
}
|
||||
if (newTask.getState() == IEntity.STATE_WAIT) {
|
||||
|
@@ -17,10 +17,9 @@ package com.arialyy.aria.core.upload;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.FtpUrlEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsUploadTarget;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@@ -33,23 +32,22 @@ import java.io.File;
|
||||
public class FtpUploadTarget
|
||||
extends AbsUploadTarget<FtpUploadTarget, UploadEntity, UploadTaskEntity> {
|
||||
private final String TAG = "FtpUploadTarget";
|
||||
private FtpUrlEntity mUrlEntity;
|
||||
|
||||
FtpUploadTarget(String filePath, String targetName) {
|
||||
this.mTargetName = targetName;
|
||||
mTaskEntity = DbEntity.findFirst(UploadTaskEntity.class, "key=?", filePath);
|
||||
initTask(filePath);
|
||||
}
|
||||
|
||||
private void initTask(String filePath) {
|
||||
mTaskEntity = TEManager.getInstance().getTEntity(UploadTaskEntity.class, filePath);
|
||||
if (mTaskEntity == null) {
|
||||
mTaskEntity = new UploadTaskEntity();
|
||||
mTaskEntity.entity = getUploadEntity(filePath);
|
||||
mTaskEntity = TEManager.getInstance().createTEntity(UploadTaskEntity.class, filePath);
|
||||
}
|
||||
if (mTaskEntity.entity == null) {
|
||||
mTaskEntity.entity = getUploadEntity(filePath);
|
||||
}
|
||||
mTaskEntity.requestType = AbsTaskEntity.FTP;
|
||||
mEntity = mTaskEntity.entity;
|
||||
File file = new File(filePath);
|
||||
mEntity.setFileName(file.getName());
|
||||
mEntity.setFileSize(file.length());
|
||||
mTaskEntity.requestType = AbsTaskEntity.FTP;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -16,12 +16,9 @@
|
||||
package com.arialyy.aria.core.upload;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import com.arialyy.aria.core.inf.AbsDownloadTarget;
|
||||
import com.arialyy.aria.core.inf.AbsUploadTarget;
|
||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/2/28.
|
||||
@@ -31,18 +28,18 @@ public class UploadTarget extends AbsUploadTarget<UploadTarget, UploadEntity, Up
|
||||
|
||||
UploadTarget(String filePath, String targetName) {
|
||||
this.mTargetName = targetName;
|
||||
mTaskEntity = DbEntity.findFirst(UploadTaskEntity.class, "key=?", filePath);
|
||||
initTask(filePath);
|
||||
}
|
||||
|
||||
private void initTask(String filePath) {
|
||||
mTaskEntity = TEManager.getInstance().getTEntity(UploadTaskEntity.class, filePath);
|
||||
if (mTaskEntity == null) {
|
||||
mTaskEntity = new UploadTaskEntity();
|
||||
mTaskEntity.entity = getUploadEntity(filePath);
|
||||
}
|
||||
if (mTaskEntity.entity == null) {
|
||||
mTaskEntity.entity = getUploadEntity(filePath);
|
||||
mTaskEntity = TEManager.getInstance().createTEntity(UploadTaskEntity.class, filePath);
|
||||
}
|
||||
mEntity = mTaskEntity.entity;
|
||||
File file = new File(filePath);
|
||||
mEntity.setFileName(file.getName());
|
||||
mEntity.setFileSize(file.length());
|
||||
mEntity = mTaskEntity.entity;
|
||||
//http暂时不支持断点上传
|
||||
mTaskEntity.isSupportBP = false;
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ package com.arialyy.aria.util;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/10/25.
|
||||
@@ -27,7 +26,16 @@ import com.arialyy.aria.core.AriaManager;
|
||||
*/
|
||||
public class ALog {
|
||||
|
||||
public static int LOG_LEVEL = AriaManager.LOG_DEFAULT;
|
||||
public static final int LOG_LEVEL_VERBOSE = 2;
|
||||
public static final int LOG_LEVEL_DEBUG = 3;
|
||||
public static final int LOG_LEVEL_INFO = 4;
|
||||
public static final int LOG_LEVEL_WARN = 5;
|
||||
public static final int LOG_LEVEL_ERROR = 6;
|
||||
public static final int LOG_LEVEL_ASSERT = 7;
|
||||
public static final int LOG_CLOSE = 8;
|
||||
public static final int LOG_DEFAULT = LOG_LEVEL_DEBUG;
|
||||
|
||||
public static int LOG_LEVEL = LOG_DEFAULT;
|
||||
|
||||
public static int v(String tag, String msg) {
|
||||
return println(Log.VERBOSE, tag, msg);
|
||||
|
Reference in New Issue
Block a user