重构任务实体,移除任务实体保存数据库的操作
This commit is contained in:
@@ -30,15 +30,15 @@ import com.arialyy.aria.core.command.ICmd;
|
||||
import com.arialyy.aria.core.common.QueueMod;
|
||||
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.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadReceiver;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.AbsReceiver;
|
||||
import com.arialyy.aria.core.inf.IReceiver;
|
||||
import com.arialyy.aria.core.inf.ReceiverType;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.core.upload.UploadReceiver;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.orm.DelegateWrapper;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
@@ -128,7 +128,7 @@ import org.xml.sax.SAXException;
|
||||
private void amendTaskState() {
|
||||
Class[] clazzs = new Class[] {
|
||||
DownloadEntity.class, UploadEntity.class, DownloadGroupEntity.class,
|
||||
DownloadTaskEntity.class, UploadTaskEntity.class, DownloadGroupTaskEntity.class
|
||||
DTaskWrapper.class, UTaskWrapper.class, DGTaskWrapper.class
|
||||
};
|
||||
String sql = "UPDATE %s SET state=2 WHERE state IN (3,4,5,6)";
|
||||
for (Class clazz : clazzs) {
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package com.arialyy.aria.core;
|
||||
|
||||
import com.arialyy.aria.core.common.ProtocolType;
|
||||
import com.arialyy.aria.orm.annotation.Ignore;
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
@@ -58,7 +57,6 @@ public class FtpUrlEntity implements Cloneable {
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@Ignore
|
||||
public String password;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
|
||||
package com.arialyy.aria.core.command;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.queue.ITaskQueue;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/6/29.
|
||||
*/
|
||||
public abstract class AbsCmd<T extends AbsTaskEntity> implements ICmd {
|
||||
public abstract class AbsCmd<T extends AbsTaskWrapper> implements ICmd {
|
||||
protected ITaskQueue mQueue;
|
||||
protected T mTaskEntity;
|
||||
protected T mTaskWrapper;
|
||||
protected String TAG;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.command;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/6/29.
|
||||
* 抽象命令工厂
|
||||
*/
|
||||
public abstract class AbsCmdFactory<TASK_ENTITY extends AbsTaskEntity, CMD extends AbsCmd> {
|
||||
public abstract class AbsCmdFactory<TASK_ENTITY extends AbsTaskWrapper, CMD extends AbsCmd> {
|
||||
|
||||
/**
|
||||
* @param entity 下载实体
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
package com.arialyy.aria.core.command.group;
|
||||
|
||||
import com.arialyy.aria.core.command.AbsCmd;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTask;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskWrapper;
|
||||
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@@ -28,7 +28,7 @@ import com.arialyy.aria.util.CommonUtil;
|
||||
* Created by AriaL on 2017/6/29.
|
||||
* 任务组命令
|
||||
*/
|
||||
public abstract class AbsGroupCmd<T extends AbsGroupTaskEntity> extends AbsCmd<T> {
|
||||
public abstract class AbsGroupCmd<T extends AbsGroupTaskWrapper> extends AbsCmd<T> {
|
||||
/**
|
||||
* 需要控制的子任务url
|
||||
*/
|
||||
@@ -37,9 +37,9 @@ public abstract class AbsGroupCmd<T extends AbsGroupTaskEntity> extends AbsCmd<T
|
||||
AbsGroupTask tempTask;
|
||||
|
||||
AbsGroupCmd(T entity) {
|
||||
mTaskEntity = entity;
|
||||
mTaskWrapper = entity;
|
||||
TAG = CommonUtil.getClassName(this);
|
||||
if (entity instanceof DownloadGroupTaskEntity) {
|
||||
if (entity instanceof DGTaskWrapper) {
|
||||
mQueue = DownloadGroupTaskQueue.getInstance();
|
||||
isDownloadCmd = true;
|
||||
}
|
||||
@@ -51,12 +51,12 @@ public abstract class AbsGroupCmd<T extends AbsGroupTaskEntity> extends AbsCmd<T
|
||||
* @return 创建的任务
|
||||
*/
|
||||
AbsTask createTask() {
|
||||
tempTask = (AbsGroupTask) mQueue.createTask(mTaskEntity);
|
||||
tempTask = (AbsGroupTask) mQueue.createTask(mTaskWrapper);
|
||||
return tempTask;
|
||||
}
|
||||
|
||||
boolean checkTask() {
|
||||
tempTask = (AbsGroupTask) mQueue.getTask(mTaskEntity.getEntity().getKey());
|
||||
tempTask = (AbsGroupTask) mQueue.getTask(mTaskWrapper.getEntity().getKey());
|
||||
if (tempTask == null) {
|
||||
createTask();
|
||||
if (tempTask.isComplete()) {
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.command.group;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/6/29.
|
||||
* 删除任务组子任务
|
||||
*/
|
||||
class GroupCancelCmd<T extends AbsGroupTaskEntity> extends AbsGroupCmd<T> {
|
||||
class GroupCancelCmd<T extends AbsGroupTaskWrapper> extends AbsGroupCmd<T> {
|
||||
GroupCancelCmd(T entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
package com.arialyy.aria.core.command.group;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/6/29.
|
||||
* 任务组子任务控制命令
|
||||
* Created by AriaL on 2017/6/29. 任务组子任务控制命令
|
||||
*/
|
||||
public class GroupCmdFactory {
|
||||
/**
|
||||
@@ -53,22 +53,22 @@ public class GroupCmdFactory {
|
||||
|
||||
/**
|
||||
* @param target 创建任务的对象
|
||||
* @param entity 下载实体
|
||||
* @param wrapper 参数信息
|
||||
* @param type 命令类型{@link #SUB_TASK_START}、{@link #SUB_TASK_STOP}、{@link #SUB_TASK_CANCEL}
|
||||
* @param childUrl 需要控制的子任务url
|
||||
*/
|
||||
public AbsGroupCmd createCmd(String target, AbsGroupTaskEntity entity, int type,
|
||||
public AbsGroupCmd createCmd(String target, AbsGroupTaskWrapper wrapper, int type,
|
||||
String childUrl) {
|
||||
AbsGroupCmd cmd = null;
|
||||
switch (type) {
|
||||
case SUB_TASK_START:
|
||||
cmd = new GroupStartCmd<>(entity);
|
||||
cmd = new GroupStartCmd<>(wrapper);
|
||||
break;
|
||||
case SUB_TASK_STOP:
|
||||
cmd = new GroupStopCmd<>(entity);
|
||||
cmd = new GroupStopCmd<>(wrapper);
|
||||
break;
|
||||
case SUB_TASK_CANCEL:
|
||||
cmd = new GroupCancelCmd<>(entity);
|
||||
cmd = new GroupCancelCmd<>(wrapper);
|
||||
}
|
||||
if (cmd != null) {
|
||||
cmd.childUrl = childUrl;
|
||||
|
||||
@@ -15,15 +15,14 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.command.group;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/6/29.
|
||||
* 任务组开始命令,该命令负责处理任务组子任务的开始\恢复等工作
|
||||
* Created by AriaL on 2017/6/29. 任务组开始命令,该命令负责处理任务组子任务的开始\恢复等工作
|
||||
*/
|
||||
class GroupStartCmd<T extends AbsGroupTaskEntity> extends AbsGroupCmd<T> {
|
||||
GroupStartCmd( T entity) {
|
||||
super( entity);
|
||||
class GroupStartCmd<T extends AbsGroupTaskWrapper> extends AbsGroupCmd<T> {
|
||||
GroupStartCmd(T wrapper) {
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
@Override public void executeCmd() {
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.command.group;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/6/29.
|
||||
* 停止任务组的命令
|
||||
*/
|
||||
class GroupStopCmd<T extends AbsGroupTaskEntity> extends AbsGroupCmd<T> {
|
||||
class GroupStopCmd<T extends AbsGroupTaskWrapper> extends AbsGroupCmd<T> {
|
||||
GroupStopCmd(T entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@@ -18,25 +18,25 @@ package com.arialyy.aria.core.command.normal;
|
||||
|
||||
import com.arialyy.aria.core.command.AbsCmd;
|
||||
import com.arialyy.aria.core.command.ICmd;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
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.inf.AbsTaskWrapper;
|
||||
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;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulers;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/8/22. 下载命令
|
||||
*/
|
||||
public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
|
||||
public abstract class AbsNormalCmd<T extends AbsTaskWrapper> extends AbsCmd<T> {
|
||||
/**
|
||||
* 能否执行命令
|
||||
*/
|
||||
@@ -51,22 +51,22 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
|
||||
*/
|
||||
AbsNormalCmd(T entity, int taskType) {
|
||||
this.taskType = taskType;
|
||||
mTaskEntity = entity;
|
||||
mTaskWrapper = entity;
|
||||
TAG = CommonUtil.getClassName(this);
|
||||
if (taskType == ICmd.TASK_TYPE_DOWNLOAD) {
|
||||
if (!(entity instanceof DownloadTaskEntity)) {
|
||||
if (!(entity instanceof DTaskWrapper)) {
|
||||
ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD");
|
||||
return;
|
||||
}
|
||||
mQueue = DownloadTaskQueue.getInstance();
|
||||
} else if (taskType == ICmd.TASK_TYPE_DOWNLOAD_GROUP) {
|
||||
if (!(entity instanceof DownloadGroupTaskEntity)) {
|
||||
if (!(entity instanceof DGTaskWrapper)) {
|
||||
ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD_GROUP");
|
||||
return;
|
||||
}
|
||||
mQueue = DownloadGroupTaskQueue.getInstance();
|
||||
} else if (taskType == ICmd.TASK_TYPE_UPLOAD) {
|
||||
if (!(entity instanceof UploadTaskEntity)) {
|
||||
if (!(entity instanceof UTaskWrapper)) {
|
||||
ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_UPLOAD");
|
||||
return;
|
||||
}
|
||||
@@ -92,9 +92,8 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
|
||||
*/
|
||||
void sendWaitState(AbsTask task) {
|
||||
if (task != null) {
|
||||
task.getTaskEntity().getEntity().setState(IEntity.STATE_WAIT);
|
||||
task.getTaskEntity().setState(IEntity.STATE_WAIT);
|
||||
task.getTaskEntity().update();
|
||||
task.getTaskWrapper().getEntity().setState(IEntity.STATE_WAIT);
|
||||
task.getTaskWrapper().setState(IEntity.STATE_WAIT);
|
||||
task.getOutHandler().obtainMessage(ISchedulers.WAIT, task).sendToTarget();
|
||||
}
|
||||
}
|
||||
@@ -125,7 +124,7 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
|
||||
/**
|
||||
* 删除任务
|
||||
*/
|
||||
void removeTask(AbsTaskEntity taskEntity) {
|
||||
void removeTask(AbsTaskWrapper taskEntity) {
|
||||
AbsTask tempTask = getTask(taskEntity.getEntity());
|
||||
if (tempTask == null) {
|
||||
tempTask = createTask(taskEntity);
|
||||
@@ -162,7 +161,7 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
|
||||
* @return 执行任务
|
||||
*/
|
||||
AbsTask getTask() {
|
||||
tempTask = mQueue.getTask(mTaskEntity.getEntity().getKey());
|
||||
tempTask = mQueue.getTask(mTaskWrapper.getEntity().getKey());
|
||||
return tempTask;
|
||||
}
|
||||
|
||||
@@ -182,7 +181,7 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
|
||||
* @return 创建的任务
|
||||
*/
|
||||
AbsTask createTask() {
|
||||
tempTask = mQueue.createTask(mTaskEntity);
|
||||
tempTask = mQueue.createTask(mTaskWrapper);
|
||||
return tempTask;
|
||||
}
|
||||
|
||||
@@ -192,7 +191,7 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
|
||||
* @param taskEntity 特定的任务实体
|
||||
* @return 创建的任务
|
||||
*/
|
||||
AbsTask createTask(AbsTaskEntity taskEntity) {
|
||||
AbsTask createTask(AbsTaskWrapper taskEntity) {
|
||||
TEManager.getInstance().addTEntity(taskEntity);
|
||||
return mQueue.createTask(taskEntity);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.arialyy.aria.core.command.normal;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.arialyy.aria.util.ALog;
|
||||
* Created by lyy on 2016/8/22.
|
||||
* 添加任务的命令
|
||||
*/
|
||||
class AddCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
class AddCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
|
||||
|
||||
AddCmd(T entity, int taskType) {
|
||||
super(entity, taskType);
|
||||
@@ -35,7 +35,7 @@ class AddCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
if (!canExeCmd) return;
|
||||
AbsTask task = getTask();
|
||||
if (task == null) {
|
||||
mTaskEntity.getEntity().setState(IEntity.STATE_WAIT);
|
||||
mTaskWrapper.getEntity().setState(IEntity.STATE_WAIT);
|
||||
createTask();
|
||||
sendWaitState();
|
||||
} else {
|
||||
|
||||
@@ -16,17 +16,17 @@
|
||||
|
||||
package com.arialyy.aria.core.command.normal;
|
||||
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
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.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
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;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
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.ALog;
|
||||
import java.util.List;
|
||||
@@ -35,7 +35,7 @@ import java.util.List;
|
||||
* Created by AriaL on 2017/6/27.
|
||||
* 删除所有任务,并且删除所有回掉
|
||||
*/
|
||||
public class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
public class CancelAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
|
||||
/**
|
||||
* removeFile {@code true} 删除已经下载完成的任务,不仅删除下载记录,还会删除已经下载完成的文件,{@code false}
|
||||
* 如果文件已经下载完成,只删除下载记录
|
||||
@@ -64,7 +64,7 @@ public class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
DbEntity.findDatas(DownloadEntity.class, "isGroupChild=?", "false");
|
||||
if (entities != null && !entities.isEmpty()) {
|
||||
for (DownloadEntity entity : entities) {
|
||||
remove(TEManager.getInstance().getTEntity(DownloadTaskEntity.class, entity.getKey()));
|
||||
remove(TEManager.getInstance().getTEntity(DTaskWrapper.class, entity.getKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
if (entities != null && !entities.isEmpty()) {
|
||||
for (DownloadGroupEntity entity : entities) {
|
||||
remove(
|
||||
TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, entity.getUrls()));
|
||||
TEManager.getInstance().getGTEntity(DGTaskWrapper.class, entity.getUrls()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,21 +91,21 @@ public class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
DbEntity.findDatas(UploadEntity.class, "isGroupChild=?", "false");
|
||||
if (entities != null && !entities.isEmpty()) {
|
||||
for (UploadEntity entity : entities) {
|
||||
remove(TEManager.getInstance().getTEntity(UploadTaskEntity.class, entity.getKey()));
|
||||
remove(TEManager.getInstance().getTEntity(UTaskWrapper.class, entity.getKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void remove(AbsTaskEntity te) {
|
||||
private void remove(AbsTaskWrapper te) {
|
||||
if (te == null){
|
||||
ALog.w(TAG, "取消任务失败,任务为空");
|
||||
return;
|
||||
}
|
||||
if (te instanceof DownloadTaskEntity) {
|
||||
if (te instanceof DTaskWrapper) {
|
||||
mQueue = DownloadTaskQueue.getInstance();
|
||||
} else if (te instanceof UploadTaskEntity) {
|
||||
} else if (te instanceof UTaskWrapper) {
|
||||
mQueue = UploadTaskQueue.getInstance();
|
||||
} else if (te instanceof DownloadGroupTaskEntity) {
|
||||
} else if (te instanceof DGTaskWrapper) {
|
||||
mQueue = DownloadGroupTaskQueue.getInstance();
|
||||
}
|
||||
te.setRemoveFile(removeFile);
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
package com.arialyy.aria.core.command.normal;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/9/20.
|
||||
* 取消命令
|
||||
*/
|
||||
public class CancelCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
public class CancelCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
|
||||
/**
|
||||
* removeFile {@code true} 删除已经下载完成的任务,不仅删除下载记录,还会删除已经下载完成的文件,{@code false}
|
||||
* 如果文件已经下载完成,只删除下载记录
|
||||
@@ -41,7 +41,7 @@ public class CancelCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
task = createTask();
|
||||
}
|
||||
if (task != null) {
|
||||
mTaskEntity.setRemoveFile(removeFile);
|
||||
mTaskWrapper.setRemoveFile(removeFile);
|
||||
removeTask();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.command.normal;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.NetUtils;
|
||||
@@ -35,7 +34,7 @@ import com.arialyy.aria.util.NetUtils;
|
||||
*
|
||||
* 目前只只支持单下载任务的最高优先级任务
|
||||
*/
|
||||
final class HighestPriorityCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
final class HighestPriorityCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
|
||||
HighestPriorityCmd(T entity, int taskType) {
|
||||
super(entity, taskType);
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ package com.arialyy.aria.core.command.normal;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.command.AbsCmdFactory;
|
||||
import com.arialyy.aria.core.command.ICmd;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by Lyy on 2016/9/23.
|
||||
* 命令工厂
|
||||
*/
|
||||
public class NormalCmdFactory extends AbsCmdFactory<AbsTaskEntity, AbsNormalCmd> {
|
||||
public class NormalCmdFactory extends AbsCmdFactory<AbsTaskWrapper, AbsNormalCmd> {
|
||||
/**
|
||||
* 创建任务
|
||||
*/
|
||||
@@ -84,7 +84,7 @@ public class NormalCmdFactory extends AbsCmdFactory<AbsTaskEntity, AbsNormalCmd>
|
||||
* @param taskType {@link ICmd#TASK_TYPE_DOWNLOAD}、{@link ICmd#TASK_TYPE_DOWNLOAD_GROUP}、{@link
|
||||
* ICmd#TASK_TYPE_UPLOAD}
|
||||
*/
|
||||
public AbsNormalCmd createCmd(AbsTaskEntity entity, int type, int taskType) {
|
||||
public AbsNormalCmd createCmd(AbsTaskWrapper entity, int type, int taskType) {
|
||||
switch (type) {
|
||||
case TASK_CREATE:
|
||||
return new AddCmd<>(entity, taskType);
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package com.arialyy.aria.core.command.normal;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
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.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
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;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
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.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@@ -30,8 +29,8 @@ import java.util.List;
|
||||
* 3.如果队列中只有等待状态的任务,如果执行队列没有满,则会启动等待状态的任务,如果执行队列已经满了,则会将所有等待状态的任务加载到缓存队列中
|
||||
* 4.恢复下载的任务规则是,停止时间越晚的任务启动越早,按照DESC来进行排序
|
||||
*/
|
||||
final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
private List<AbsTaskEntity> mWaitList = new ArrayList<>();
|
||||
final class ResumeAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
|
||||
private List<AbsTaskWrapper> mWaitList = new ArrayList<>();
|
||||
|
||||
ResumeAllCmd(T entity, int taskType) {
|
||||
super(entity, taskType);
|
||||
@@ -66,7 +65,7 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
//if (TextUtils.isEmpty(entity.getDownloadPath())){
|
||||
// continue;
|
||||
//}
|
||||
resumeTask(TEManager.getInstance().getTEntity(DownloadTaskEntity.class, entity.getKey()));
|
||||
resumeTask(TEManager.getInstance().getTEntity(DTaskWrapper.class, entity.getKey()));
|
||||
}
|
||||
}
|
||||
} else if (type == 2) {
|
||||
@@ -75,7 +74,7 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
if (entities != null && !entities.isEmpty()) {
|
||||
for (DownloadGroupEntity entity : entities) {
|
||||
resumeTask(
|
||||
TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, entity.getUrls()));
|
||||
TEManager.getInstance().getGTEntity(DGTaskWrapper.class, entity.getUrls()));
|
||||
}
|
||||
}
|
||||
} else if (type == 3) {
|
||||
@@ -83,7 +82,7 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
DbEntity.findDatas(UploadEntity.class, "state!=? ORDER BY stopTime DESC", "1");
|
||||
if (entities != null && !entities.isEmpty()) {
|
||||
for (UploadEntity entity : entities) {
|
||||
resumeTask(TEManager.getInstance().getTEntity(UploadTaskEntity.class, entity.getKey()));
|
||||
resumeTask(TEManager.getInstance().getTEntity(UTaskWrapper.class, entity.getKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,7 +91,7 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
/**
|
||||
* 恢复任务
|
||||
*/
|
||||
private void resumeTask(AbsTaskEntity te) {
|
||||
private void resumeTask(AbsTaskWrapper te) {
|
||||
if (te == null || te.getEntity() == null) return;
|
||||
int state = te.getState();
|
||||
if (state == IEntity.STATE_STOP || state == IEntity.STATE_OTHER) {
|
||||
@@ -112,12 +111,12 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
private void resumeWaitTask() {
|
||||
int maxTaskNum = mQueue.getMaxTaskNum();
|
||||
if (mWaitList == null || mWaitList.isEmpty()) return;
|
||||
for (AbsTaskEntity te : mWaitList) {
|
||||
if (te instanceof DownloadTaskEntity) {
|
||||
for (AbsTaskWrapper te : mWaitList) {
|
||||
if (te instanceof DTaskWrapper) {
|
||||
mQueue = DownloadTaskQueue.getInstance();
|
||||
} else if (te instanceof UploadTaskEntity) {
|
||||
} else if (te instanceof UTaskWrapper) {
|
||||
mQueue = UploadTaskQueue.getInstance();
|
||||
} else if (te instanceof DownloadGroupTaskEntity) {
|
||||
} else if (te instanceof DGTaskWrapper) {
|
||||
mQueue = DownloadGroupTaskQueue.getInstance();
|
||||
}
|
||||
if (mQueue.getCurrentExePoolNum() < maxTaskNum) {
|
||||
@@ -135,16 +134,16 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
*
|
||||
* @param te 任务实体
|
||||
*/
|
||||
private void resumeEntity(AbsTaskEntity te) {
|
||||
if (te instanceof DownloadTaskEntity) {
|
||||
if (te.getRequestType() == AbsTaskEntity.D_FTP
|
||||
|| te.getRequestType() == AbsTaskEntity.U_FTP) {
|
||||
te.setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey()));
|
||||
private void resumeEntity(AbsTaskWrapper te) {
|
||||
if (te instanceof DTaskWrapper) {
|
||||
if (te.getRequestType() == AbsTaskWrapper.D_FTP
|
||||
|| te.getRequestType() == AbsTaskWrapper.U_FTP) {
|
||||
te.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey()));
|
||||
}
|
||||
mQueue = DownloadTaskQueue.getInstance();
|
||||
} else if (te instanceof UploadTaskEntity) {
|
||||
} else if (te instanceof UTaskWrapper) {
|
||||
mQueue = UploadTaskQueue.getInstance();
|
||||
} else if (te instanceof DownloadGroupTaskEntity) {
|
||||
} else if (te instanceof DGTaskWrapper) {
|
||||
mQueue = DownloadGroupTaskQueue.getInstance();
|
||||
}
|
||||
int exeNum = mQueue.getCurrentExePoolNum();
|
||||
|
||||
@@ -18,17 +18,17 @@ package com.arialyy.aria.core.command.normal;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.QueueMod;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.wrapper.DGTEWrapper;
|
||||
import com.arialyy.aria.core.download.wrapper.DTEWrapper;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
import com.arialyy.aria.core.upload.wrapper.UTEWrapper;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
@@ -40,7 +40,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by lyy on 2016/8/22. 开始命令 队列模型{@link QueueMod#NOW}、{@link QueueMod#WAIT}
|
||||
*/
|
||||
class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
class StartCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
|
||||
|
||||
StartCmd(T entity, int taskType) {
|
||||
super(entity, taskType);
|
||||
@@ -115,11 +115,11 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
}
|
||||
}
|
||||
|
||||
private List<AbsTaskEntity> findWaitData(int type) {
|
||||
List<AbsTaskEntity> waitList = new ArrayList<>();
|
||||
private List<AbsTaskWrapper> findWaitData(int type) {
|
||||
List<AbsTaskWrapper> waitList = new ArrayList<>();
|
||||
if (type == 1) {
|
||||
List<DTEWrapper> wrappers = DbEntity.findRelationData(DTEWrapper.class,
|
||||
"DownloadTaskEntity.isGroupTask=? and DownloadTaskEntity.state=?", "false", "3");
|
||||
"DTaskWrapper.isGroupTask=? and DTaskWrapper.state=?", "false", "3");
|
||||
if (wrappers != null && !wrappers.isEmpty()) {
|
||||
for (DTEWrapper w : wrappers) {
|
||||
waitList.add(w.taskEntity);
|
||||
@@ -127,7 +127,7 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
}
|
||||
} else if (type == 2) {
|
||||
List<DGTEWrapper> wrappers =
|
||||
DbEntity.findRelationData(DGTEWrapper.class, "DownloadGroupTaskEntity.state=?", "3");
|
||||
DbEntity.findRelationData(DGTEWrapper.class, "DGTaskWrapper.state=?", "3");
|
||||
if (wrappers != null && !wrappers.isEmpty()) {
|
||||
for (DGTEWrapper w : wrappers) {
|
||||
waitList.add(w.taskEntity);
|
||||
@@ -135,7 +135,7 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
}
|
||||
} else if (type == 3) {
|
||||
List<UTEWrapper> wrappers = DbEntity.findRelationData(UTEWrapper.class,
|
||||
"UploadTaskEntity.state=?", "3");
|
||||
"UTaskWrapper.state=?", "3");
|
||||
if (wrappers != null && !wrappers.isEmpty()) {
|
||||
for (UTEWrapper w : wrappers) {
|
||||
waitList.add(w.taskEntity);
|
||||
@@ -145,20 +145,20 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
return waitList;
|
||||
}
|
||||
|
||||
private void handleTask(List<AbsTaskEntity> waitList) {
|
||||
for (AbsTaskEntity te : waitList) {
|
||||
private void handleTask(List<AbsTaskWrapper> waitList) {
|
||||
for (AbsTaskWrapper te : waitList) {
|
||||
if (te.getEntity() == null) continue;
|
||||
AbsTask task = getTask(te.getEntity());
|
||||
if (task != null) continue;
|
||||
if (te instanceof DownloadTaskEntity) {
|
||||
if (te.getRequestType() == AbsTaskEntity.D_FTP
|
||||
|| te.getRequestType() == AbsTaskEntity.U_FTP) {
|
||||
te.setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey()));
|
||||
if (te instanceof DTaskWrapper) {
|
||||
if (te.getRequestType() == AbsTaskWrapper.D_FTP
|
||||
|| te.getRequestType() == AbsTaskWrapper.U_FTP) {
|
||||
te.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey()));
|
||||
}
|
||||
mQueue = DownloadTaskQueue.getInstance();
|
||||
} else if (te instanceof UploadTaskEntity) {
|
||||
} else if (te instanceof UTaskWrapper) {
|
||||
mQueue = UploadTaskQueue.getInstance();
|
||||
} else if (te instanceof DownloadGroupTaskEntity) {
|
||||
} else if (te instanceof DGTaskWrapper) {
|
||||
mQueue = DownloadGroupTaskQueue.getInstance();
|
||||
}
|
||||
createTask(te);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.arialyy.aria.core.command.normal;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/6/13.
|
||||
* 停止所有任务的命令,并清空所有等待队列
|
||||
*/
|
||||
final class StopAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
final class StopAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
|
||||
StopAllCmd(T entity, int taskType) {
|
||||
super(entity, taskType);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.arialyy.aria.core.command.normal;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.arialyy.aria.util.ALog;
|
||||
* Created by lyy on 2016/9/20.
|
||||
* 停止命令
|
||||
*/
|
||||
class StopCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
class StopCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
|
||||
|
||||
StopCmd(T entity, int taskType) {
|
||||
super(entity, taskType);
|
||||
@@ -35,7 +35,7 @@ class StopCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
|
||||
if (!canExeCmd) return;
|
||||
AbsTask task = getTask();
|
||||
if (task == null) {
|
||||
if (mTaskEntity.getEntity().getState() == IEntity.STATE_RUNNING) {
|
||||
if (mTaskWrapper.getEntity().getState() == IEntity.STATE_RUNNING) {
|
||||
stopTask();
|
||||
} else {
|
||||
ALog.w(TAG, "停止命令执行失败,【调度器中没有该任务】");
|
||||
|
||||
@@ -20,9 +20,9 @@ import android.util.SparseArray;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.BaseDListener;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.AbsNormalEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IEventListener;
|
||||
import com.arialyy.aria.core.manager.ThreadTaskManager;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
@@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
|
||||
/**
|
||||
* Created by AriaL on 2017/7/1. 任务处理器
|
||||
*/
|
||||
public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>>
|
||||
public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskWrapper<ENTITY>>
|
||||
implements Runnable {
|
||||
private static final String STATE = "_state_";
|
||||
private static final String RECORD = "_record_";
|
||||
@@ -140,7 +140,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
mConstance.START_THREAD_NUM = mTotalThreadNum;
|
||||
|
||||
// 处理分块和动态文件参数
|
||||
if (mTaskEntity.isNewTask() && mTaskEntity instanceof DownloadTaskEntity) {
|
||||
if (mTaskEntity.isNewTask() && mTaskEntity instanceof DTaskWrapper) {
|
||||
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||
mRecord.isBlock = mTotalThreadNum > 1 && manager.getDownloadConfig().isUseBlock();
|
||||
// 线程数不等1并且没有使用块下载,则认为没有使用动态文件
|
||||
@@ -148,7 +148,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
||||
}
|
||||
|
||||
/*
|
||||
* mTaskEntity.getEntity().getFileSize() != mTempFile.length()为兼容以前老版本代码
|
||||
* mTaskWrapper.getEntity().getFileSize() != mTempFile.length()为兼容以前老版本代码
|
||||
* 动态长度条件:
|
||||
* 1、总线程数为1,并且是新任务
|
||||
* 2、总线程数为1,不是新任务,但是长度不是文件全长度
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.arialyy.aria.core.common;
|
||||
import android.os.Process;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.inf.AbsNormalEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IEventListener;
|
||||
import com.arialyy.aria.core.manager.ThreadTaskManager;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
@@ -40,7 +40,7 @@ import java.util.concurrent.Executors;
|
||||
* Created by lyy on 2017/1/18.
|
||||
* 任务线程
|
||||
*/
|
||||
public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>>
|
||||
public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAPPER extends AbsTaskWrapper<ENTITY>>
|
||||
implements Callable<AbsThreadTask> {
|
||||
/**
|
||||
* 线程重试次数
|
||||
@@ -55,9 +55,9 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
||||
protected int mBufSize;
|
||||
protected IEventListener mListener;
|
||||
protected StateConstance STATE;
|
||||
protected SubThreadConfig<TASK_ENTITY> mConfig;
|
||||
protected SubThreadConfig<TASK_WRAPPER> mConfig;
|
||||
protected ENTITY mEntity;
|
||||
protected TASK_ENTITY mTaskEntity;
|
||||
protected TASK_WRAPPER mTaskWrapper;
|
||||
private int mFailTimes = 0;
|
||||
private long mLastSaveTime;
|
||||
private ExecutorService mConfigThreadPool;
|
||||
@@ -82,12 +82,12 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
||||
});
|
||||
|
||||
protected AbsThreadTask(StateConstance constance, IEventListener listener,
|
||||
SubThreadConfig<TASK_ENTITY> config) {
|
||||
SubThreadConfig<TASK_WRAPPER> config) {
|
||||
STATE = constance;
|
||||
mListener = listener;
|
||||
mConfig = config;
|
||||
mTaskEntity = mConfig.TASK_ENTITY;
|
||||
mEntity = mTaskEntity.getEntity();
|
||||
mTaskWrapper = mConfig.TASK_ENTITY;
|
||||
mEntity = mTaskWrapper.getEntity();
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
mConfigThreadPool = Executors.newCachedThreadPool();
|
||||
mThreadNum = STATE.TASK_RECORD.threadRecords.size();
|
||||
|
||||
@@ -19,7 +19,7 @@ import android.os.Handler;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
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.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.inf.IEventListener;
|
||||
import com.arialyy.aria.core.inf.TaskSchedulerType;
|
||||
@@ -30,7 +30,7 @@ import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.ErrorHelp;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public abstract class BaseListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>, TASK extends AbsTask<ENTITY, TASK_ENTITY>>
|
||||
public abstract class BaseListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskWrapper<ENTITY>, TASK extends AbsTask<ENTITY, TASK_ENTITY>>
|
||||
implements IEventListener {
|
||||
private static final String TAG = "BaseListener";
|
||||
protected WeakReference<Handler> outHandler;
|
||||
@@ -48,8 +48,8 @@ public abstract class BaseListener<ENTITY extends AbsEntity, TASK_ENTITY extends
|
||||
protected BaseListener(TASK task, Handler outHandler) {
|
||||
this.outHandler = new WeakReference<>(outHandler);
|
||||
this.mTask = new WeakReference<>(task).get();
|
||||
this.mEntity = mTask.getTaskEntity().getEntity();
|
||||
this.mTaskEntity = mTask.getTaskEntity();
|
||||
this.mEntity = mTask.getTaskWrapper().getEntity();
|
||||
this.mTaskEntity = mTask.getTaskWrapper();
|
||||
manager = AriaManager.getInstance(AriaManager.APP);
|
||||
mLastLen = mEntity.getCurrentProgress();
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.arialyy.aria.core.common;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 子线程下载信息类
|
||||
*/
|
||||
public class SubThreadConfig<TASK_ENTITY extends AbsTaskEntity> {
|
||||
public class SubThreadConfig<TASK_ENTITY extends AbsTaskWrapper> {
|
||||
//线程Id
|
||||
public int THREAD_ID;
|
||||
//文件总长度
|
||||
|
||||
@@ -17,7 +17,6 @@ package com.arialyy.aria.core.common.ftp;
|
||||
|
||||
import android.os.Process;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import aria.apache.commons.net.ftp.FTP;
|
||||
import aria.apache.commons.net.ftp.FTPClient;
|
||||
import aria.apache.commons.net.ftp.FTPFile;
|
||||
@@ -28,7 +27,7 @@ import com.arialyy.aria.core.FtpUrlEntity;
|
||||
import com.arialyy.aria.core.common.OnFileInfoCallback;
|
||||
import com.arialyy.aria.core.common.ProtocolType;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.exception.AriaIOException;
|
||||
import com.arialyy.aria.exception.BaseException;
|
||||
@@ -48,21 +47,23 @@ import javax.net.ssl.SSLContext;
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/7/25. 获取ftp文件夹信息
|
||||
*/
|
||||
public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>>
|
||||
public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER extends AbsTaskWrapper<ENTITY>>
|
||||
implements Runnable {
|
||||
|
||||
private final String TAG = "AbsFtpInfoThread";
|
||||
protected ENTITY mEntity;
|
||||
protected TASK_ENTITY mTaskEntity;
|
||||
protected TASK_WRAPPER mTaskWrapper;
|
||||
private FtpTaskDelegate mTaskDelegate;
|
||||
private int mConnectTimeOut;
|
||||
protected OnFileInfoCallback mCallback;
|
||||
protected long mSize = 0;
|
||||
protected String charSet = "UTF-8";
|
||||
private boolean isUpload = false;
|
||||
|
||||
public AbsFtpInfoThread(TASK_ENTITY taskEntity, OnFileInfoCallback callback) {
|
||||
mTaskEntity = taskEntity;
|
||||
mEntity = taskEntity.getEntity();
|
||||
public AbsFtpInfoThread(TASK_WRAPPER taskWrapper, OnFileInfoCallback callback) {
|
||||
mTaskWrapper = taskWrapper;
|
||||
mEntity = taskWrapper.getEntity();
|
||||
mTaskDelegate = taskWrapper.asFtp();
|
||||
mConnectTimeOut =
|
||||
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getConnectTimeOut();
|
||||
mCallback = callback;
|
||||
@@ -84,12 +85,12 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
|
||||
try {
|
||||
client = createFtpClient();
|
||||
if (client == null) {
|
||||
ALog.e(TAG, String.format("任务【%s】失败", mTaskEntity.getUrlEntity().url));
|
||||
ALog.e(TAG, String.format("任务【%s】失败", mTaskDelegate.getUrlEntity().url));
|
||||
return;
|
||||
}
|
||||
String remotePath =
|
||||
new String(setRemotePath().getBytes(charSet), AbsFtpThreadTask.SERVER_CHARSET);
|
||||
if (mTaskEntity.getUrlEntity().isFtps) {
|
||||
if (mTaskDelegate.getUrlEntity().isFtps) {
|
||||
((FTPSClient) client).execPROT("P");
|
||||
//((FTPSClient) client).enterLocalActiveMode();
|
||||
}
|
||||
@@ -97,7 +98,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
|
||||
boolean isExist = files.length != 0;
|
||||
if (!isExist && !isUpload) {
|
||||
failDownload(new FileException(TAG,
|
||||
String.format("文件不存在,url: %s, remotePath:%s", mTaskEntity.getUrlEntity().url,
|
||||
String.format("文件不存在,url: %s, remotePath:%s", mTaskDelegate.getUrlEntity().url,
|
||||
remotePath)), false);
|
||||
int i = remotePath.lastIndexOf(File.separator);
|
||||
FTPFile[] files1;
|
||||
@@ -129,20 +130,19 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
|
||||
if (!FTPReply.isPositiveCompletion(reply)) {
|
||||
if (isUpload) {
|
||||
//服务器上没有该文件路径,表示该任务为新的上传任务
|
||||
mTaskEntity.setNewTask(true);
|
||||
mTaskWrapper.setNewTask(true);
|
||||
} else {
|
||||
client.disconnect();
|
||||
failDownload(new AriaIOException(TAG,
|
||||
String.format("获取文件信息错误,url: %s, errorCode:%s, errorMsg:%s",
|
||||
mTaskEntity.getUrlEntity().url, reply, client.getReplyString())), true);
|
||||
mTaskDelegate.getUrlEntity().url, reply, client.getReplyString())), true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
mTaskEntity.setCode(reply);
|
||||
mTaskWrapper.setCode(reply);
|
||||
if (mSize != 0 && !isUpload) {
|
||||
mEntity.setFileSize(mSize);
|
||||
}
|
||||
mTaskEntity.update();
|
||||
onPreComplete(reply);
|
||||
} catch (IOException e) {
|
||||
failDownload(new AriaIOException(TAG,
|
||||
@@ -180,7 +180,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
|
||||
*/
|
||||
private FTPClient createFtpClient() {
|
||||
FTPClient client = null;
|
||||
final FtpUrlEntity urlEntity = mTaskEntity.getUrlEntity();
|
||||
final FtpUrlEntity urlEntity = mTaskDelegate.getUrlEntity();
|
||||
try {
|
||||
Pattern p = Pattern.compile(Regular.REG_IP_V4);
|
||||
Matcher m = p.matcher(urlEntity.hostName);
|
||||
@@ -189,7 +189,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
|
||||
InetAddress ip = InetAddress.getByName(urlEntity.hostName);
|
||||
client.setConnectTimeout(mConnectTimeOut); // 连接10s超时
|
||||
client.connect(ip, Integer.parseInt(urlEntity.port));
|
||||
mTaskEntity.getUrlEntity().validAddr = ip;
|
||||
mTaskDelegate.getUrlEntity().validAddr = ip;
|
||||
} else {
|
||||
DNSQueryThread dnsThread = new DNSQueryThread(urlEntity.hostName);
|
||||
dnsThread.start();
|
||||
@@ -206,7 +206,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
|
||||
|
||||
if (client == null) {
|
||||
failDownload(new AriaIOException(TAG,
|
||||
String.format("链接失败, url: %s", mTaskEntity.getUrlEntity().url)), false);
|
||||
String.format("链接失败, url: %s", mTaskDelegate.getUrlEntity().url)), false);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
|
||||
client.disconnect();
|
||||
failDownload(new AriaIOException(TAG,
|
||||
String.format("无法连接到ftp服务器,filePath: %s, url: %s, errorCode: %s, errorMsg:%s",
|
||||
mEntity.getKey(), mTaskEntity.getUrlEntity().url, reply, client.getReplyString())),
|
||||
mEntity.getKey(), mTaskDelegate.getUrlEntity().url, reply, client.getReplyString())),
|
||||
true);
|
||||
return null;
|
||||
}
|
||||
@@ -249,8 +249,8 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
|
||||
reply = client.sendCommand("OPTS UTF8", "ON");
|
||||
if (reply != FTPReply.COMMAND_IS_SUPERFLUOUS) {
|
||||
ALog.i(TAG, "FTP 服务器不支持开启UTF8编码,尝试使用Aria手动设置的编码");
|
||||
if (!TextUtils.isEmpty(mTaskEntity.getCharSet())) {
|
||||
charSet = mTaskEntity.getCharSet();
|
||||
if (!TextUtils.isEmpty(mTaskWrapper.asFtp().getCharSet())) {
|
||||
charSet = mTaskWrapper.asFtp().getCharSet();
|
||||
}
|
||||
}
|
||||
client.setControlEncoding(charSet);
|
||||
@@ -307,7 +307,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
|
||||
try {
|
||||
client.setConnectTimeout(mConnectTimeOut); //需要先设置超时,这样才不会出现阻塞
|
||||
client.connect(ips[index], port);
|
||||
mTaskEntity.getUrlEntity().validAddr = ips[index];
|
||||
mTaskDelegate.getUrlEntity().validAddr = ips[index];
|
||||
return client;
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
@@ -328,7 +328,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
|
||||
e1.printStackTrace();
|
||||
}
|
||||
ALog.w(TAG, "遇到[ECONNREFUSED-连接被服务器拒绝]错误,正在尝试下一个地址");
|
||||
return connect(newInstanceClient(mTaskEntity.getUrlEntity()), ips, index + 1, port);
|
||||
return connect(newInstanceClient(mTaskDelegate.getUrlEntity()), ips, index + 1, port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.arialyy.aria.core.common.ProtocolType;
|
||||
import com.arialyy.aria.core.common.StateConstance;
|
||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
import com.arialyy.aria.core.inf.AbsNormalEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IEventListener;
|
||||
import com.arialyy.aria.exception.AriaIOException;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
@@ -39,7 +39,7 @@ import javax.net.ssl.SSLContext;
|
||||
* Created by lyy on 2017/9/26.
|
||||
* FTP单任务父类
|
||||
*/
|
||||
public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>>
|
||||
public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskWrapper<ENTITY>>
|
||||
extends AbsThreadTask<ENTITY, TASK_ENTITY> {
|
||||
private final String TAG = "AbsFtpThreadTask";
|
||||
protected String charSet;
|
||||
@@ -58,7 +58,7 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTI
|
||||
*/
|
||||
protected FTPClient createClient() {
|
||||
FTPClient client = null;
|
||||
final FtpUrlEntity urlEntity = mTaskEntity.getUrlEntity();
|
||||
final FtpUrlEntity urlEntity = mTaskWrapper.asFtp().getUrlEntity();
|
||||
if (urlEntity.validAddr == null) {
|
||||
try {
|
||||
InetAddress[] ips = InetAddress.getAllByName(urlEntity.hostName);
|
||||
@@ -107,8 +107,8 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTI
|
||||
// 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码
|
||||
charSet = "UTF-8";
|
||||
if (reply != FTPReply.COMMAND_IS_SUPERFLUOUS) {
|
||||
if (!TextUtils.isEmpty(mTaskEntity.getCharSet())) {
|
||||
charSet = mTaskEntity.getCharSet();
|
||||
if (!TextUtils.isEmpty(mTaskWrapper.asFtp().getCharSet())) {
|
||||
charSet = mTaskWrapper.asFtp().getCharSet();
|
||||
}
|
||||
}
|
||||
client.setControlEncoding(charSet);
|
||||
@@ -117,7 +117,7 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTI
|
||||
client.enterLocalPassiveMode();
|
||||
client.setFileType(FTP.BINARY_FILE_TYPE);
|
||||
client.setControlKeepAliveTimeout(5000);
|
||||
if (mTaskEntity.getUrlEntity().isFtps) {
|
||||
if (mTaskWrapper.asFtp().getUrlEntity().isFtps) {
|
||||
((FTPSClient) client).execPROT("P");
|
||||
}
|
||||
} catch (java.io.IOException e) {
|
||||
@@ -151,7 +151,7 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTI
|
||||
private FTPClient connect(FTPClient client, InetAddress[] ips, int index, int port) {
|
||||
try {
|
||||
client.connect(ips[index], port);
|
||||
mTaskEntity.getUrlEntity().validAddr = ips[index];
|
||||
mTaskWrapper.asFtp().getUrlEntity().validAddr = ips[index];
|
||||
return client;
|
||||
} catch (java.io.IOException e) {
|
||||
try {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class FTPSConfig<TARGET extends AbsTarget> implements ITarget {
|
||||
|
||||
public FTPSConfig(TARGET target) {
|
||||
mTarget = target;
|
||||
mUrlEntity = mTarget.getTaskEntity().getUrlEntity();
|
||||
mUrlEntity = mTarget.getTaskWrapper().asFtp().getUrlEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,14 +33,14 @@ public class FtpDelegate<TARGET extends AbsTarget> implements IFtpTarget<TARGET>
|
||||
|
||||
public FtpDelegate(TARGET target) {
|
||||
mTarget = target;
|
||||
mUrlEntity = target.getTaskEntity().getUrlEntity();
|
||||
mUrlEntity = target.getTaskWrapper().asFtp().getUrlEntity();
|
||||
}
|
||||
|
||||
@Override public TARGET charSet(String charSet) {
|
||||
if (TextUtils.isEmpty(charSet)) {
|
||||
throw new NullPointerException("字符编码为空");
|
||||
}
|
||||
mTarget.getTaskEntity().setCharSet(charSet);
|
||||
mTarget.getTaskWrapper().asFtp().setCharSet(charSet);
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class FtpDelegate<TARGET extends AbsTarget> implements IFtpTarget<TARGET>
|
||||
}
|
||||
|
||||
@Override public TARGET setProxy(Proxy proxy) {
|
||||
mTarget.getTaskEntity().setProxy(proxy);
|
||||
mTarget.getTaskWrapper().asFtp().setProxy(proxy);
|
||||
return mTarget;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.common.ftp;
|
||||
|
||||
import com.arialyy.aria.core.FtpUrlEntity;
|
||||
import com.arialyy.aria.core.inf.ITaskDelegate;
|
||||
import java.net.Proxy;
|
||||
|
||||
/**
|
||||
* fTP任务设置的信息,如:用户名、密码、端口等信息
|
||||
*/
|
||||
public class FtpTaskDelegate implements ITaskDelegate {
|
||||
|
||||
/**
|
||||
* 账号和密码
|
||||
*/
|
||||
private FtpUrlEntity urlEntity;
|
||||
|
||||
private Proxy proxy;
|
||||
|
||||
/**
|
||||
* 字符编码,默认为"utf-8"
|
||||
*/
|
||||
private String charSet = "utf-8";
|
||||
|
||||
public FtpUrlEntity getUrlEntity() {
|
||||
return urlEntity;
|
||||
}
|
||||
|
||||
public void setUrlEntity(FtpUrlEntity urlEntity) {
|
||||
this.urlEntity = urlEntity;
|
||||
}
|
||||
|
||||
public void setProxy(Proxy proxy) {
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
public Proxy getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
public String getCharSet() {
|
||||
return charSet;
|
||||
}
|
||||
|
||||
public void setCharSet(String charSet) {
|
||||
this.charSet = charSet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.common.http;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTarget;
|
||||
import com.arialyy.aria.core.inf.AbsTarget;
|
||||
import com.arialyy.aria.core.inf.ITarget;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class BaseTarget<TARGET extends AbsTarget> implements ITarget {
|
||||
private static final String TAG = "PostDelegate";
|
||||
TARGET mTarget;
|
||||
|
||||
public BaseTarget(TARGET target){
|
||||
mTarget = target;
|
||||
}
|
||||
|
||||
public TARGET setParams(Map<String, String> params) {
|
||||
mTarget.getTaskWrapper().asHttp().setParams(params);
|
||||
if (mTarget instanceof DownloadGroupTarget) {
|
||||
for (DTaskWrapper subTask : ((DGTaskWrapper) mTarget.getTaskWrapper()).getSubTaskWrapper()) {
|
||||
subTask.asHttp().setParams(params);
|
||||
}
|
||||
}
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
public TARGET setParam(String key, String value) {
|
||||
if (TextUtils.isEmpty(key) || TextUtils.isEmpty(value)) {
|
||||
ALog.d(TAG, "key 或value 为空");
|
||||
return mTarget;
|
||||
}
|
||||
Map<String, String> params = mTarget.getTaskWrapper().asHttp().getParams();
|
||||
if (params == null) {
|
||||
params = new HashMap<>();
|
||||
mTarget.getTaskWrapper().asHttp().setParams(params);
|
||||
}
|
||||
params.put(key, value);
|
||||
if (mTarget instanceof DownloadGroupTarget) {
|
||||
for (DTaskWrapper subTask : ((DGTaskWrapper) mTarget.getTaskWrapper()).getSubTaskWrapper()) {
|
||||
subTask.asHttp().setParams(params);
|
||||
}
|
||||
}
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
|
||||
}
|
||||
|
||||
@Override public void stop() {
|
||||
|
||||
}
|
||||
|
||||
@Override public void resume() {
|
||||
|
||||
}
|
||||
|
||||
@Override public void cancel() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,72 +15,16 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.common.http;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTarget;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTarget;
|
||||
import com.arialyy.aria.core.inf.IPostDelegate;
|
||||
import com.arialyy.aria.core.inf.ITarget;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* get处理委托类
|
||||
*/
|
||||
public class GetDelegate<TARGET extends AbsTarget> implements IPostDelegate<TARGET>, ITarget {
|
||||
private static final String TAG = "PostDelegate";
|
||||
private TARGET mTarget;
|
||||
public class GetDelegate<TARGET extends AbsTarget> extends BaseTarget<TARGET> {
|
||||
|
||||
public GetDelegate(TARGET target) {
|
||||
mTarget = target;
|
||||
mTarget.getTaskEntity().setRequestEnum(RequestEnum.GET);
|
||||
}
|
||||
|
||||
@Override public TARGET setParams(Map<String, String> params) {
|
||||
mTarget.getTaskEntity().setParams(params);
|
||||
if (mTarget instanceof DownloadGroupTarget) {
|
||||
for (DownloadTaskEntity subTask : ((DownloadGroupTaskEntity) mTarget.getTaskEntity()).getSubTaskEntities()) {
|
||||
subTask.setParams(params);
|
||||
}
|
||||
}
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
@Override public TARGET setParam(String key, String value) {
|
||||
if (TextUtils.isEmpty(key) || TextUtils.isEmpty(value)) {
|
||||
ALog.d(TAG, "key 或value 为空");
|
||||
return mTarget;
|
||||
}
|
||||
Map<String, String> params = mTarget.getTaskEntity().getParams();
|
||||
if (params == null) {
|
||||
params = new HashMap<>();
|
||||
mTarget.getTaskEntity().setParams(params);
|
||||
}
|
||||
params.put(key, value);
|
||||
if (mTarget instanceof DownloadGroupTarget) {
|
||||
for (DownloadTaskEntity subTask : ((DownloadGroupTaskEntity) mTarget.getTaskEntity()).getSubTaskEntities()) {
|
||||
subTask.setParams(params);
|
||||
}
|
||||
}
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
mTarget.start();
|
||||
}
|
||||
|
||||
@Override public void stop() {
|
||||
mTarget.stop();
|
||||
}
|
||||
|
||||
@Override public void resume() {
|
||||
mTarget.resume();
|
||||
}
|
||||
|
||||
@Override public void cancel() {
|
||||
mTarget.cancel();
|
||||
super(target);
|
||||
mTarget.getTaskWrapper().asHttp().setRequestEnum(RequestEnum.GET);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.arialyy.aria.core.common.http;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.inf.AbsTarget;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IHttpHeaderDelegate;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import java.net.Proxy;
|
||||
@@ -55,7 +55,7 @@ public class HttpHeaderDelegate<TARGET extends AbsTarget>
|
||||
ALog.w(TAG, "设置header失败,header对应的value不能为null");
|
||||
return mTarget;
|
||||
}
|
||||
addHeader(mTarget.getTaskEntity(), key, value);
|
||||
addHeader(mTarget.getTaskWrapper(), key, value);
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
@@ -71,24 +71,26 @@ public class HttpHeaderDelegate<TARGET extends AbsTarget>
|
||||
ALog.w(TAG, "设置header失败,map没有header数据");
|
||||
return mTarget;
|
||||
}
|
||||
addHeaders(mTarget.getTaskEntity(), headers);
|
||||
addHeaders(mTarget.getTaskWrapper(), headers);
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
@Override public TARGET setUrlProxy(Proxy proxy) {
|
||||
mTarget.getTaskEntity().setProxy(proxy);
|
||||
mTarget.getTaskWrapper().asHttp().setProxy(proxy);
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
public void addHeader(AbsTaskEntity taskEntity, String key, String value) {
|
||||
if (taskEntity.getHeaders().get(key) == null) {
|
||||
taskEntity.getHeaders().put(key, value);
|
||||
} else if (!taskEntity.getHeaders().get(key).equals(value)) {
|
||||
taskEntity.getHeaders().put(key, value);
|
||||
public void addHeader(AbsTaskWrapper taskWrapper, String key, String value) {
|
||||
HttpTaskDelegate taskDelegate = taskWrapper.asHttp();
|
||||
if (taskDelegate.getHeaders().get(key) == null) {
|
||||
taskDelegate.getHeaders().put(key, value);
|
||||
} else if (!taskDelegate.getHeaders().get(key).equals(value)) {
|
||||
taskDelegate.getHeaders().put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void addHeaders(AbsTaskEntity taskEntity, Map<String, String> headers) {
|
||||
public void addHeaders(AbsTaskWrapper taskWrapper, Map<String, String> headers) {
|
||||
HttpTaskDelegate taskDelegate = taskWrapper.asHttp();
|
||||
/*
|
||||
两个map比较逻辑
|
||||
1、比对key是否相同
|
||||
@@ -96,9 +98,9 @@ public class HttpHeaderDelegate<TARGET extends AbsTarget>
|
||||
3、只有当上面两个步骤中key 和 value都相同时才能任务两个map数据一致
|
||||
*/
|
||||
boolean mapEquals = false;
|
||||
if (taskEntity.getHeaders().size() == headers.size()) {
|
||||
if (taskDelegate.getHeaders().size() == headers.size()) {
|
||||
int i = 0;
|
||||
Set<String> keys = taskEntity.getHeaders().keySet();
|
||||
Set<String> keys = taskDelegate.getHeaders().keySet();
|
||||
for (String key : keys) {
|
||||
if (headers.containsKey(key)) {
|
||||
i++;
|
||||
@@ -106,9 +108,9 @@ public class HttpHeaderDelegate<TARGET extends AbsTarget>
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == taskEntity.getHeaders().size()) {
|
||||
if (i == taskDelegate.getHeaders().size()) {
|
||||
int j = 0;
|
||||
Collection<String> values = taskEntity.getHeaders().values();
|
||||
Collection<String> values = taskDelegate.getHeaders().values();
|
||||
for (String value : values) {
|
||||
if (headers.containsValue(value)) {
|
||||
j++;
|
||||
@@ -116,17 +118,17 @@ public class HttpHeaderDelegate<TARGET extends AbsTarget>
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == taskEntity.getHeaders().size()) {
|
||||
if (j == taskDelegate.getHeaders().size()) {
|
||||
mapEquals = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!mapEquals) {
|
||||
taskEntity.getHeaders().clear();
|
||||
taskDelegate.getHeaders().clear();
|
||||
Set<String> keys = headers.keySet();
|
||||
for (String key : keys) {
|
||||
taskEntity.getHeaders().put(key, headers.get(key));
|
||||
taskDelegate.getHeaders().put(key, headers.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* 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.common.http;
|
||||
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.core.inf.ITaskDelegate;
|
||||
import java.net.CookieManager;
|
||||
import java.net.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Http任务设置的信息,如:cookie、请求参数
|
||||
*/
|
||||
public class HttpTaskDelegate implements ITaskDelegate {
|
||||
|
||||
private CookieManager cookieManager;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
private Map<String, String> params;
|
||||
|
||||
/**
|
||||
* http 请求头
|
||||
*/
|
||||
private Map<String, String> headers = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 字符编码,默认为"utf-8"
|
||||
*/
|
||||
private String charSet = "utf-8";
|
||||
|
||||
/**
|
||||
* 网络请求类型
|
||||
*/
|
||||
private RequestEnum requestEnum = RequestEnum.GET;
|
||||
|
||||
/**
|
||||
* 是否使用服务器通过content-disposition传递的文件名,内容格式{@code attachment; filename="filename.jpg"} {@code true}
|
||||
* 使用
|
||||
*/
|
||||
private boolean useServerFileName = false;
|
||||
|
||||
/**
|
||||
* 重定向链接
|
||||
*/
|
||||
private String redirectUrl = "";
|
||||
|
||||
/**
|
||||
* 是否是chunk模式
|
||||
*/
|
||||
private boolean isChunked = false;
|
||||
/**
|
||||
* 文件上传需要的key
|
||||
*/
|
||||
private String attachment;
|
||||
/**
|
||||
* 上传的文件类型
|
||||
*/
|
||||
private String contentType = "multipart/form-data";
|
||||
private String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)";
|
||||
|
||||
private Proxy proxy;
|
||||
/**
|
||||
* 文件上传表单
|
||||
*/
|
||||
private Map<String, String> formFields = new HashMap<>();
|
||||
|
||||
public Map<String, String> getFormFields() {
|
||||
return formFields;
|
||||
}
|
||||
|
||||
public void setFormFields(Map<String, String> formFields) {
|
||||
this.formFields = formFields;
|
||||
}
|
||||
|
||||
public String getAttachment() {
|
||||
return attachment;
|
||||
}
|
||||
|
||||
public void setAttachment(String attachment) {
|
||||
this.attachment = attachment;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public String getUserAgent() {
|
||||
return userAgent;
|
||||
}
|
||||
|
||||
public void setUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
}
|
||||
|
||||
public boolean isChunked() {
|
||||
return isChunked;
|
||||
}
|
||||
|
||||
public void setChunked(boolean chunked) {
|
||||
isChunked = chunked;
|
||||
}
|
||||
|
||||
public CookieManager getCookieManager() {
|
||||
return cookieManager;
|
||||
}
|
||||
|
||||
public void setCookieManager(CookieManager cookieManager) {
|
||||
this.cookieManager = cookieManager;
|
||||
}
|
||||
|
||||
public Proxy getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
public void setProxy(Proxy proxy) {
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
public Map<String, String> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public void setHeaders(Map<String, String> headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
public String getCharSet() {
|
||||
return charSet;
|
||||
}
|
||||
|
||||
public void setCharSet(String charSet) {
|
||||
this.charSet = charSet;
|
||||
}
|
||||
|
||||
public RequestEnum getRequestEnum() {
|
||||
return requestEnum;
|
||||
}
|
||||
|
||||
public void setRequestEnum(RequestEnum requestEnum) {
|
||||
this.requestEnum = requestEnum;
|
||||
}
|
||||
|
||||
public boolean isUseServerFileName() {
|
||||
return useServerFileName;
|
||||
}
|
||||
|
||||
public void setUseServerFileName(boolean useServerFileName) {
|
||||
this.useServerFileName = useServerFileName;
|
||||
}
|
||||
|
||||
public String getRedirectUrl() {
|
||||
return redirectUrl;
|
||||
}
|
||||
|
||||
public void setRedirectUrl(String redirectUrl) {
|
||||
this.redirectUrl = redirectUrl;
|
||||
}
|
||||
|
||||
public Map<String, String> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(Map<String, String> params) {
|
||||
this.params = params;
|
||||
}
|
||||
}
|
||||
@@ -15,72 +15,16 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.common.http;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTarget;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTarget;
|
||||
import com.arialyy.aria.core.inf.IPostDelegate;
|
||||
import com.arialyy.aria.core.inf.ITarget;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* post处理委托类
|
||||
*/
|
||||
public class PostDelegate<TARGET extends AbsTarget> implements IPostDelegate<TARGET>, ITarget {
|
||||
private static final String TAG = "PostDelegate";
|
||||
private TARGET mTarget;
|
||||
public class PostDelegate<TARGET extends AbsTarget> extends BaseTarget<TARGET> {
|
||||
|
||||
public PostDelegate(TARGET target) {
|
||||
mTarget = target;
|
||||
mTarget.getTaskEntity().setRequestEnum(RequestEnum.POST);
|
||||
}
|
||||
|
||||
@Override public TARGET setParams(Map<String, String> params) {
|
||||
mTarget.getTaskEntity().setParams(params);
|
||||
if (mTarget instanceof DownloadGroupTarget) {
|
||||
for (DownloadTaskEntity subTask : ((DownloadGroupTaskEntity) mTarget.getTaskEntity()).getSubTaskEntities()) {
|
||||
subTask.setParams(params);
|
||||
}
|
||||
}
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
@Override public TARGET setParam(String key, String value) {
|
||||
if (TextUtils.isEmpty(key) || TextUtils.isEmpty(value)) {
|
||||
ALog.d(TAG, "key 或value 为空");
|
||||
return mTarget;
|
||||
}
|
||||
Map<String, String> params = mTarget.getTaskEntity().getParams();
|
||||
if (params == null) {
|
||||
params = new HashMap<>();
|
||||
mTarget.getTaskEntity().setParams(params);
|
||||
}
|
||||
params.put(key, value);
|
||||
if (mTarget instanceof DownloadGroupTarget) {
|
||||
for (DownloadTaskEntity subTask : ((DownloadGroupTaskEntity) mTarget.getTaskEntity()).getSubTaskEntities()) {
|
||||
subTask.setParams(params);
|
||||
}
|
||||
}
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
mTarget.start();
|
||||
}
|
||||
|
||||
@Override public void stop() {
|
||||
mTarget.stop();
|
||||
}
|
||||
|
||||
@Override public void resume() {
|
||||
mTarget.resume();
|
||||
}
|
||||
|
||||
@Override public void cancel() {
|
||||
mTarget.cancel();
|
||||
super(target);
|
||||
mTarget.getTaskWrapper().asHttp().setRequestEnum(RequestEnum.POST);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTarget;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/2/28.
|
||||
*/
|
||||
abstract class AbsDownloadTarget<TARGET extends AbsTarget, ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity>
|
||||
abstract class AbsDownloadTarget<TARGET extends AbsTarget, ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskWrapper>
|
||||
extends AbsTarget<TARGET, ENTITY, TASK_ENTITY> {
|
||||
|
||||
static final int HTTP = 1;
|
||||
@@ -57,7 +57,7 @@ abstract class AbsDownloadTarget<TARGET extends AbsTarget, ENTITY extends AbsEnt
|
||||
protected void setHighestPriority() {
|
||||
if (checkEntity()) {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_HIGHEST_PRIORITY,
|
||||
.setCmd(CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_HIGHEST_PRIORITY,
|
||||
checkTaskType()))
|
||||
.exe();
|
||||
}
|
||||
@@ -69,7 +69,7 @@ abstract class AbsDownloadTarget<TARGET extends AbsTarget, ENTITY extends AbsEnt
|
||||
public void add() {
|
||||
if (checkEntity()) {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_CREATE,
|
||||
.setCmd(CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_CREATE,
|
||||
checkTaskType()))
|
||||
.exe();
|
||||
}
|
||||
|
||||
@@ -17,17 +17,15 @@ package com.arialyy.aria.core.download;
|
||||
|
||||
import android.os.Handler;
|
||||
import com.arialyy.aria.core.common.BaseListener;
|
||||
import com.arialyy.aria.core.common.TaskRecord;
|
||||
import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulers;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
|
||||
/**
|
||||
* 下载监听类
|
||||
*/
|
||||
public class BaseDListener extends BaseListener<DownloadEntity, DownloadTaskEntity, DownloadTask>
|
||||
public class BaseDListener extends BaseListener<DownloadEntity, DTaskWrapper, DownloadTask>
|
||||
implements IDownloadListener {
|
||||
private static final String TAG = "BaseDListener";
|
||||
|
||||
@@ -68,6 +66,5 @@ public class BaseDListener extends BaseListener<DownloadEntity, DownloadTaskEnti
|
||||
if (location > 0) {
|
||||
mEntity.setCurrentProgress(location);
|
||||
}
|
||||
mTaskEntity.update();
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ package com.arialyy.aria.core.download;
|
||||
|
||||
import android.support.annotation.CheckResult;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.manager.SubTaskManager;
|
||||
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||
@@ -31,7 +30,7 @@ import java.util.List;
|
||||
* Created by lyy on 2017/7/26.
|
||||
*/
|
||||
abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
|
||||
extends AbsDownloadTarget<TARGET, DownloadGroupEntity, DownloadGroupTaskEntity> {
|
||||
extends AbsDownloadTarget<TARGET, DownloadGroupEntity, DGTaskWrapper> {
|
||||
|
||||
/**
|
||||
* 组任务名
|
||||
@@ -56,7 +55,7 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
|
||||
@CheckResult
|
||||
public SubTaskManager getSubTaskManager() {
|
||||
if (mSubTaskManager == null) {
|
||||
mSubTaskManager = new SubTaskManager(mTargetName, mTaskEntity);
|
||||
mSubTaskManager = new SubTaskManager(mTargetName, mTaskWrapper);
|
||||
}
|
||||
return mSubTaskManager;
|
||||
}
|
||||
@@ -123,12 +122,10 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
|
||||
* @param newDirPath 新的文件夹路径
|
||||
*/
|
||||
void reChangeDirPath(String newDirPath) {
|
||||
List<DownloadTaskEntity> subTasks = mTaskEntity.getSubTaskEntities();
|
||||
List<DTaskWrapper> subTasks = mTaskWrapper.getSubTaskWrapper();
|
||||
if (subTasks != null && !subTasks.isEmpty()) {
|
||||
//List<DownloadEntity> des = new ArrayList<>();
|
||||
//List<DownloadTaskEntity> dtes = new ArrayList<>();
|
||||
List<DbEntity> des = new ArrayList<>();
|
||||
for (DownloadTaskEntity dte : subTasks) {
|
||||
for (DTaskWrapper dte : subTasks) {
|
||||
DownloadEntity de = dte.getEntity();
|
||||
String oldPath = de.getDownloadPath();
|
||||
String newPath = newDirPath + "/" + de.getFileName();
|
||||
@@ -138,13 +135,7 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
|
||||
}
|
||||
de.setDownloadPath(newPath);
|
||||
dte.setKey(newPath);
|
||||
|
||||
//des.add(de);
|
||||
//dtes.add(dte);
|
||||
//de.save();
|
||||
//dte.save();
|
||||
des.add(de);
|
||||
des.add(dte);
|
||||
}
|
||||
AbsEntity.saveAll(des);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.TaskRecord;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
@@ -28,7 +27,7 @@ import java.io.File;
|
||||
* Created by Aria.Lao on 2017/7/26.
|
||||
*/
|
||||
abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
||||
extends AbsDownloadTarget<TARGET, DownloadEntity, DownloadTaskEntity> {
|
||||
extends AbsDownloadTarget<TARGET, DownloadEntity, DTaskWrapper> {
|
||||
|
||||
/**
|
||||
* 资源地址
|
||||
@@ -41,8 +40,8 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
||||
void initTarget(String url, String targetName) {
|
||||
this.url = url;
|
||||
mTargetName = targetName;
|
||||
mTaskEntity = TEManager.getInstance().getTEntity(DownloadTaskEntity.class, url);
|
||||
mEntity = mTaskEntity.getEntity();
|
||||
mTaskWrapper = TEManager.getInstance().getTEntity(DTaskWrapper.class, url);
|
||||
mEntity = mTaskWrapper.getEntity();
|
||||
|
||||
if (mEntity != null) {
|
||||
mTempFilePath = mEntity.getDownloadPath();
|
||||
@@ -64,7 +63,7 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
||||
return (TARGET) this;
|
||||
}
|
||||
this.newUrl = newUrl;
|
||||
mTaskEntity.setRefreshInfo(true);
|
||||
mTaskWrapper.setRefreshInfo(true);
|
||||
return (TARGET) this;
|
||||
}
|
||||
|
||||
@@ -122,7 +121,6 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
||||
boolean b = getTargetType() < GROUP_HTTP && checkUrl() && checkFilePath();
|
||||
if (b) {
|
||||
mEntity.save();
|
||||
mTaskEntity.save();
|
||||
}
|
||||
return b;
|
||||
}
|
||||
@@ -166,14 +164,14 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
||||
} else {
|
||||
ALog.w(TAG, "保存路径【" + filePath + "】已经被其它任务占用,当前任务将覆盖该路径的文件");
|
||||
CommonUtil.delTaskRecord(filePath, 1);
|
||||
mTaskEntity = TEManager.getInstance().getTEntity(DownloadTaskEntity.class, url);
|
||||
mTaskWrapper = TEManager.getInstance().getTEntity(DTaskWrapper.class, url);
|
||||
}
|
||||
}
|
||||
File oldFile = new File(mEntity.getDownloadPath());
|
||||
File newFile = new File(filePath);
|
||||
mEntity.setDownloadPath(filePath);
|
||||
mEntity.setFileName(newFile.getName());
|
||||
mTaskEntity.setKey(filePath);
|
||||
mTaskWrapper.setKey(filePath);
|
||||
if (oldFile.exists()) {
|
||||
oldFile.renameTo(newFile);
|
||||
CommonUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath());
|
||||
@@ -203,7 +201,7 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
||||
}
|
||||
if (!TextUtils.isEmpty(newUrl)) {
|
||||
mEntity.setUrl(newUrl);
|
||||
mTaskEntity.setUrl(newUrl);
|
||||
mTaskWrapper.setUrl(newUrl);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,26 +15,18 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
|
||||
import com.arialyy.aria.orm.ActionPolicy;
|
||||
import com.arialyy.aria.orm.annotation.Foreign;
|
||||
import com.arialyy.aria.orm.annotation.Ignore;
|
||||
import com.arialyy.aria.orm.annotation.Primary;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTaskWrapper;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/7/1.
|
||||
* 任务组的任务实体
|
||||
* Created by AriaL on 2017/7/1. 任务组的任务实体
|
||||
*/
|
||||
public class DownloadGroupTaskEntity extends AbsGroupTaskEntity<DownloadGroupEntity> {
|
||||
public class DGTaskWrapper extends AbsGroupTaskWrapper<DownloadGroupEntity, DTaskWrapper> {
|
||||
|
||||
@Ignore private DownloadGroupEntity entity;
|
||||
private DownloadGroupEntity entity;
|
||||
|
||||
@Ignore private List<DownloadTaskEntity> subTaskEntities;
|
||||
private List<DTaskWrapper> subTaskEntities;
|
||||
|
||||
@Primary
|
||||
@Foreign(parent = DownloadGroupEntity.class, column = "groupName",
|
||||
onUpdate = ActionPolicy.CASCADE, onDelete = ActionPolicy.CASCADE)
|
||||
private String key;
|
||||
|
||||
@Override public DownloadGroupEntity getEntity() {
|
||||
@@ -45,11 +37,8 @@ public class DownloadGroupTaskEntity extends AbsGroupTaskEntity<DownloadGroupEnt
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public List<DownloadTaskEntity> getSubTaskEntities() {
|
||||
return subTaskEntities;
|
||||
}
|
||||
|
||||
public void setSubTaskEntities(List<DownloadTaskEntity> subTaskEntities) {
|
||||
@Override
|
||||
public void setSubTaskWrapper(List<DTaskWrapper> subTaskEntities) {
|
||||
this.subTaskEntities = subTaskEntities;
|
||||
}
|
||||
|
||||
@@ -60,4 +49,8 @@ public class DownloadGroupTaskEntity extends AbsGroupTaskEntity<DownloadGroupEnt
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override public List<DTaskWrapper> getSubTaskWrapper() {
|
||||
return subTaskEntities;
|
||||
}
|
||||
}
|
||||
@@ -15,39 +15,25 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsNormalTaskEntity;
|
||||
import com.arialyy.aria.orm.ActionPolicy;
|
||||
import com.arialyy.aria.orm.annotation.Foreign;
|
||||
import com.arialyy.aria.orm.annotation.Ignore;
|
||||
import com.arialyy.aria.orm.annotation.NoNull;
|
||||
import com.arialyy.aria.orm.annotation.Primary;
|
||||
import java.util.Map;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/1/23.
|
||||
* 下载任务实体和下载实体为一对一关系,下载实体删除,任务实体自动删除
|
||||
* Created by lyy on 2017/1/23. 下载任务实体和下载实体为一对一关系,下载实体删除,任务实体自动删除
|
||||
*/
|
||||
public class DownloadTaskEntity extends AbsNormalTaskEntity<DownloadEntity> {
|
||||
public class DTaskWrapper extends AbsTaskWrapper<DownloadEntity> {
|
||||
|
||||
@Ignore private DownloadEntity entity;
|
||||
private DownloadEntity entity;
|
||||
|
||||
/**
|
||||
* 任务的url
|
||||
*/
|
||||
@NoNull private String url;
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 所属的任务组组名,如果不属于任务组,则为null
|
||||
*/
|
||||
@Foreign(parent = DownloadGroupTaskEntity.class, column = "key",
|
||||
onUpdate = ActionPolicy.CASCADE, onDelete = ActionPolicy.CASCADE)
|
||||
private String groupName;
|
||||
|
||||
/**
|
||||
* 是否是chunk模式
|
||||
*/
|
||||
private boolean isChunked = false;
|
||||
|
||||
/**
|
||||
* 该任务是否属于任务组
|
||||
*/
|
||||
@@ -56,12 +42,9 @@ public class DownloadTaskEntity extends AbsNormalTaskEntity<DownloadEntity> {
|
||||
/**
|
||||
* Task实体对应的key
|
||||
*/
|
||||
@Primary
|
||||
@Foreign(parent = DownloadEntity.class, column = "downloadPath",
|
||||
onUpdate = ActionPolicy.CASCADE, onDelete = ActionPolicy.CASCADE)
|
||||
private String key;
|
||||
|
||||
public DownloadTaskEntity() {
|
||||
public DTaskWrapper() {
|
||||
}
|
||||
|
||||
@Override public DownloadEntity getEntity() {
|
||||
@@ -84,10 +67,6 @@ public class DownloadTaskEntity extends AbsNormalTaskEntity<DownloadEntity> {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public boolean isChunked() {
|
||||
return isChunked;
|
||||
}
|
||||
|
||||
public boolean isGroupTask() {
|
||||
return isGroupTask;
|
||||
}
|
||||
@@ -104,10 +83,6 @@ public class DownloadTaskEntity extends AbsNormalTaskEntity<DownloadEntity> {
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
public void setChunked(boolean chunked) {
|
||||
isChunked = chunked;
|
||||
}
|
||||
|
||||
public void setGroupTask(boolean groupTask) {
|
||||
isGroupTask = groupTask;
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.inf.AbsNormalEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.orm.ActionPolicy;
|
||||
import com.arialyy.aria.orm.annotation.Foreign;
|
||||
import com.arialyy.aria.orm.annotation.Primary;
|
||||
@@ -61,7 +61,7 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
|
||||
}
|
||||
|
||||
@Override public int getTaskType() {
|
||||
return getUrl().startsWith("ftp") ? AbsTaskEntity.D_FTP : AbsTaskEntity.D_HTTP;
|
||||
return getUrl().startsWith("ftp") ? AbsTaskWrapper.D_FTP : AbsTaskWrapper.D_HTTP;
|
||||
}
|
||||
|
||||
public DownloadEntity() {
|
||||
|
||||
@@ -17,7 +17,7 @@ package com.arialyy.aria.core.download;
|
||||
|
||||
import android.os.Parcel;
|
||||
import com.arialyy.aria.core.inf.AbsGroupEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.orm.annotation.Ignore;
|
||||
import java.util.List;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class DownloadGroupEntity extends AbsGroupEntity {
|
||||
}
|
||||
|
||||
@Override public int getTaskType() {
|
||||
return getKey().startsWith("ftp") ? AbsTaskEntity.D_FTP_DIR : AbsTaskEntity.DG_HTTP;
|
||||
return getKey().startsWith("ftp") ? AbsTaskWrapper.D_FTP_DIR : AbsTaskWrapper.DG_HTTP;
|
||||
}
|
||||
|
||||
public DownloadGroupEntity() {
|
||||
|
||||
@@ -30,7 +30,7 @@ import com.arialyy.aria.util.ErrorHelp;
|
||||
* Created by Aria.Lao on 2017/7/20. 任务组下载事件
|
||||
*/
|
||||
class DownloadGroupListener
|
||||
extends BaseListener<DownloadGroupEntity, DownloadGroupTaskEntity, DownloadGroupTask>
|
||||
extends BaseListener<DownloadGroupEntity, DGTaskWrapper, DownloadGroupTask>
|
||||
implements IDownloadGroupListener {
|
||||
private final String TAG = "DownloadGroupListener";
|
||||
private GroupSendParams<DownloadGroupTask, DownloadEntity> mSeedEntity;
|
||||
@@ -136,6 +136,5 @@ class DownloadGroupListener
|
||||
if (location > 0) {
|
||||
mEntity.setCurrentProgress(location);
|
||||
}
|
||||
mTaskEntity.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,8 +67,8 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
|
||||
|
||||
private void init() {
|
||||
mGroupName = CommonUtil.getMd5Code(mUrls);
|
||||
mTaskEntity = TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, mUrls);
|
||||
mEntity = mTaskEntity.getEntity();
|
||||
mTaskWrapper = TEManager.getInstance().getGTEntity(DGTaskWrapper.class, mUrls);
|
||||
mEntity = mTaskWrapper.getEntity();
|
||||
if (mEntity != null) {
|
||||
mDirPathTemp = mEntity.getDirPath();
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
|
||||
mUrls.addAll(urls);
|
||||
mGroupName = CommonUtil.getMd5Code(urls);
|
||||
mEntity.setGroupName(mGroupName);
|
||||
mTaskEntity.setKey(mGroupName);
|
||||
mTaskWrapper.setKey(mGroupName);
|
||||
mEntity.update();
|
||||
if (mEntity.getSubEntities() != null && !mEntity.getSubEntities().isEmpty()) {
|
||||
for (DownloadEntity de : mEntity.getSubEntities()) {
|
||||
@@ -159,7 +159,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
|
||||
ALog.e(TAG, "修改子任务的文件名失败:列表为null");
|
||||
return this;
|
||||
}
|
||||
if (subTaskFileName.size() != mTaskEntity.getSubTaskEntities().size()) {
|
||||
if (subTaskFileName.size() != mTaskWrapper.getSubTaskWrapper().size()) {
|
||||
ALog.e(TAG, "修改子任务的文件名失败:子任务文件名列表数量和子任务的数量不匹配");
|
||||
return this;
|
||||
}
|
||||
@@ -186,14 +186,13 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mTaskEntity.getRequestEnum() == RequestEnum.POST) {
|
||||
for (DownloadTaskEntity subTask : mTaskEntity.getSubTaskEntities()) {
|
||||
subTask.setRequestEnum(RequestEnum.POST);
|
||||
if (mTaskWrapper.asHttp().getRequestEnum() == RequestEnum.POST) {
|
||||
for (DTaskWrapper subTask : mTaskWrapper.getSubTaskWrapper()) {
|
||||
subTask.asHttp().setRequestEnum(RequestEnum.POST);
|
||||
}
|
||||
}
|
||||
|
||||
mEntity.save();
|
||||
mTaskEntity.save();
|
||||
|
||||
if (needModifyPath) {
|
||||
reChangeDirPath(mDirPathTemp);
|
||||
@@ -211,9 +210,9 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
|
||||
* 更新所有改动的子任务文件名
|
||||
*/
|
||||
private void updateSingleSubFileName() {
|
||||
List<DownloadTaskEntity> entities = mTaskEntity.getSubTaskEntities();
|
||||
List<DTaskWrapper> entities = mTaskWrapper.getSubTaskWrapper();
|
||||
int i = 0;
|
||||
for (DownloadTaskEntity entity : entities) {
|
||||
for (DTaskWrapper entity : entities) {
|
||||
if (i < mSubNameTemp.size()) {
|
||||
String newName = mSubNameTemp.get(i);
|
||||
updateSingleSubFileName(entity, newName);
|
||||
@@ -271,7 +270,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
|
||||
/**
|
||||
* 更新单个子任务文件名
|
||||
*/
|
||||
private void updateSingleSubFileName(DownloadTaskEntity taskEntity, String newName) {
|
||||
private void updateSingleSubFileName(DTaskWrapper taskEntity, String newName) {
|
||||
DownloadEntity entity = taskEntity.getEntity();
|
||||
if (!newName.equals(entity.getFileName())) {
|
||||
String oldPath = mEntity.getDirPath() + "/" + entity.getFileName();
|
||||
@@ -314,7 +313,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
|
||||
|
||||
@CheckResult
|
||||
@Override public DownloadGroupTarget addHeader(@NonNull String key, @NonNull String value) {
|
||||
for (DownloadTaskEntity subTask : mTaskEntity.getSubTaskEntities()) {
|
||||
for (DTaskWrapper subTask : mTaskWrapper.getSubTaskWrapper()) {
|
||||
mDelegate.addHeader(subTask, key, value);
|
||||
}
|
||||
return mDelegate.addHeader(key, value);
|
||||
@@ -322,7 +321,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
|
||||
|
||||
@CheckResult
|
||||
@Override public DownloadGroupTarget addHeaders(Map<String, String> headers) {
|
||||
for (DownloadTaskEntity subTask : mTaskEntity.getSubTaskEntities()) {
|
||||
for (DTaskWrapper subTask : mTaskWrapper.getSubTaskWrapper()) {
|
||||
mDelegate.addHeaders(subTask, headers);
|
||||
}
|
||||
return mDelegate.addHeaders(headers);
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.arialyy.aria.core.download.downloader.DownloadGroupUtil;
|
||||
import com.arialyy.aria.core.download.downloader.FtpDirDownloadUtil;
|
||||
import com.arialyy.aria.core.download.downloader.IDownloadGroupListener;
|
||||
import com.arialyy.aria.core.inf.AbsGroupTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulers;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
|
||||
@@ -31,30 +31,30 @@ import com.arialyy.aria.util.CheckUtil;
|
||||
* Created by AriaL on 2017/6/27.
|
||||
* 任务组任务
|
||||
*/
|
||||
public class DownloadGroupTask extends AbsGroupTask<DownloadGroupEntity, DownloadGroupTaskEntity> {
|
||||
public class DownloadGroupTask extends AbsGroupTask<DownloadGroupEntity, DGTaskWrapper> {
|
||||
|
||||
private DownloadGroupTask(DownloadGroupTaskEntity taskEntity, Handler outHandler) {
|
||||
mTaskEntity = taskEntity;
|
||||
private DownloadGroupTask(DGTaskWrapper taskEntity, Handler outHandler) {
|
||||
mTaskWrapper = taskEntity;
|
||||
mOutHandler = outHandler;
|
||||
mContext = AriaManager.APP;
|
||||
mListener = new DownloadGroupListener(this, mOutHandler);
|
||||
switch (taskEntity.getRequestType()) {
|
||||
case AbsTaskEntity.D_HTTP:
|
||||
mUtil = new DownloadGroupUtil((IDownloadGroupListener) mListener, mTaskEntity);
|
||||
case AbsTaskWrapper.D_HTTP:
|
||||
mUtil = new DownloadGroupUtil((IDownloadGroupListener) mListener, mTaskWrapper);
|
||||
break;
|
||||
case AbsTaskEntity.D_FTP_DIR:
|
||||
mUtil = new FtpDirDownloadUtil((IDownloadGroupListener) mListener, mTaskEntity);
|
||||
case AbsTaskWrapper.D_FTP_DIR:
|
||||
mUtil = new FtpDirDownloadUtil((IDownloadGroupListener) mListener, mTaskWrapper);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public DownloadGroupEntity getEntity() {
|
||||
return mTaskEntity.getEntity();
|
||||
return mTaskWrapper.getEntity();
|
||||
}
|
||||
|
||||
@Override public String getTaskName() {
|
||||
return "任务组->" + (TextUtils.isEmpty(mTaskEntity.getEntity().getAlias())
|
||||
? mTaskEntity.getEntity().getGroupName() : mTaskEntity.getEntity().getAlias());
|
||||
return "任务组->" + (TextUtils.isEmpty(mTaskWrapper.getEntity().getAlias())
|
||||
? mTaskWrapper.getEntity().getGroupName() : mTaskWrapper.getEntity().getAlias());
|
||||
}
|
||||
|
||||
@Override public int getTaskType() {
|
||||
@@ -62,10 +62,10 @@ public class DownloadGroupTask extends AbsGroupTask<DownloadGroupEntity, Downloa
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
DownloadGroupTaskEntity taskEntity;
|
||||
DGTaskWrapper taskEntity;
|
||||
Handler outHandler;
|
||||
|
||||
public Builder(DownloadGroupTaskEntity taskEntity) {
|
||||
public Builder(DGTaskWrapper taskEntity) {
|
||||
CheckUtil.checkTaskEntity(taskEntity);
|
||||
this.taskEntity = taskEntity;
|
||||
}
|
||||
|
||||
@@ -236,14 +236,14 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
* @param downloadUrl 下载地址
|
||||
* @return 如果url错误或查找不到数据,则返回null
|
||||
*/
|
||||
public DownloadTaskEntity getDownloadTask(String downloadUrl) {
|
||||
public DTaskWrapper getDownloadTask(String downloadUrl) {
|
||||
if (!CheckUtil.checkUrl(downloadUrl)) {
|
||||
return null;
|
||||
}
|
||||
if (!taskExists(downloadUrl)) {
|
||||
return null;
|
||||
}
|
||||
return TEManager.getInstance().getTEntity(DownloadTaskEntity.class, downloadUrl);
|
||||
return TEManager.getInstance().getTEntity(DTaskWrapper.class, downloadUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,7 +252,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
* @param urls 任务组子任务下载地址列表
|
||||
* @return 返回对应的任务组实体;如果查找不到对应的数据或子任务列表为null,返回null
|
||||
*/
|
||||
public DownloadGroupTaskEntity getGroupTask(List<String> urls) {
|
||||
public DGTaskWrapper getGroupTask(List<String> urls) {
|
||||
if (urls == null || urls.isEmpty()) {
|
||||
ALog.e(TAG, "获取任务组实体失败:任务组子任务下载地址列表为null");
|
||||
return null;
|
||||
@@ -260,7 +260,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
if (!taskExists(urls)) {
|
||||
return null;
|
||||
}
|
||||
return TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, urls);
|
||||
return TEManager.getInstance().getGTEntity(DGTaskWrapper.class, urls);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,7 +269,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
* @param dirUrl FTP文件夹本地下载路径
|
||||
* @return 返回对应的任务组实体;如果查找不到对应的数据或路径为null,返回null
|
||||
*/
|
||||
public DownloadGroupTaskEntity getFtpDirTask(String dirUrl) {
|
||||
public DGTaskWrapper getFtpDirTask(String dirUrl) {
|
||||
if (TextUtils.isEmpty(dirUrl)) {
|
||||
ALog.e(TAG, "获取FTP文件夹实体失败:下载路径为null");
|
||||
return null;
|
||||
@@ -279,7 +279,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
if (!b) {
|
||||
return null;
|
||||
}
|
||||
return TEManager.getInstance().getFDTEntity(DownloadGroupTaskEntity.class, dirUrl);
|
||||
return TEManager.getInstance().getFDTEntity(DGTaskWrapper.class, dirUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,7 +288,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
* @return {@code true}存在,{@code false} 不存在
|
||||
*/
|
||||
public boolean taskExists(String downloadUrl) {
|
||||
return DbEntity.checkDataExist(DownloadTaskEntity.class, "url=?", downloadUrl);
|
||||
return DbEntity.checkDataExist(DTaskWrapper.class, "url=?", downloadUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -369,7 +369,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
public void stopAllTask() {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(NormalCmdFactory.getInstance()
|
||||
.createCmd(new DownloadTaskEntity(), NormalCmdFactory.TASK_STOP_ALL,
|
||||
.createCmd(new DTaskWrapper(), NormalCmdFactory.TASK_STOP_ALL,
|
||||
ICmd.TASK_TYPE_DOWNLOAD))
|
||||
.exe();
|
||||
}
|
||||
@@ -382,7 +382,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
public void resumeAllTask() {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(NormalCmdFactory.getInstance()
|
||||
.createCmd(new DownloadTaskEntity(), NormalCmdFactory.TASK_RESUME_ALL,
|
||||
.createCmd(new DTaskWrapper(), NormalCmdFactory.TASK_RESUME_ALL,
|
||||
ICmd.TASK_TYPE_DOWNLOAD))
|
||||
.exe();
|
||||
}
|
||||
@@ -396,7 +396,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
public void removeAllTask(boolean removeFile) {
|
||||
final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP);
|
||||
CancelAllCmd cancelCmd =
|
||||
(CancelAllCmd) CommonUtil.createNormalCmd(new DownloadTaskEntity(),
|
||||
(CancelAllCmd) CommonUtil.createNormalCmd(new DTaskWrapper(),
|
||||
NormalCmdFactory.TASK_CANCEL_ALL, ICmd.TASK_TYPE_DOWNLOAD);
|
||||
cancelCmd.removeFile = removeFile;
|
||||
ariaManager.setCmd(cancelCmd).exe();
|
||||
|
||||
@@ -17,7 +17,6 @@ package com.arialyy.aria.core.download;
|
||||
|
||||
import android.support.annotation.CheckResult;
|
||||
import android.support.annotation.NonNull;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.core.common.http.GetDelegate;
|
||||
import com.arialyy.aria.core.common.http.HttpHeaderDelegate;
|
||||
import com.arialyy.aria.core.common.http.PostDelegate;
|
||||
@@ -64,7 +63,7 @@ public class DownloadTarget extends BaseNormalTarget<DownloadTarget>
|
||||
*/
|
||||
@CheckResult
|
||||
public DownloadTarget useServerFileName(boolean use) {
|
||||
mTaskEntity.setUseServerFileName(use);
|
||||
mTaskWrapper.asHttp().setUseServerFileName(use);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,18 +23,17 @@ import com.arialyy.aria.core.download.downloader.SimpleDownloadUtil;
|
||||
import com.arialyy.aria.core.inf.AbsNormalTask;
|
||||
import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulers;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/8/11.
|
||||
* 下载任务类
|
||||
*/
|
||||
public class DownloadTask extends AbsNormalTask<DownloadEntity, DownloadTaskEntity> {
|
||||
public class DownloadTask extends AbsNormalTask<DownloadEntity, DTaskWrapper> {
|
||||
public static final String TAG = "DownloadTask";
|
||||
|
||||
private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) {
|
||||
mTaskEntity = taskEntity;
|
||||
private DownloadTask(DTaskWrapper taskEntity, Handler outHandler) {
|
||||
mTaskWrapper = taskEntity;
|
||||
mOutHandler = outHandler;
|
||||
mContext = AriaManager.APP;
|
||||
mListener = new BaseDListener(this, mOutHandler);
|
||||
@@ -56,7 +55,7 @@ public class DownloadTask extends AbsNormalTask<DownloadEntity, DownloadTaskEnti
|
||||
}
|
||||
|
||||
public DownloadEntity getEntity() {
|
||||
return mTaskEntity.getEntity();
|
||||
return mTaskWrapper.getEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,10 +84,10 @@ public class DownloadTask extends AbsNormalTask<DownloadEntity, DownloadTaskEnti
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
DownloadTaskEntity taskEntity;
|
||||
DTaskWrapper taskEntity;
|
||||
Handler outHandler;
|
||||
|
||||
public Builder(DownloadTaskEntity taskEntity) {
|
||||
public Builder(DTaskWrapper taskEntity) {
|
||||
this.taskEntity = taskEntity;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.FtpUrlEntity;
|
||||
import com.arialyy.aria.core.common.ftp.FTPSConfig;
|
||||
import com.arialyy.aria.core.common.ftp.FtpDelegate;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IFtpTarget;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
@@ -41,9 +41,9 @@ public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget>
|
||||
|
||||
private void init(String key) {
|
||||
mGroupName = key;
|
||||
mTaskEntity = TEManager.getInstance().getFDTEntity(DownloadGroupTaskEntity.class, key);
|
||||
mTaskEntity.setRequestType(AbsTaskEntity.D_FTP_DIR);
|
||||
mEntity = mTaskEntity.getEntity();
|
||||
mTaskWrapper = TEManager.getInstance().getFDTEntity(DGTaskWrapper.class, key);
|
||||
mTaskWrapper.setRequestType(AbsTaskWrapper.D_FTP_DIR);
|
||||
mEntity = mTaskWrapper.getEntity();
|
||||
if (mEntity != null) {
|
||||
mDirPathTemp = mEntity.getDirPath();
|
||||
}
|
||||
@@ -58,12 +58,11 @@ public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget>
|
||||
boolean b = getTargetType() == GROUP_FTP_DIR && checkDirPath() && checkUrl();
|
||||
if (b) {
|
||||
mEntity.save();
|
||||
mTaskEntity.save();
|
||||
if (mTaskEntity.getSubTaskEntities() != null) {
|
||||
if (mTaskWrapper.getSubTaskWrapper() != null) {
|
||||
//初始化子项的登录信息
|
||||
FtpUrlEntity tUrlEntity = mTaskEntity.getUrlEntity();
|
||||
for (DownloadTaskEntity entity : mTaskEntity.getSubTaskEntities()) {
|
||||
FtpUrlEntity urlEntity = entity.getUrlEntity();
|
||||
FtpUrlEntity tUrlEntity = mTaskWrapper.asFtp().getUrlEntity();
|
||||
for (DTaskWrapper wrapper : mTaskWrapper.getSubTaskWrapper()) {
|
||||
FtpUrlEntity urlEntity = wrapper.asFtp().getUrlEntity();
|
||||
urlEntity.needLogin = tUrlEntity.needLogin;
|
||||
urlEntity.account = tUrlEntity.account;
|
||||
urlEntity.user = tUrlEntity.user;
|
||||
@@ -79,12 +78,12 @@ public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget>
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mTaskEntity.getUrlEntity().isFtps) {
|
||||
if (TextUtils.isEmpty(mTaskEntity.getUrlEntity().storePath)) {
|
||||
if (mTaskWrapper.asFtp().getUrlEntity().isFtps) {
|
||||
if (TextUtils.isEmpty(mTaskWrapper.asFtp().getUrlEntity().storePath)) {
|
||||
ALog.e(TAG, "证书路径为空");
|
||||
return false;
|
||||
}
|
||||
if (TextUtils.isEmpty(mTaskEntity.getUrlEntity().keyAlias)) {
|
||||
if (TextUtils.isEmpty(mTaskWrapper.asFtp().getUrlEntity().keyAlias)) {
|
||||
ALog.e(TAG, "证书别名为空");
|
||||
return false;
|
||||
}
|
||||
@@ -121,7 +120,7 @@ public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget>
|
||||
*/
|
||||
@CheckResult
|
||||
public FTPSConfig<FtpDirDownloadTarget> asFtps() {
|
||||
mTaskEntity.getUrlEntity().isFtps = true;
|
||||
mTaskWrapper.asFtp().getUrlEntity().isFtps = true;
|
||||
return new FTPSConfig<>(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.ftp.FTPSConfig;
|
||||
import com.arialyy.aria.core.common.ftp.FtpDelegate;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.common.ftp.FtpTaskDelegate;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IFtpTarget;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@@ -45,9 +46,9 @@ public class FtpDownloadTarget extends BaseNormalTarget<FtpDownloadTarget>
|
||||
|
||||
private void init() {
|
||||
int lastIndex = url.lastIndexOf("/");
|
||||
mEntity.setFileName(url.substring(lastIndex + 1, url.length()));
|
||||
mTaskEntity.setUrlEntity(CommonUtil.getFtpUrlInfo(url));
|
||||
mTaskEntity.setRequestType(AbsTaskEntity.D_FTP);
|
||||
mEntity.setFileName(url.substring(lastIndex + 1));
|
||||
mTaskWrapper.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(url));
|
||||
mTaskWrapper.setRequestType(AbsTaskWrapper.D_FTP);
|
||||
|
||||
mDelegate = new FtpDelegate<>(this);
|
||||
}
|
||||
@@ -59,17 +60,17 @@ public class FtpDownloadTarget extends BaseNormalTarget<FtpDownloadTarget>
|
||||
*/
|
||||
@CheckResult
|
||||
public FTPSConfig<FtpDownloadTarget> asFtps() {
|
||||
mTaskEntity.getUrlEntity().isFtps = true;
|
||||
mTaskWrapper.asFtp().getUrlEntity().isFtps = true;
|
||||
return new FTPSConfig<>(this);
|
||||
}
|
||||
|
||||
@Override protected boolean checkEntity() {
|
||||
if (mTaskEntity.getUrlEntity().isFtps){
|
||||
if (TextUtils.isEmpty(mTaskEntity.getUrlEntity().storePath)){
|
||||
if (mTaskWrapper.asFtp().getUrlEntity().isFtps){
|
||||
if (TextUtils.isEmpty(mTaskWrapper.asFtp().getUrlEntity().storePath)){
|
||||
ALog.e(TAG, "证书路径为空");
|
||||
return false;
|
||||
}
|
||||
if (TextUtils.isEmpty(mTaskEntity.getUrlEntity().keyAlias)){
|
||||
if (TextUtils.isEmpty(mTaskWrapper.asFtp().getUrlEntity().keyAlias)){
|
||||
ALog.e(TAG, "证书别名为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ package com.arialyy.aria.core.download.downloader;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.IUtil;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.exception.BaseException;
|
||||
@@ -56,23 +56,23 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
long mTotalLen = 0;
|
||||
long mCurrentLocation = 0;
|
||||
protected IDownloadGroupListener mListener;
|
||||
DownloadGroupTaskEntity mGTEntity;
|
||||
DGTaskWrapper mGTWrapper;
|
||||
private boolean isRunning = false;
|
||||
private ScheduledThreadPoolExecutor mTimer;
|
||||
/**
|
||||
* 保存所有没有下载完成的任务,key为下载地址
|
||||
*/
|
||||
Map<String, DownloadTaskEntity> mExeMap = new ConcurrentHashMap<>();
|
||||
Map<String, DTaskWrapper> mExeMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 下载失败的映射表,key为下载地址
|
||||
*/
|
||||
Map<String, DownloadTaskEntity> mFailMap = new ConcurrentHashMap<>();
|
||||
Map<String, DTaskWrapper> mFailMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 该任务组对应的所有任务
|
||||
*/
|
||||
private Map<String, DownloadTaskEntity> mTasksMap = new ConcurrentHashMap<>();
|
||||
private Map<String, DTaskWrapper> mTasksMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 下载器映射表,key为下载地址
|
||||
@@ -92,9 +92,9 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
private long mUpdateInterval = 1000;
|
||||
private boolean isStop = false, isCancel = false;
|
||||
|
||||
AbsGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity groupEntity) {
|
||||
AbsGroupUtil(IDownloadGroupListener listener, DGTaskWrapper groupEntity) {
|
||||
mListener = listener;
|
||||
mGTEntity = groupEntity;
|
||||
mGTWrapper = groupEntity;
|
||||
mUpdateInterval =
|
||||
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getUpdateInterval();
|
||||
}
|
||||
@@ -111,8 +111,8 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
*/
|
||||
void updateFileSize() {
|
||||
if (isNeedLoadFileSize) {
|
||||
mGTEntity.getEntity().setFileSize(mTotalLen);
|
||||
mGTEntity.getEntity().update();
|
||||
mGTWrapper.getEntity().setFileSize(mTotalLen);
|
||||
mGTWrapper.getEntity().update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
public void cancelSubTask(String url) {
|
||||
Set<String> urls = mTasksMap.keySet();
|
||||
if (!urls.isEmpty() && urls.contains(url)) {
|
||||
DownloadTaskEntity det = mTasksMap.get(url);
|
||||
DTaskWrapper det = mTasksMap.get(url);
|
||||
if (det != null) {
|
||||
mTotalLen -= det.getEntity().getFileSize();
|
||||
mCurrentLocation -= det.getEntity().getCurrentProgress();
|
||||
@@ -166,7 +166,6 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
mListener.onCancel();
|
||||
}
|
||||
}
|
||||
mGTEntity.update();
|
||||
}
|
||||
Downloader d = getDownloader(url, false);
|
||||
if (d != null) {
|
||||
@@ -182,7 +181,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
* @return {@code true} 任务可以下载
|
||||
*/
|
||||
private boolean checkSubTask(String url, String type) {
|
||||
DownloadTaskEntity entity = mTasksMap.get(url);
|
||||
DTaskWrapper entity = mTasksMap.get(url);
|
||||
if (entity != null) {
|
||||
if (entity.getState() == IEntity.STATE_COMPLETE) {
|
||||
ALog.w(TAG, "任务【" + url + "】已完成," + type + "失败");
|
||||
@@ -267,10 +266,10 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
protected void onPre() {
|
||||
mListener.onPre();
|
||||
isRunning = true;
|
||||
mGroupSize = mGTEntity.getSubTaskEntities().size();
|
||||
mTotalLen = mGTEntity.getEntity().getFileSize();
|
||||
mGroupSize = mGTWrapper.getSubTaskWrapper().size();
|
||||
mTotalLen = mGTWrapper.getEntity().getFileSize();
|
||||
isNeedLoadFileSize = mTotalLen <= 10;
|
||||
for (DownloadTaskEntity te : mGTEntity.getSubTaskEntities()) {
|
||||
for (DTaskWrapper te : mGTWrapper.getSubTaskWrapper()) {
|
||||
File file = new File(te.getKey());
|
||||
if (te.getState() == IEntity.STATE_COMPLETE && file.exists()) {
|
||||
mCompleteNum++;
|
||||
@@ -351,7 +350,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
closeTimer();
|
||||
} else if (mCurrentLocation >= 0) {
|
||||
long t = 0;
|
||||
for (DownloadTaskEntity te : mGTEntity.getSubTaskEntities()) {
|
||||
for (DTaskWrapper te : mGTWrapper.getSubTaskWrapper()) {
|
||||
if (te.getState() == IEntity.STATE_COMPLETE) {
|
||||
t += te.getEntity().getFileSize();
|
||||
} else {
|
||||
@@ -368,7 +367,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
/**
|
||||
* 创建子任务下载器,默认创建完成自动启动
|
||||
*/
|
||||
void createChildDownload(DownloadTaskEntity taskEntity) {
|
||||
void createChildDownload(DTaskWrapper taskEntity) {
|
||||
createChildDownload(taskEntity, true);
|
||||
}
|
||||
|
||||
@@ -377,7 +376,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
*
|
||||
* @param start 是否启动下载
|
||||
*/
|
||||
private Downloader createChildDownload(DownloadTaskEntity taskEntity, boolean start) {
|
||||
private Downloader createChildDownload(DTaskWrapper taskEntity, boolean start) {
|
||||
ChildDownloadListener listener = new ChildDownloadListener(taskEntity);
|
||||
Downloader dt = new Downloader(listener, taskEntity);
|
||||
mDownloaderMap.put(taskEntity.getEntity().getUrl(), dt);
|
||||
@@ -391,7 +390,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
* 子任务事件监听
|
||||
*/
|
||||
private class ChildDownloadListener implements IDownloadListener {
|
||||
private DownloadTaskEntity subTaskEntity;
|
||||
private DTaskWrapper subTaskEntity;
|
||||
private DownloadEntity subEntity;
|
||||
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
|
||||
private long lastSaveTime;
|
||||
@@ -399,7 +398,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
private ScheduledThreadPoolExecutor timer;
|
||||
private boolean isNotNetRetry;
|
||||
|
||||
ChildDownloadListener(DownloadTaskEntity entity) {
|
||||
ChildDownloadListener(DTaskWrapper entity) {
|
||||
subTaskEntity = entity;
|
||||
subEntity = subTaskEntity.getEntity();
|
||||
subEntity.setFailNum(0);
|
||||
@@ -514,7 +513,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
}
|
||||
if (mFailMap.size() == mGroupSize) {
|
||||
mListener.onFail(true, new TaskException(TAG,
|
||||
String.format("任务组【%s】下载失败", mGTEntity.getEntity().getGroupName())));
|
||||
String.format("任务组【%s】下载失败", mGTWrapper.getEntity().getGroupName())));
|
||||
} else if (mFailMap.size() + mCompleteNum >= mExeMap.size()) {
|
||||
mListener.onStop(mCurrentLocation);
|
||||
}
|
||||
@@ -549,7 +548,6 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
subEntity.setComplete(state == IEntity.STATE_COMPLETE);
|
||||
if (state == IEntity.STATE_CANCEL) {
|
||||
subEntity.deleteData();
|
||||
return;
|
||||
} else if (state == IEntity.STATE_STOP) {
|
||||
subEntity.setStopTime(System.currentTimeMillis());
|
||||
} else if (subEntity.isComplete()) {
|
||||
@@ -558,7 +556,6 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
|
||||
} else if (location > 0) {
|
||||
subEntity.setCurrentProgress(location);
|
||||
}
|
||||
subTaskEntity.update();
|
||||
}
|
||||
|
||||
@Override public void supportBreakpoint(boolean support) {
|
||||
|
||||
@@ -19,17 +19,14 @@ import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.ProtocolType;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.common.http.HttpTaskDelegate;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.SSLContextUtil;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.CookieManager;
|
||||
import java.net.CookieStore;
|
||||
import java.net.HttpCookie;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
@@ -55,9 +52,9 @@ class ConnectionHelp {
|
||||
*
|
||||
* @throws MalformedURLException
|
||||
*/
|
||||
static URL handleUrl(String url, AbsTaskEntity taskEntity) throws MalformedURLException {
|
||||
Map<String, String> params = taskEntity.getParams();
|
||||
if (params != null && taskEntity.getRequestEnum() == RequestEnum.GET) {
|
||||
static URL handleUrl(String url, HttpTaskDelegate taskDelegate) throws MalformedURLException {
|
||||
Map<String, String> params = taskDelegate.getParams();
|
||||
if (params != null && taskDelegate.getRequestEnum() == RequestEnum.GET) {
|
||||
if (url.contains("?")) {
|
||||
ALog.e(TAG, String.format("设置参数失败,url中已经有?,url: %s", url));
|
||||
return new URL(CommonUtil.convertUrl(url));
|
||||
@@ -101,11 +98,12 @@ class ConnectionHelp {
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
static HttpURLConnection handleConnection(URL url, AbsTaskEntity taskEntity) throws IOException {
|
||||
static HttpURLConnection handleConnection(URL url, HttpTaskDelegate taskDelegate)
|
||||
throws IOException {
|
||||
HttpURLConnection conn;
|
||||
URLConnection urlConn;
|
||||
if (taskEntity.getProxy() != null) {
|
||||
urlConn = url.openConnection(taskEntity.getProxy());
|
||||
if (taskDelegate.getProxy() != null) {
|
||||
urlConn = url.openConnection(taskDelegate.getProxy());
|
||||
} else {
|
||||
urlConn = url.openConnection();
|
||||
}
|
||||
@@ -132,17 +130,17 @@ class ConnectionHelp {
|
||||
*
|
||||
* @throws ProtocolException
|
||||
*/
|
||||
static HttpURLConnection setConnectParam(DownloadTaskEntity entity, HttpURLConnection conn) {
|
||||
if (entity.getRequestEnum() == RequestEnum.POST) {
|
||||
static HttpURLConnection setConnectParam(HttpTaskDelegate delegate, HttpURLConnection conn) {
|
||||
if (delegate.getRequestEnum() == RequestEnum.POST) {
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.setUseCaches(false);
|
||||
}
|
||||
Set<String> keys = null;
|
||||
if (entity.getHeaders() != null && entity.getHeaders().size() > 0) {
|
||||
keys = entity.getHeaders().keySet();
|
||||
if (delegate.getHeaders() != null && delegate.getHeaders().size() > 0) {
|
||||
keys = delegate.getHeaders().keySet();
|
||||
for (String key : keys) {
|
||||
conn.setRequestProperty(key, entity.getHeaders().get(key));
|
||||
conn.setRequestProperty(key, delegate.getHeaders().get(key));
|
||||
}
|
||||
}
|
||||
if (conn.getRequestProperty("Accept-Language") == null) {
|
||||
@@ -190,7 +188,7 @@ class ConnectionHelp {
|
||||
//302获取重定向地址
|
||||
conn.setInstanceFollowRedirects(false);
|
||||
|
||||
CookieManager manager = entity.getCookieManager();
|
||||
CookieManager manager = delegate.getCookieManager();
|
||||
if (manager != null) {
|
||||
CookieStore store = manager.getCookieStore();
|
||||
if (store != null && store.getCookies().size() > 0) {
|
||||
|
||||
@@ -19,8 +19,8 @@ import android.util.SparseArray;
|
||||
import com.arialyy.aria.core.common.CompleteInfo;
|
||||
import com.arialyy.aria.core.common.IUtil;
|
||||
import com.arialyy.aria.core.common.OnFileInfoCallback;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.exception.BaseException;
|
||||
import com.arialyy.aria.exception.TaskException;
|
||||
@@ -53,8 +53,8 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
||||
*/
|
||||
private SparseArray<OnFileInfoCallback> mFileInfoCallbacks = new SparseArray<>();
|
||||
|
||||
public DownloadGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity taskEntity) {
|
||||
super(listener, taskEntity);
|
||||
public DownloadGroupUtil(IDownloadGroupListener listener, DGTaskWrapper taskWrapper) {
|
||||
super(listener, taskWrapper);
|
||||
mInfoPool = Executors.newCachedThreadPool();
|
||||
}
|
||||
|
||||
@@ -88,13 +88,13 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
||||
|
||||
if (mExeMap.size() == 0) {
|
||||
mListener.onFail(false, new TaskException(TAG,
|
||||
String.format("任务组【%s】无可执行任务", mGTEntity.getEntity().getGroupName())));
|
||||
String.format("任务组【%s】无可执行任务", mGTWrapper.getEntity().getGroupName())));
|
||||
return;
|
||||
}
|
||||
Set<String> keys = mExeMap.keySet();
|
||||
mExeNum = mExeMap.size();
|
||||
for (String key : keys) {
|
||||
DownloadTaskEntity taskEntity = mExeMap.get(key);
|
||||
DTaskWrapper taskEntity = mExeMap.get(key);
|
||||
if (taskEntity != null) {
|
||||
if (taskEntity.getState() != IEntity.STATE_FAIL
|
||||
&& taskEntity.getState() != IEntity.STATE_WAIT) {
|
||||
@@ -114,7 +114,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
||||
/**
|
||||
* 创建文件信息获取线程
|
||||
*/
|
||||
private HttpFileInfoThread createFileInfoThread(DownloadTaskEntity taskEntity) {
|
||||
private HttpFileInfoThread createFileInfoThread(DTaskWrapper taskEntity) {
|
||||
OnFileInfoCallback callback = mFileInfoCallbacks.get(taskEntity.hashCode());
|
||||
|
||||
if (callback == null) {
|
||||
@@ -123,7 +123,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
||||
|
||||
@Override public void onComplete(String url, CompleteInfo info) {
|
||||
if (isStop) return;
|
||||
DownloadTaskEntity te = mExeMap.get(url);
|
||||
DTaskWrapper te = mExeMap.get(url);
|
||||
if (te != null) {
|
||||
if (isNeedLoadFileSize) {
|
||||
mTotalLen += te.getEntity().getFileSize();
|
||||
@@ -138,7 +138,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
||||
@Override public void onFail(String url, BaseException e, boolean needRetry) {
|
||||
if (isStop) return;
|
||||
ALog.e(TAG, String.format("任务【%s】初始化失败", url));
|
||||
DownloadTaskEntity te = mExeMap.get(url);
|
||||
DTaskWrapper te = mExeMap.get(url);
|
||||
if (te != null) {
|
||||
mFailMap.put(url, te);
|
||||
mFileInfoCallbacks.put(te.hashCode(), this);
|
||||
@@ -172,7 +172,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
|
||||
if (mInitFailNum == mExeNum) {
|
||||
closeTimer();
|
||||
mListener.onFail(true, new TaskException(TAG,
|
||||
String.format("任务组【%s】初始化失败", mGTEntity.getEntity().getGroupName())));
|
||||
String.format("任务组【%s】初始化失败", mGTWrapper.getEntity().getGroupName())));
|
||||
}
|
||||
if (!isStart && mInitCompleteNum + mInitFailNum == mExeNum || !isNeedLoadFileSize) {
|
||||
startRunningFlow();
|
||||
|
||||
@@ -20,8 +20,8 @@ import com.arialyy.aria.core.common.AbsFileer;
|
||||
import com.arialyy.aria.core.common.AbsThreadTask;
|
||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.exception.BaseException;
|
||||
import com.arialyy.aria.exception.TaskException;
|
||||
@@ -33,10 +33,10 @@ import java.io.IOException;
|
||||
* Created by AriaL on 2017/7/1.
|
||||
* 文件下载器
|
||||
*/
|
||||
class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
||||
class Downloader extends AbsFileer<DownloadEntity, DTaskWrapper> {
|
||||
private String TAG = "Downloader";
|
||||
|
||||
Downloader(IDownloadListener listener, DownloadTaskEntity taskEntity) {
|
||||
Downloader(IDownloadListener listener, DTaskWrapper taskEntity) {
|
||||
super(listener, taskEntity);
|
||||
mTempFile = new File(mEntity.getDownloadPath());
|
||||
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||
@@ -48,8 +48,8 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
||||
return
|
||||
// 小于1m的文件或是任务组的子任务、使用虚拟文件,线程数都是1
|
||||
mEntity.getFileSize() <= SUB_LEN
|
||||
|| mTaskEntity.getRequestType() == AbsTaskEntity.D_FTP_DIR
|
||||
|| mTaskEntity.getRequestType() == AbsTaskEntity.DG_HTTP
|
||||
|| mTaskEntity.getRequestType() == AbsTaskWrapper.D_FTP_DIR
|
||||
|| mTaskEntity.getRequestType() == AbsTaskWrapper.DG_HTTP
|
||||
|| threadNum == 1
|
||||
? 1
|
||||
: threadNum;
|
||||
@@ -95,12 +95,12 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected AbsThreadTask selectThreadTask(SubThreadConfig<DownloadTaskEntity> config) {
|
||||
@Override protected AbsThreadTask selectThreadTask(SubThreadConfig<DTaskWrapper> config) {
|
||||
switch (mTaskEntity.getRequestType()) {
|
||||
case AbsTaskEntity.D_FTP:
|
||||
case AbsTaskEntity.D_FTP_DIR:
|
||||
case AbsTaskWrapper.D_FTP:
|
||||
case AbsTaskWrapper.D_FTP_DIR:
|
||||
return new FtpThreadTask(mConstance, (IDownloadListener) mListener, config);
|
||||
case AbsTaskEntity.D_HTTP:
|
||||
case AbsTaskWrapper.D_HTTP:
|
||||
return new HttpThreadTask(mConstance, (IDownloadListener) mListener, config);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -17,11 +17,9 @@ package com.arialyy.aria.core.download.downloader;
|
||||
|
||||
import com.arialyy.aria.core.common.CompleteInfo;
|
||||
import com.arialyy.aria.core.common.OnFileInfoCallback;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.exception.BaseException;
|
||||
import com.arialyy.aria.exception.TaskException;
|
||||
import com.arialyy.aria.util.ErrorHelp;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -31,7 +29,7 @@ import java.util.Set;
|
||||
public class FtpDirDownloadUtil extends AbsGroupUtil {
|
||||
private String TAG = "FtpDirDownloadUtil";
|
||||
|
||||
public FtpDirDownloadUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity taskEntity) {
|
||||
public FtpDirDownloadUtil(IDownloadGroupListener listener, DGTaskWrapper taskEntity) {
|
||||
super(listener, taskEntity);
|
||||
}
|
||||
|
||||
@@ -41,11 +39,11 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
|
||||
|
||||
@Override protected void onStart() {
|
||||
super.onStart();
|
||||
if (mGTEntity.getEntity().getFileSize() > 1) {
|
||||
if (mGTWrapper.getEntity().getFileSize() > 1) {
|
||||
onPre();
|
||||
startDownload();
|
||||
} else {
|
||||
new FtpDirInfoThread(mGTEntity, new OnFileInfoCallback() {
|
||||
new FtpDirInfoThread(mGTWrapper, new OnFileInfoCallback() {
|
||||
@Override public void onComplete(String url, CompleteInfo info) {
|
||||
if (info.code >= 200 && info.code < 300) {
|
||||
onPre();
|
||||
@@ -54,7 +52,7 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
|
||||
}
|
||||
|
||||
@Override public void onFail(String url, BaseException e, boolean needRetry) {
|
||||
DownloadTaskEntity te = mExeMap.get(url);
|
||||
DTaskWrapper te = mExeMap.get(url);
|
||||
if (te != null) {
|
||||
mFailMap.put(url, te);
|
||||
mExeMap.remove(url);
|
||||
@@ -73,7 +71,7 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
|
||||
int i = 0;
|
||||
Set<String> keys = mExeMap.keySet();
|
||||
for (String key : keys) {
|
||||
DownloadTaskEntity taskEntity = mExeMap.get(key);
|
||||
DTaskWrapper taskEntity = mExeMap.get(key);
|
||||
if (taskEntity != null) {
|
||||
createChildDownload(taskEntity);
|
||||
i++;
|
||||
|
||||
@@ -20,27 +20,26 @@ import com.arialyy.aria.core.FtpUrlEntity;
|
||||
import com.arialyy.aria.core.common.CompleteInfo;
|
||||
import com.arialyy.aria.core.common.OnFileInfoCallback;
|
||||
import com.arialyy.aria.core.common.ftp.AbsFtpInfoThread;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
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.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/7/25.
|
||||
* 获取ftp文件夹信息
|
||||
* Created by Aria.Lao on 2017/7/25. 获取ftp文件夹信息
|
||||
*/
|
||||
class FtpDirInfoThread extends AbsFtpInfoThread<DownloadGroupEntity, DownloadGroupTaskEntity> {
|
||||
class FtpDirInfoThread extends AbsFtpInfoThread<DownloadGroupEntity, DGTaskWrapper> {
|
||||
|
||||
FtpDirInfoThread(DownloadGroupTaskEntity taskEntity, OnFileInfoCallback callback) {
|
||||
FtpDirInfoThread(DGTaskWrapper taskEntity, OnFileInfoCallback callback) {
|
||||
super(taskEntity, callback);
|
||||
}
|
||||
|
||||
@Override protected String setRemotePath() {
|
||||
return mTaskEntity.getUrlEntity().remotePath;
|
||||
return mTaskWrapper.asFtp().getUrlEntity().remotePath;
|
||||
}
|
||||
|
||||
@Override protected void handleFile(String remotePath, FTPFile ftpFile) {
|
||||
@@ -58,36 +57,36 @@ class FtpDirInfoThread extends AbsFtpInfoThread<DownloadGroupEntity, DownloadGro
|
||||
* FTP文件夹的子任务实体 在这生成
|
||||
*/
|
||||
private void addEntity(String remotePath, FTPFile ftpFile) {
|
||||
final FtpUrlEntity urlEntity = mTaskEntity.getUrlEntity().clone();
|
||||
final FtpUrlEntity urlEntity = mTaskWrapper.asFtp().getUrlEntity().clone();
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
entity.setUrl(
|
||||
urlEntity.scheme + "://" + urlEntity.hostName + ":" + urlEntity.port + "/" + remotePath);
|
||||
entity.setDownloadPath(mEntity.getDirPath() + "/" + remotePath);
|
||||
int lastIndex = remotePath.lastIndexOf("/");
|
||||
String fileName = lastIndex < 0 ? CommonUtil.keyToHashKey(remotePath)
|
||||
: remotePath.substring(lastIndex + 1, remotePath.length());
|
||||
entity.setFileName(new String(fileName.getBytes(), Charset.forName(mTaskEntity.getCharSet())));
|
||||
: remotePath.substring(lastIndex + 1);
|
||||
entity.setFileName(
|
||||
new String(fileName.getBytes(), Charset.forName(mTaskWrapper.asHttp().getCharSet())));
|
||||
entity.setGroupName(mEntity.getGroupName());
|
||||
entity.setGroupChild(true);
|
||||
entity.setFileSize(ftpFile.getSize());
|
||||
entity.insert();
|
||||
|
||||
DownloadTaskEntity taskEntity = new DownloadTaskEntity();
|
||||
DTaskWrapper taskEntity = new DTaskWrapper();
|
||||
taskEntity.setKey(entity.getDownloadPath());
|
||||
taskEntity.setUrl(entity.getUrl());
|
||||
taskEntity.setEntity(entity);
|
||||
taskEntity.setGroupTask(true);
|
||||
taskEntity.setGroupName(mEntity.getGroupName());
|
||||
taskEntity.setRequestType(AbsTaskEntity.D_FTP);
|
||||
taskEntity.setRequestType(AbsTaskWrapper.D_FTP);
|
||||
urlEntity.url = entity.getUrl();
|
||||
urlEntity.remotePath = remotePath;
|
||||
taskEntity.setUrlEntity(urlEntity);
|
||||
taskEntity.insert();
|
||||
taskEntity.asFtp().setUrlEntity(urlEntity);
|
||||
|
||||
if (mEntity.getUrls() == null) {
|
||||
mEntity.setUrls(new ArrayList<String>());
|
||||
}
|
||||
mEntity.getSubEntities().add(entity);
|
||||
mTaskEntity.getSubTaskEntities().add(taskEntity);
|
||||
mTaskWrapper.getSubTaskWrapper().add(taskEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ import aria.apache.commons.net.ftp.FTPFile;
|
||||
import com.arialyy.aria.core.common.CompleteInfo;
|
||||
import com.arialyy.aria.core.common.OnFileInfoCallback;
|
||||
import com.arialyy.aria.core.common.ftp.AbsFtpInfoThread;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.exception.AriaIOException;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
|
||||
@@ -28,10 +28,10 @@ import com.arialyy.aria.util.CommonUtil;
|
||||
* Created by Aria.Lao on 2017/7/25.
|
||||
* 获取ftp文件信息
|
||||
*/
|
||||
class FtpFileInfoThread extends AbsFtpInfoThread<DownloadEntity, DownloadTaskEntity> {
|
||||
class FtpFileInfoThread extends AbsFtpInfoThread<DownloadEntity, DTaskWrapper> {
|
||||
private final String TAG = "FtpFileInfoThread";
|
||||
|
||||
FtpFileInfoThread(DownloadTaskEntity taskEntity, OnFileInfoCallback callback) {
|
||||
FtpFileInfoThread(DTaskWrapper taskEntity, OnFileInfoCallback callback) {
|
||||
super(taskEntity, callback);
|
||||
}
|
||||
|
||||
@@ -46,13 +46,13 @@ class FtpFileInfoThread extends AbsFtpInfoThread<DownloadEntity, DownloadTaskEnt
|
||||
}
|
||||
|
||||
@Override protected String setRemotePath() {
|
||||
return mTaskEntity.getUrlEntity().remotePath;
|
||||
return mTaskWrapper.asFtp().getUrlEntity().remotePath;
|
||||
}
|
||||
|
||||
@Override protected void onPreComplete(int code) {
|
||||
super.onPreComplete(code);
|
||||
if (mSize != mTaskEntity.getEntity().getFileSize()) {
|
||||
mTaskEntity.setNewTask(true);
|
||||
if (mSize != mTaskWrapper.getEntity().getFileSize()) {
|
||||
mTaskWrapper.setNewTask(true);
|
||||
}
|
||||
mEntity.setFileSize(mSize);
|
||||
mCallback.onComplete(mEntity.getUrl(), new CompleteInfo(code));
|
||||
|
||||
@@ -20,8 +20,8 @@ import aria.apache.commons.net.ftp.FTPReply;
|
||||
import com.arialyy.aria.core.common.StateConstance;
|
||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.exception.AriaIOException;
|
||||
import com.arialyy.aria.exception.TaskException;
|
||||
@@ -39,13 +39,13 @@ import java.nio.channels.ReadableByteChannel;
|
||||
* Created by Aria.Lao on 2017/7/24.
|
||||
* Ftp下载任务
|
||||
*/
|
||||
class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity> {
|
||||
class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DTaskWrapper> {
|
||||
private final String TAG = "FtpThreadTask";
|
||||
private boolean isOpenDynamicFile;
|
||||
private boolean isBlock;
|
||||
|
||||
FtpThreadTask(StateConstance constance, IDownloadListener listener,
|
||||
SubThreadConfig<DownloadTaskEntity> downloadInfo) {
|
||||
SubThreadConfig<DTaskWrapper> downloadInfo) {
|
||||
super(constance, listener, downloadInfo);
|
||||
mConnectTimeOut = mAridManager.getDownloadConfig().getConnectTimeOut();
|
||||
mReadTimeOut = mAridManager.getDownloadConfig().getIOTimeOut();
|
||||
@@ -87,7 +87,7 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
|
||||
return this;
|
||||
}
|
||||
String remotePath =
|
||||
new String(mTaskEntity.getUrlEntity().remotePath.getBytes(charSet), SERVER_CHARSET);
|
||||
new String(mTaskWrapper.asFtp().getUrlEntity().remotePath.getBytes(charSet), SERVER_CHARSET);
|
||||
ALog.i(TAG, String.format("remotePath【%s】", remotePath));
|
||||
is = client.retrieveFileStream(remotePath);
|
||||
reply = client.getReplyCode();
|
||||
|
||||
@@ -17,13 +17,13 @@ package com.arialyy.aria.core.download.downloader;
|
||||
|
||||
import android.os.Process;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.common.CompleteInfo;
|
||||
import com.arialyy.aria.core.common.OnFileInfoCallback;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.common.http.HttpTaskDelegate;
|
||||
import com.arialyy.aria.exception.AriaIOException;
|
||||
import com.arialyy.aria.exception.BaseException;
|
||||
import com.arialyy.aria.exception.TaskException;
|
||||
@@ -35,14 +35,12 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.CookieHandler;
|
||||
import java.net.CookieManager;
|
||||
import java.net.HttpCookie;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -53,25 +51,27 @@ import java.util.Set;
|
||||
class HttpFileInfoThread implements Runnable {
|
||||
private final String TAG = "HttpFileInfoThread";
|
||||
private DownloadEntity mEntity;
|
||||
private DownloadTaskEntity mTaskEntity;
|
||||
private DTaskWrapper mTaskWrapper;
|
||||
private int mConnectTimeOut;
|
||||
private OnFileInfoCallback onFileInfoCallback;
|
||||
private HttpTaskDelegate mTaskDelegate;
|
||||
|
||||
HttpFileInfoThread(DownloadTaskEntity taskEntity, OnFileInfoCallback callback) {
|
||||
this.mTaskEntity = taskEntity;
|
||||
mEntity = taskEntity.getEntity();
|
||||
HttpFileInfoThread(DTaskWrapper taskWrapper, OnFileInfoCallback callback) {
|
||||
this.mTaskWrapper = taskWrapper;
|
||||
mEntity = taskWrapper.getEntity();
|
||||
mConnectTimeOut =
|
||||
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getConnectTimeOut();
|
||||
onFileInfoCallback = callback;
|
||||
mTaskDelegate = taskWrapper.asHttp();
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||
HttpURLConnection conn = null;
|
||||
try {
|
||||
URL url = ConnectionHelp.handleUrl(mEntity.getUrl(), mTaskEntity);
|
||||
conn = ConnectionHelp.handleConnection(url, mTaskEntity);
|
||||
conn = ConnectionHelp.setConnectParam(mTaskEntity, conn);
|
||||
URL url = ConnectionHelp.handleUrl(mEntity.getUrl(), mTaskDelegate);
|
||||
conn = ConnectionHelp.handleConnection(url, mTaskDelegate);
|
||||
ConnectionHelp.setConnectParam(mTaskDelegate, conn);
|
||||
conn.setRequestProperty("Range", "bytes=" + 0 + "-");
|
||||
conn.setConnectTimeout(mConnectTimeOut);
|
||||
//conn.setChunkedStreamingMode(0);
|
||||
@@ -89,8 +89,8 @@ class HttpFileInfoThread implements Runnable {
|
||||
}
|
||||
|
||||
private void handleConnect(HttpURLConnection conn) throws IOException {
|
||||
if (mTaskEntity.getRequestEnum() == RequestEnum.POST) {
|
||||
Map<String, String> params = mTaskEntity.getParams();
|
||||
if (mTaskDelegate.getRequestEnum() == RequestEnum.POST) {
|
||||
Map<String, String> params = mTaskDelegate.getParams();
|
||||
if (params != null) {
|
||||
OutputStreamWriter dos = new OutputStreamWriter(conn.getOutputStream());
|
||||
Set<String> keys = params.keySet();
|
||||
@@ -144,7 +144,7 @@ class HttpFileInfoThread implements Runnable {
|
||||
}
|
||||
Map<String, List<String>> headers = conn.getHeaderFields();
|
||||
String disposition = conn.getHeaderField("Content-Disposition");
|
||||
if (mTaskEntity.isUseServerFileName() && !TextUtils.isEmpty(disposition)) {
|
||||
if (mTaskDelegate.isUseServerFileName() && !TextUtils.isEmpty(disposition)) {
|
||||
mEntity.setDisposition(CommonUtil.encryptBASE64(disposition));
|
||||
if (disposition.contains(";")) {
|
||||
String[] infos = disposition.split(";");
|
||||
@@ -168,10 +168,10 @@ class HttpFileInfoThread implements Runnable {
|
||||
for (String cookie : cookiesHeader) {
|
||||
msCookieManager.getCookieStore().add(null, HttpCookie.parse(cookie).get(0));
|
||||
}
|
||||
mTaskEntity.setCookieManager(msCookieManager);
|
||||
mTaskDelegate.setCookieManager(msCookieManager);
|
||||
}
|
||||
|
||||
mTaskEntity.setCode(code);
|
||||
mTaskWrapper.setCode(code);
|
||||
if (code == HttpURLConnection.HTTP_PARTIAL) {
|
||||
if (!checkLen(len) && !isChunked) {
|
||||
if (len < 0) {
|
||||
@@ -182,7 +182,7 @@ class HttpFileInfoThread implements Runnable {
|
||||
return;
|
||||
}
|
||||
mEntity.setFileSize(len);
|
||||
mTaskEntity.setSupportBP(true);
|
||||
mTaskWrapper.setSupportBP(true);
|
||||
end = true;
|
||||
} else if (code == HttpURLConnection.HTTP_OK) {
|
||||
String contentType = conn.getHeaderField("Content-Type");
|
||||
@@ -210,8 +210,8 @@ class HttpFileInfoThread implements Runnable {
|
||||
return;
|
||||
}
|
||||
mEntity.setFileSize(len);
|
||||
mTaskEntity.setNewTask(true);
|
||||
mTaskEntity.setSupportBP(false);
|
||||
mTaskWrapper.setNewTask(true);
|
||||
mTaskWrapper.setSupportBP(false);
|
||||
end = true;
|
||||
} else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||
failDownload(new AriaIOException(TAG,
|
||||
@@ -228,8 +228,7 @@ class HttpFileInfoThread implements Runnable {
|
||||
conn.getResponseMessage(), mEntity.getUrl())), true);
|
||||
}
|
||||
if (end) {
|
||||
mTaskEntity.setChunked(isChunked);
|
||||
mTaskEntity.update();
|
||||
mTaskDelegate.setChunked(isChunked);
|
||||
if (onFileInfoCallback != null) {
|
||||
CompleteInfo info = new CompleteInfo(code);
|
||||
onFileInfoCallback.onComplete(mEntity.getUrl(), info);
|
||||
@@ -252,7 +251,7 @@ class HttpFileInfoThread implements Runnable {
|
||||
}
|
||||
mEntity.setFileName(newName);
|
||||
mEntity.setDownloadPath(newPath);
|
||||
mTaskEntity.setKey(newPath);
|
||||
mTaskWrapper.setKey(newPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,13 +270,13 @@ class HttpFileInfoThread implements Runnable {
|
||||
failDownload(new TaskException(TAG, "下载失败,重定向url错误"), false);
|
||||
return;
|
||||
}
|
||||
mTaskEntity.setRedirectUrl(newUrl);
|
||||
mTaskDelegate.setRedirectUrl(newUrl);
|
||||
mEntity.setRedirect(true);
|
||||
mEntity.setRedirectUrl(newUrl);
|
||||
String cookies = conn.getHeaderField("Set-Cookie");
|
||||
URL url = ConnectionHelp.handleUrl(newUrl, mTaskEntity);
|
||||
conn = ConnectionHelp.handleConnection(url, mTaskEntity);
|
||||
conn = ConnectionHelp.setConnectParam(mTaskEntity, conn);
|
||||
URL url = ConnectionHelp.handleUrl(newUrl, mTaskDelegate);
|
||||
conn = ConnectionHelp.handleConnection(url, mTaskDelegate);
|
||||
ConnectionHelp.setConnectParam(mTaskDelegate, conn);
|
||||
conn.setRequestProperty("Cookie", cookies);
|
||||
conn.setRequestProperty("Range", "bytes=" + 0 + "-");
|
||||
conn.setConnectTimeout(mConnectTimeOut);
|
||||
@@ -294,7 +293,7 @@ class HttpFileInfoThread implements Runnable {
|
||||
*/
|
||||
private boolean checkLen(long len) {
|
||||
if (len != mEntity.getFileSize()) {
|
||||
mTaskEntity.setNewTask(true);
|
||||
mTaskWrapper.setNewTask(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@ import com.arialyy.aria.core.common.AbsThreadTask;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.core.common.StateConstance;
|
||||
import com.arialyy.aria.core.common.SubThreadConfig;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.common.http.HttpTaskDelegate;
|
||||
import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.exception.AriaIOException;
|
||||
import com.arialyy.aria.exception.TaskException;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.BufferedRandomAccessFile;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -47,13 +47,13 @@ import java.util.Set;
|
||||
* Created by lyy on 2017/1/18.
|
||||
* 下载线程
|
||||
*/
|
||||
final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEntity> {
|
||||
final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DTaskWrapper> {
|
||||
private final String TAG = "HttpThreadTask";
|
||||
private boolean isOpenDynamicFile;
|
||||
private boolean isBlock;
|
||||
|
||||
HttpThreadTask(StateConstance constance, IDownloadListener listener,
|
||||
SubThreadConfig<DownloadTaskEntity> downloadInfo) {
|
||||
SubThreadConfig<DTaskWrapper> downloadInfo) {
|
||||
super(constance, listener, downloadInfo);
|
||||
mConnectTimeOut = mAridManager.getDownloadConfig().getConnectTimeOut();
|
||||
mReadTimeOut = mAridManager.getDownloadConfig().getIOTimeOut();
|
||||
@@ -75,8 +75,9 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
||||
//当前子线程的下载位置
|
||||
mChildCurrentLocation = mConfig.START_LOCATION;
|
||||
try {
|
||||
URL url = ConnectionHelp.handleUrl(mConfig.URL, mTaskEntity);
|
||||
conn = ConnectionHelp.handleConnection(url, mTaskEntity);
|
||||
HttpTaskDelegate taskDelegate = mTaskWrapper.asHttp();
|
||||
URL url = ConnectionHelp.handleUrl(mConfig.URL, taskDelegate);
|
||||
conn = ConnectionHelp.handleConnection(url, taskDelegate);
|
||||
if (mConfig.SUPPORT_BP) {
|
||||
ALog.d(TAG,
|
||||
String.format("任务【%s】线程__%s__开始下载【开始位置 : %s,结束位置:%s】", mConfig.TEMP_FILE.getName(),
|
||||
@@ -86,12 +87,12 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
||||
} else {
|
||||
ALog.w(TAG, "该下载不支持断点");
|
||||
}
|
||||
conn = ConnectionHelp.setConnectParam(mConfig.TASK_ENTITY, conn);
|
||||
ConnectionHelp.setConnectParam(taskDelegate, conn);
|
||||
conn.setConnectTimeout(mConnectTimeOut);
|
||||
conn.setReadTimeout(mReadTimeOut); //设置读取流的等待时间,必须设置该参数
|
||||
conn.connect();
|
||||
if (mTaskEntity.getRequestEnum() == RequestEnum.POST) {
|
||||
Map<String, String> params = mTaskEntity.getParams();
|
||||
if (taskDelegate.getRequestEnum() == RequestEnum.POST) {
|
||||
Map<String, String> params = taskDelegate.getParams();
|
||||
if (params != null) {
|
||||
OutputStreamWriter dos = new OutputStreamWriter(conn.getOutputStream());
|
||||
Set<String> keys = params.keySet();
|
||||
@@ -115,7 +116,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
||||
file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize);
|
||||
//设置每条线程写入文件的位置
|
||||
file.seek(mConfig.START_LOCATION);
|
||||
if (mTaskEntity.isChunked()) {
|
||||
if (taskDelegate.isChunked()) {
|
||||
readChunk(is, file);
|
||||
} else {
|
||||
readNormal(is, file);
|
||||
|
||||
@@ -19,12 +19,11 @@ package com.arialyy.aria.core.download.downloader;
|
||||
import com.arialyy.aria.core.common.CompleteInfo;
|
||||
import com.arialyy.aria.core.common.IUtil;
|
||||
import com.arialyy.aria.core.common.OnFileInfoCallback;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IDownloadListener;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.exception.BaseException;
|
||||
import com.arialyy.aria.exception.TaskException;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2015/8/25.
|
||||
@@ -34,10 +33,10 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
|
||||
private String TAG = "SimpleDownloadUtil";
|
||||
private IDownloadListener mListener;
|
||||
private Downloader mDownloader;
|
||||
private DownloadTaskEntity mTaskEntity;
|
||||
private DTaskWrapper mTaskEntity;
|
||||
private boolean isStop = false, isCancel = false;
|
||||
|
||||
public SimpleDownloadUtil(DownloadTaskEntity entity, IDownloadListener downloadListener) {
|
||||
public SimpleDownloadUtil(DTaskWrapper entity, IDownloadListener downloadListener) {
|
||||
mTaskEntity = entity;
|
||||
mListener = downloadListener;
|
||||
mDownloader = new Downloader(downloadListener, entity);
|
||||
@@ -106,7 +105,7 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
|
||||
}
|
||||
if (mTaskEntity.getEntity().getFileSize() <= 1
|
||||
|| mTaskEntity.isRefreshInfo()
|
||||
|| mTaskEntity.getRequestType() == AbsTaskEntity.D_FTP
|
||||
|| mTaskEntity.getRequestType() == AbsTaskWrapper.D_FTP
|
||||
|| mTaskEntity.getState() == IEntity.STATE_FAIL) {
|
||||
new Thread(createInfoThread()).start();
|
||||
} else {
|
||||
@@ -119,7 +118,7 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
|
||||
*/
|
||||
private Runnable createInfoThread() {
|
||||
switch (mTaskEntity.getRequestType()) {
|
||||
case AbsTaskEntity.D_FTP:
|
||||
case AbsTaskWrapper.D_FTP:
|
||||
return new FtpFileInfoThread(mTaskEntity, new OnFileInfoCallback() {
|
||||
@Override public void onComplete(String url, CompleteInfo info) {
|
||||
mDownloader.start();
|
||||
@@ -130,7 +129,7 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
|
||||
mDownloader.closeTimer();
|
||||
}
|
||||
});
|
||||
case AbsTaskEntity.D_HTTP:
|
||||
case AbsTaskWrapper.D_HTTP:
|
||||
return new HttpFileInfoThread(mTaskEntity, new OnFileInfoCallback() {
|
||||
@Override public void onComplete(String url, CompleteInfo info) {
|
||||
mDownloader.start();
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.download.wrapper;
|
||||
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.orm.AbsWrapper;
|
||||
import com.arialyy.aria.orm.annotation.Many;
|
||||
import com.arialyy.aria.orm.annotation.One;
|
||||
@@ -31,14 +31,14 @@ import java.util.List;
|
||||
public class DGSTEWrapper extends AbsWrapper {
|
||||
|
||||
@One
|
||||
public DownloadGroupTaskEntity dgTaskEntity;
|
||||
public DGTaskWrapper dgTaskEntity;
|
||||
|
||||
@Many(parentColumn = "key", entityColumn = "groupName")
|
||||
public List<DownloadTaskEntity> subTaskEntity;
|
||||
public List<DTaskWrapper> subTaskEntity;
|
||||
|
||||
@Override protected void handleConvert() {
|
||||
if (subTaskEntity != null && !subTaskEntity.isEmpty()) {
|
||||
dgTaskEntity.setSubTaskEntities(subTaskEntity);
|
||||
dgTaskEntity.setSubTaskWrapper(subTaskEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.download.wrapper;
|
||||
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
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.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.orm.AbsWrapper;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.orm.annotation.Many;
|
||||
@@ -39,26 +39,26 @@ public class DGTEWrapper extends AbsWrapper {
|
||||
public DownloadGroupEntity entity;
|
||||
|
||||
@Many(parentColumn = "groupName", entityColumn = "key")
|
||||
private List<DownloadGroupTaskEntity> taskEntitys;
|
||||
private List<DGTaskWrapper> taskEntitys;
|
||||
|
||||
public DownloadGroupTaskEntity taskEntity;
|
||||
public DGTaskWrapper taskEntity;
|
||||
|
||||
@Override protected void handleConvert() {
|
||||
taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0);
|
||||
if (taskEntity != null) {
|
||||
taskEntity.setEntity(entity);
|
||||
List<DTEWrapper> subWrappers =
|
||||
DbEntity.findRelationData(DTEWrapper.class, "DownloadTaskEntity.groupName=?",
|
||||
DbEntity.findRelationData(DTEWrapper.class, "DTaskWrapper.groupName=?",
|
||||
taskEntity.getKey());
|
||||
if (subWrappers != null && !subWrappers.isEmpty()) {
|
||||
List<DownloadTaskEntity> temp = new ArrayList<>();
|
||||
List<DTaskWrapper> temp = new ArrayList<>();
|
||||
for (DTEWrapper dw : subWrappers) {
|
||||
if (dw.taskEntity.getRequestType() == AbsTaskEntity.D_FTP) {
|
||||
dw.taskEntity.setUrlEntity(CommonUtil.getFtpUrlInfo(dw.taskEntity.getUrl()));
|
||||
if (dw.taskEntity.getRequestType() == AbsTaskWrapper.D_FTP) {
|
||||
dw.taskEntity.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(dw.taskEntity.getUrl()));
|
||||
}
|
||||
temp.add(dw.taskEntity);
|
||||
}
|
||||
taskEntity.setSubTaskEntities(temp);
|
||||
taskEntity.setSubTaskWrapper(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package com.arialyy.aria.core.download.wrapper;
|
||||
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.orm.AbsWrapper;
|
||||
import com.arialyy.aria.orm.annotation.Many;
|
||||
import com.arialyy.aria.orm.annotation.One;
|
||||
@@ -33,9 +33,9 @@ public class DTEWrapper extends AbsWrapper {
|
||||
public DownloadEntity entity;
|
||||
|
||||
@Many(parentColumn = "downloadPath", entityColumn = "key")
|
||||
private List<DownloadTaskEntity> taskEntitys = null;
|
||||
private List<DTaskWrapper> taskEntitys = null;
|
||||
|
||||
public DownloadTaskEntity taskEntity;
|
||||
public DTaskWrapper taskEntity;
|
||||
|
||||
@Override public void handleConvert() {
|
||||
taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0);
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.os.Parcelable;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.orm.annotation.Ignore;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/6/29.
|
||||
*/
|
||||
@@ -180,8 +179,8 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable,
|
||||
/**
|
||||
* 实体驱动的下载任务类型
|
||||
*
|
||||
* @return {@link AbsTaskEntity#D_FTP}、{@link AbsTaskEntity#D_FTP_DIR}、{@link
|
||||
* AbsTaskEntity#U_HTTP}...
|
||||
* @return {@link AbsTaskWrapper#D_FTP}、{@link AbsTaskWrapper#D_FTP_DIR}、{@link
|
||||
* AbsTaskWrapper#U_HTTP}...
|
||||
*/
|
||||
public abstract int getTaskType();
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ import com.arialyy.aria.core.download.downloader.AbsGroupUtil;
|
||||
* Created by AriaL on 2017/6/29.
|
||||
* 任务组任务抽象类
|
||||
*/
|
||||
public abstract class AbsGroupTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsGroupTaskEntity>
|
||||
public abstract class AbsGroupTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsGroupTaskWrapper>
|
||||
extends AbsTask<ENTITY, TASK_ENTITY> {
|
||||
|
||||
@Override public String getKey() {
|
||||
return mTaskEntity.getEntity().getKey();
|
||||
return mTaskWrapper.getEntity().getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,26 +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.inf;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/9/5.
|
||||
*/
|
||||
public abstract class AbsGroupTaskEntity<ENTITY extends AbsGroupEntity> extends AbsTaskEntity<ENTITY>{
|
||||
@Override public ENTITY getEntity() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -15,17 +15,16 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.inf;
|
||||
|
||||
import java.util.Map;
|
||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* post 通用处理接口
|
||||
* 组合任务实体包裹器,用于加载和任务相关的参数,如:组合任务实体{@link DownloadGroupEntity}
|
||||
*/
|
||||
public interface IPostDelegate<TARGET extends ITarget> {
|
||||
public abstract class AbsGroupTaskWrapper<ENTITY extends AbsEntity, SUB extends AbsTaskWrapper>
|
||||
extends AbsTaskWrapper<ENTITY> {
|
||||
|
||||
/**
|
||||
* 设置Post请求参数
|
||||
*/
|
||||
TARGET setParams(Map<String, String> params);
|
||||
public abstract List<SUB> getSubTaskWrapper();
|
||||
|
||||
TARGET setParam(String key, String value);
|
||||
public abstract void setSubTaskWrapper(List<SUB> subTaskWrapper);
|
||||
}
|
||||
@@ -18,8 +18,8 @@ package com.arialyy.aria.core.inf;
|
||||
/**
|
||||
* Created by lyy on 2017/6/3.
|
||||
*/
|
||||
public abstract class AbsNormalTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsNormalTaskEntity>
|
||||
extends AbsTask<ENTITY, TASK_ENTITY> {
|
||||
public abstract class AbsNormalTask<ENTITY extends AbsEntity, TASK_WRAPPER extends AbsTaskWrapper>
|
||||
extends AbsTask<ENTITY, TASK_WRAPPER> {
|
||||
|
||||
/**
|
||||
* 最高优先级命令,最高优先级命令有以下属性
|
||||
|
||||
@@ -22,12 +22,11 @@ import com.arialyy.aria.core.command.ICmd;
|
||||
import com.arialyy.aria.core.command.normal.CancelCmd;
|
||||
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
|
||||
import com.arialyy.aria.core.common.TaskRecord;
|
||||
import com.arialyy.aria.core.common.http.PostDelegate;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
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.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.manager.TEManager;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
@@ -37,11 +36,11 @@ import java.util.List;
|
||||
/**
|
||||
* Created by AriaL on 2017/7/3.
|
||||
*/
|
||||
public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity>
|
||||
public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEntity, TASK_WRAPPER extends AbsTaskWrapper>
|
||||
implements ITarget {
|
||||
protected String TAG;
|
||||
protected ENTITY mEntity;
|
||||
protected TASK_ENTITY mTaskEntity;
|
||||
protected TASK_WRAPPER mTaskWrapper;
|
||||
protected String mTargetName;
|
||||
|
||||
protected AbsTarget() {
|
||||
@@ -55,8 +54,8 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
*/
|
||||
@CheckResult(suggest = "after use #start()、#stop()、#cancel()、#resume()、#save()?")
|
||||
public TARGET resetState() {
|
||||
mTaskEntity.getEntity().setState(IEntity.STATE_WAIT);
|
||||
mTaskEntity.setRefreshInfo(true);
|
||||
mTaskWrapper.getEntity().setState(IEntity.STATE_WAIT);
|
||||
mTaskWrapper.setRefreshInfo(true);
|
||||
return (TARGET) this;
|
||||
}
|
||||
|
||||
@@ -70,14 +69,14 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
} else {
|
||||
if (mEntity instanceof AbsNormalEntity) {
|
||||
TaskRecord record =
|
||||
DbEntity.findFirst(TaskRecord.class, "TaskRecord.filePath=?", mTaskEntity.getKey());
|
||||
DbEntity.findFirst(TaskRecord.class, "TaskRecord.filePath=?", mTaskWrapper.getKey());
|
||||
if (record != null) {
|
||||
CommonUtil.delTaskRecord(record, mTaskEntity.isRemoveFile(), (AbsNormalEntity) mEntity);
|
||||
CommonUtil.delTaskRecord(record, mTaskWrapper.isRemoveFile(), (AbsNormalEntity) mEntity);
|
||||
} else {
|
||||
mEntity.deleteData();
|
||||
}
|
||||
} else if (mEntity instanceof DownloadGroupEntity) {
|
||||
CommonUtil.delGroupTaskRecord(mTaskEntity.isRemoveFile(), ((DownloadGroupEntity) mEntity));
|
||||
CommonUtil.delGroupTaskRecord(mTaskWrapper.isRemoveFile(), ((DownloadGroupEntity) mEntity));
|
||||
}
|
||||
TEManager.getInstance().removeTEntity(mEntity.getKey());
|
||||
}
|
||||
@@ -86,8 +85,8 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
/**
|
||||
* 获取任务实体
|
||||
*/
|
||||
public TASK_ENTITY getTaskEntity() {
|
||||
return mTaskEntity;
|
||||
public TASK_WRAPPER getTaskWrapper() {
|
||||
return mTaskWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,11 +177,11 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
|
||||
protected int checkTaskType() {
|
||||
int taskType = 0;
|
||||
if (mTaskEntity instanceof DownloadTaskEntity) {
|
||||
if (mTaskWrapper instanceof DTaskWrapper) {
|
||||
taskType = ICmd.TASK_TYPE_DOWNLOAD;
|
||||
} else if (mTaskEntity instanceof DownloadGroupTaskEntity) {
|
||||
} else if (mTaskWrapper instanceof DGTaskWrapper) {
|
||||
taskType = ICmd.TASK_TYPE_DOWNLOAD_GROUP;
|
||||
} else if (mTaskEntity instanceof UploadTaskEntity) {
|
||||
} else if (mTaskWrapper instanceof UTaskWrapper) {
|
||||
taskType = ICmd.TASK_TYPE_UPLOAD;
|
||||
}
|
||||
return taskType;
|
||||
@@ -218,7 +217,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
if (checkEntity()) {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(
|
||||
CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_START, checkTaskType()))
|
||||
CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_START, checkTaskType()))
|
||||
.exe();
|
||||
}
|
||||
}
|
||||
@@ -238,7 +237,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
if (checkEntity()) {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(
|
||||
CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_STOP, checkTaskType()))
|
||||
CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_STOP, checkTaskType()))
|
||||
.exe();
|
||||
}
|
||||
}
|
||||
@@ -250,7 +249,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
if (checkEntity()) {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(
|
||||
CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_START, checkTaskType()))
|
||||
CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_START, checkTaskType()))
|
||||
.exe();
|
||||
}
|
||||
}
|
||||
@@ -261,7 +260,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
@Override public void cancel() {
|
||||
if (checkEntity()) {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_CANCEL,
|
||||
.setCmd(CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_CANCEL,
|
||||
checkTaskType()))
|
||||
.exe();
|
||||
}
|
||||
@@ -275,8 +274,8 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
List<ICmd> cmds = new ArrayList<>();
|
||||
int taskType = checkTaskType();
|
||||
cmds.add(
|
||||
CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_STOP, taskType));
|
||||
cmds.add(CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_START, taskType));
|
||||
CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_STOP, taskType));
|
||||
cmds.add(CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_START, taskType));
|
||||
AriaManager.getInstance(AriaManager.APP).setCmds(cmds).exe();
|
||||
}
|
||||
}
|
||||
@@ -290,7 +289,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
|
||||
public void cancel(boolean removeFile) {
|
||||
if (checkEntity()) {
|
||||
CancelCmd cancelCmd =
|
||||
(CancelCmd) CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_CANCEL,
|
||||
(CancelCmd) CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_CANCEL,
|
||||
checkTaskType());
|
||||
cancelCmd.removeFile = removeFile;
|
||||
AriaManager.getInstance(AriaManager.APP).setCmd(cancelCmd).exe();
|
||||
|
||||
@@ -17,7 +17,6 @@ package com.arialyy.aria.core.inf;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.IUtil;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
@@ -28,15 +27,15 @@ import java.util.Map;
|
||||
/**
|
||||
* Created by AriaL on 2017/6/29.
|
||||
*/
|
||||
public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity>
|
||||
implements ITask<TASK_ENTITY> {
|
||||
public abstract class AbsTask<ENTITY extends AbsEntity, TASK_WRAPPER extends AbsTaskWrapper>
|
||||
implements ITask<TASK_WRAPPER> {
|
||||
public static final String ERROR_INFO_KEY = "ERROR_INFO_KEY";
|
||||
|
||||
/**
|
||||
* 是否需要重试,默认为true
|
||||
*/
|
||||
public boolean needRetry = true;
|
||||
protected TASK_ENTITY mTaskEntity;
|
||||
protected TASK_WRAPPER mTaskWrapper;
|
||||
protected Handler mOutHandler;
|
||||
protected Context mContext;
|
||||
boolean isHeighestTask = false;
|
||||
@@ -101,14 +100,14 @@ public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsT
|
||||
* @return {@code true} 已经完成,{@code false} 未完成
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
return mTaskEntity.getEntity().isComplete();
|
||||
return mTaskWrapper.getEntity().isComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前下载进度
|
||||
*/
|
||||
@Override public long getCurrentProgress() {
|
||||
return mTaskEntity.getEntity().getCurrentProgress();
|
||||
return mTaskWrapper.getEntity().getCurrentProgress();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,10 +116,10 @@ public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsT
|
||||
* @return 如:已经下载3mb的大小,则返回{@code 3mb}
|
||||
*/
|
||||
@Override public String getConvertCurrentProgress() {
|
||||
if (mTaskEntity.getEntity().getCurrentProgress() == 0) {
|
||||
if (mTaskWrapper.getEntity().getCurrentProgress() == 0) {
|
||||
return "0b";
|
||||
}
|
||||
return CommonUtil.formatFileSize(mTaskEntity.getEntity().getCurrentProgress());
|
||||
return CommonUtil.formatFileSize(mTaskWrapper.getEntity().getCurrentProgress());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,17 +128,17 @@ public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsT
|
||||
* @return 如果文件长度为0,则返回0m,否则返回转换后的长度1b、1kb、1mb、1gb、1tb
|
||||
*/
|
||||
@Override public String getConvertFileSize() {
|
||||
if (mTaskEntity.getEntity().getFileSize() == 0) {
|
||||
if (mTaskWrapper.getEntity().getFileSize() == 0) {
|
||||
return "0mb";
|
||||
}
|
||||
return CommonUtil.formatFileSize(mTaskEntity.getEntity().getFileSize());
|
||||
return CommonUtil.formatFileSize(mTaskWrapper.getEntity().getFileSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件大小
|
||||
*/
|
||||
@Override public long getFileSize() {
|
||||
return mTaskEntity.getEntity().getFileSize();
|
||||
return mTaskWrapper.getEntity().getFileSize();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,10 +147,10 @@ public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsT
|
||||
* @return 返回百分比进度,如果文件长度为0,返回0
|
||||
*/
|
||||
@Override public int getPercent() {
|
||||
if (mTaskEntity.getEntity().getFileSize() == 0) {
|
||||
if (mTaskWrapper.getEntity().getFileSize() == 0) {
|
||||
return 0;
|
||||
}
|
||||
return (int) (mTaskEntity.getEntity().getCurrentProgress() * 100 / mTaskEntity.getEntity()
|
||||
return (int) (mTaskWrapper.getEntity().getCurrentProgress() * 100 / mTaskWrapper.getEntity()
|
||||
.getFileSize());
|
||||
}
|
||||
|
||||
@@ -161,8 +160,8 @@ public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsT
|
||||
* @return {@link IEntity}
|
||||
*/
|
||||
public int getState() {
|
||||
return mTaskEntity.getEntity() == null ? IEntity.STATE_OTHER
|
||||
: mTaskEntity.getEntity().getState();
|
||||
return mTaskWrapper.getEntity() == null ? IEntity.STATE_OTHER
|
||||
: mTaskWrapper.getEntity().getState();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,7 +170,7 @@ public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsT
|
||||
* @return 如果实体不存在,则返回null,否则返回扩展字段
|
||||
*/
|
||||
public String getExtendField() {
|
||||
return mTaskEntity.getEntity() == null ? null : mTaskEntity.getEntity().getStr();
|
||||
return mTaskWrapper.getEntity() == null ? null : mTaskWrapper.getEntity().getStr();
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
@@ -257,7 +256,7 @@ public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsT
|
||||
* 才能生效
|
||||
*/
|
||||
@Override public long getSpeed() {
|
||||
return mTaskEntity.getEntity().getSpeed();
|
||||
return mTaskWrapper.getEntity().getSpeed();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,11 +277,11 @@ public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsT
|
||||
* 才能生效
|
||||
*/
|
||||
@Override public String getConvertSpeed() {
|
||||
return mTaskEntity.getEntity().getConvertSpeed();
|
||||
return mTaskWrapper.getEntity().getConvertSpeed();
|
||||
}
|
||||
|
||||
@Override public TASK_ENTITY getTaskEntity() {
|
||||
return mTaskEntity;
|
||||
@Override public TASK_WRAPPER getTaskWrapper() {
|
||||
return mTaskWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,286 +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.inf;
|
||||
|
||||
import com.arialyy.aria.core.FtpUrlEntity;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.orm.annotation.Ignore;
|
||||
import java.net.CookieManager;
|
||||
import java.net.HttpCookie;
|
||||
import java.net.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/2/23.
|
||||
* 所有任务实体的父类
|
||||
*/
|
||||
public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
|
||||
/**
|
||||
* HTTP单任务载
|
||||
*/
|
||||
public static final int D_HTTP = 0x11;
|
||||
/**
|
||||
* HTTP任务组下载
|
||||
*/
|
||||
public static final int DG_HTTP = 0x12;
|
||||
|
||||
/**
|
||||
* FTP单文件下载
|
||||
*/
|
||||
public static final int D_FTP = 0x13;
|
||||
/**
|
||||
* FTP文件夹下载,为避免登录过多,子任务由单线程进行处理
|
||||
*/
|
||||
public static final int D_FTP_DIR = 0x14;
|
||||
|
||||
/**
|
||||
* HTTP单文件上传
|
||||
*/
|
||||
public static final int U_HTTP = 0xA1;
|
||||
/**
|
||||
* FTP单文件上传
|
||||
*/
|
||||
public static final int U_FTP = 0xA2;
|
||||
|
||||
@Ignore private CookieManager cookieManager;
|
||||
|
||||
/**
|
||||
* 账号和密码
|
||||
*/
|
||||
@Ignore private FtpUrlEntity urlEntity;
|
||||
|
||||
/**
|
||||
* 刷新信息 {@code true} 重新刷新下载信息
|
||||
*/
|
||||
@Ignore private boolean refreshInfo = false;
|
||||
|
||||
/**
|
||||
* 是否是新任务,{@code true} 新任务
|
||||
*/
|
||||
@Ignore private boolean isNewTask = false;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
@Ignore private Map<String, String> params;
|
||||
|
||||
/**
|
||||
* 任务状态,和Entity的state同步
|
||||
*/
|
||||
private int state = IEntity.STATE_WAIT;
|
||||
|
||||
/**
|
||||
* 请求类型
|
||||
* {@link AbsTaskEntity#D_HTTP}、{@link AbsTaskEntity#D_FTP}、{@link AbsTaskEntity#D_FTP_DIR}。。。
|
||||
*/
|
||||
private int requestType = D_HTTP;
|
||||
|
||||
/**
|
||||
* http 请求头
|
||||
*/
|
||||
private Map<String, String> headers = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 字符编码,默认为"utf-8"
|
||||
*/
|
||||
private String charSet = "utf-8";
|
||||
|
||||
/**
|
||||
* 网络请求类型
|
||||
*/
|
||||
private RequestEnum requestEnum = RequestEnum.GET;
|
||||
|
||||
/**
|
||||
* 是否使用服务器通过content-disposition传递的文件名,内容格式{@code attachment; filename="filename.jpg"}
|
||||
* {@code true} 使用
|
||||
*/
|
||||
private boolean useServerFileName = false;
|
||||
|
||||
/**
|
||||
* 重定向链接
|
||||
*/
|
||||
private String redirectUrl = "";
|
||||
|
||||
/**
|
||||
* 删除任务时,是否删除已下载完成的文件
|
||||
* 未完成的任务,不管true还是false,都会删除文件
|
||||
* {@code true} 删除任务数据库记录,并且删除已经下载完成的文件
|
||||
* {@code false} 如果任务已经完成,只删除任务数据库记录
|
||||
*/
|
||||
@Ignore private boolean removeFile = false;
|
||||
|
||||
/**
|
||||
* 是否支持断点, {@code true} 为支持断点
|
||||
*/
|
||||
private boolean isSupportBP = true;
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
private int code;
|
||||
|
||||
@Ignore private Proxy proxy;
|
||||
|
||||
public abstract ENTITY getEntity();
|
||||
|
||||
public CookieManager getCookieManager() {
|
||||
return cookieManager;
|
||||
}
|
||||
|
||||
public void setCookieManager(CookieManager cookieManager) {
|
||||
this.cookieManager = cookieManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务下载状态
|
||||
*
|
||||
* @return {@link IEntity}
|
||||
*/
|
||||
public int getState() {
|
||||
return getEntity().getState();
|
||||
}
|
||||
|
||||
public Proxy getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
public void setProxy(Proxy proxy) {
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
public abstract String getKey();
|
||||
|
||||
public abstract void setKey(String key);
|
||||
|
||||
@Override public void update() {
|
||||
if (getEntity() != null) {
|
||||
getEntity().update();
|
||||
}
|
||||
super.update();
|
||||
}
|
||||
|
||||
public FtpUrlEntity getUrlEntity() {
|
||||
return urlEntity;
|
||||
}
|
||||
|
||||
public void setUrlEntity(FtpUrlEntity urlEntity) {
|
||||
this.urlEntity = urlEntity;
|
||||
}
|
||||
|
||||
public boolean isRefreshInfo() {
|
||||
return refreshInfo;
|
||||
}
|
||||
|
||||
public void setRefreshInfo(boolean refreshInfo) {
|
||||
this.refreshInfo = refreshInfo;
|
||||
}
|
||||
|
||||
public boolean isNewTask() {
|
||||
return isNewTask;
|
||||
}
|
||||
|
||||
public void setNewTask(boolean newTask) {
|
||||
isNewTask = newTask;
|
||||
}
|
||||
|
||||
public void setState(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public int getRequestType() {
|
||||
return requestType;
|
||||
}
|
||||
|
||||
public void setRequestType(int requestType) {
|
||||
this.requestType = requestType;
|
||||
}
|
||||
|
||||
public Map<String, String> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public void setHeaders(Map<String, String> headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
public String getCharSet() {
|
||||
return charSet;
|
||||
}
|
||||
|
||||
public void setCharSet(String charSet) {
|
||||
this.charSet = charSet;
|
||||
}
|
||||
|
||||
public RequestEnum getRequestEnum() {
|
||||
return requestEnum;
|
||||
}
|
||||
|
||||
public void setRequestEnum(RequestEnum requestEnum) {
|
||||
this.requestEnum = requestEnum;
|
||||
}
|
||||
|
||||
public boolean isUseServerFileName() {
|
||||
return useServerFileName;
|
||||
}
|
||||
|
||||
public void setUseServerFileName(boolean useServerFileName) {
|
||||
this.useServerFileName = useServerFileName;
|
||||
}
|
||||
|
||||
public String getRedirectUrl() {
|
||||
return redirectUrl;
|
||||
}
|
||||
|
||||
public void setRedirectUrl(String redirectUrl) {
|
||||
this.redirectUrl = redirectUrl;
|
||||
}
|
||||
|
||||
public boolean isRemoveFile() {
|
||||
return removeFile;
|
||||
}
|
||||
|
||||
public void setRemoveFile(boolean removeFile) {
|
||||
this.removeFile = removeFile;
|
||||
}
|
||||
|
||||
public boolean isSupportBP() {
|
||||
return isSupportBP;
|
||||
}
|
||||
|
||||
public void setSupportBP(boolean supportBP) {
|
||||
isSupportBP = supportBP;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Map<String, String> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(Map<String, String> params) {
|
||||
this.params = params;
|
||||
}
|
||||
}
|
||||
151
Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java
Normal file
151
Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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.inf;
|
||||
|
||||
import com.arialyy.aria.core.common.ftp.FtpTaskDelegate;
|
||||
import com.arialyy.aria.core.common.http.HttpTaskDelegate;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/2/23. 所有任务实体的父类
|
||||
*/
|
||||
public abstract class AbsTaskWrapper<ENTITY extends AbsEntity>
|
||||
implements ITaskWrapper<ENTITY> {
|
||||
|
||||
private HttpTaskDelegate httpTaskDelegate;
|
||||
private FtpTaskDelegate ftpTaskDelegate;
|
||||
|
||||
/**
|
||||
* 刷新信息 {@code true} 重新刷新下载信息
|
||||
*/
|
||||
private boolean refreshInfo = false;
|
||||
|
||||
/**
|
||||
* 任务状态,和Entity的state同步
|
||||
*/
|
||||
private int state = IEntity.STATE_WAIT;
|
||||
|
||||
/**
|
||||
* 是否是新任务,{@code true} 新任务
|
||||
*/
|
||||
private boolean isNewTask = false;
|
||||
|
||||
/**
|
||||
* 请求类型 {@link AbsTaskWrapper#D_HTTP}、{@link AbsTaskWrapper#D_FTP}、{@link
|
||||
* AbsTaskWrapper#D_FTP_DIR}。。。
|
||||
*/
|
||||
private int requestType = D_HTTP;
|
||||
|
||||
/**
|
||||
* 删除任务时,是否删除已下载完成的文件 未完成的任务,不管true还是false,都会删除文件 {@code true} 删除任务数据库记录,并且删除已经下载完成的文件 {@code
|
||||
* false} 如果任务已经完成,只删除任务数据库记录
|
||||
*/
|
||||
private boolean removeFile = false;
|
||||
|
||||
/**
|
||||
* 是否支持断点, {@code true} 为支持断点
|
||||
*/
|
||||
private boolean isSupportBP = true;
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
private int code;
|
||||
|
||||
public abstract String getKey();
|
||||
|
||||
public abstract void setKey(String key);
|
||||
|
||||
/**
|
||||
* 设置或获取HTTP任务相关参数
|
||||
*/
|
||||
public HttpTaskDelegate asHttp() {
|
||||
if (httpTaskDelegate == null) {
|
||||
httpTaskDelegate = new HttpTaskDelegate();
|
||||
}
|
||||
return httpTaskDelegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置或获取FTP任务相关参数
|
||||
*/
|
||||
public FtpTaskDelegate asFtp() {
|
||||
if (ftpTaskDelegate == null) {
|
||||
ftpTaskDelegate = new FtpTaskDelegate();
|
||||
}
|
||||
return ftpTaskDelegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务下载状态
|
||||
*
|
||||
* @return {@link IEntity}
|
||||
*/
|
||||
public int getState() {
|
||||
return getEntity().getState();
|
||||
}
|
||||
|
||||
public boolean isRefreshInfo() {
|
||||
return refreshInfo;
|
||||
}
|
||||
|
||||
public void setRefreshInfo(boolean refreshInfo) {
|
||||
this.refreshInfo = refreshInfo;
|
||||
}
|
||||
|
||||
public boolean isNewTask() {
|
||||
return isNewTask;
|
||||
}
|
||||
|
||||
public void setNewTask(boolean newTask) {
|
||||
isNewTask = newTask;
|
||||
}
|
||||
|
||||
public void setState(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public int getRequestType() {
|
||||
return requestType;
|
||||
}
|
||||
|
||||
public void setRequestType(int requestType) {
|
||||
this.requestType = requestType;
|
||||
}
|
||||
|
||||
public boolean isRemoveFile() {
|
||||
return removeFile;
|
||||
}
|
||||
|
||||
public void setRemoveFile(boolean removeFile) {
|
||||
this.removeFile = removeFile;
|
||||
}
|
||||
|
||||
public boolean isSupportBP() {
|
||||
return isSupportBP;
|
||||
}
|
||||
|
||||
public void setSupportBP(boolean supportBP) {
|
||||
isSupportBP = supportBP;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package com.arialyy.aria.core.inf;
|
||||
/**
|
||||
* Created by lyy on 2017/2/13.
|
||||
*/
|
||||
public interface ITask<TASK_ENTITY extends AbsTaskEntity> {
|
||||
public interface ITask<TASK_WRAPPER extends AbsTaskWrapper> {
|
||||
|
||||
/**
|
||||
* 普通下载任务
|
||||
@@ -68,7 +68,7 @@ public interface ITask<TASK_ENTITY extends AbsTaskEntity> {
|
||||
/**
|
||||
* 获取信息实体
|
||||
*/
|
||||
TASK_ENTITY getTaskEntity();
|
||||
TASK_WRAPPER getTaskWrapper();
|
||||
|
||||
void start();
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
package com.arialyy.aria.core.inf;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/10/12.
|
||||
* 当任务实体
|
||||
* 任务信息
|
||||
*/
|
||||
public abstract class AbsNormalTaskEntity<ENTITY extends AbsEntity> extends AbsTaskEntity<ENTITY> {
|
||||
public interface ITaskDelegate {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.inf;
|
||||
|
||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||
|
||||
/**
|
||||
* 组合任务实体包裹器,用于加载和任务相关的参数,如:组合任务实体{@link DownloadGroupEntity}、header头部
|
||||
*/
|
||||
public interface ITaskWrapper<ENTITY extends AbsEntity> {
|
||||
|
||||
/**
|
||||
* HTTP单任务载
|
||||
*/
|
||||
int D_HTTP = 0x11;
|
||||
/**
|
||||
* HTTP任务组下载
|
||||
*/
|
||||
int DG_HTTP = 0x12;
|
||||
|
||||
/**
|
||||
* FTP单文件下载
|
||||
*/
|
||||
int D_FTP = 0x13;
|
||||
/**
|
||||
* FTP文件夹下载,为避免登录过多,子任务由单线程进行处理
|
||||
*/
|
||||
int D_FTP_DIR = 0x14;
|
||||
|
||||
/**
|
||||
* HTTP单文件上传
|
||||
*/
|
||||
int U_HTTP = 0xA1;
|
||||
/**
|
||||
* FTP单文件上传
|
||||
*/
|
||||
int U_FTP = 0xA2;
|
||||
|
||||
ENTITY getEntity();
|
||||
}
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.manager;
|
||||
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
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.download.wrapper.DGEWrapper;
|
||||
import com.arialyy.aria.core.download.wrapper.DGTEWrapper;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
@@ -31,7 +31,7 @@ import java.util.List;
|
||||
* Created by Aria.Lao on 2017/11/1.
|
||||
* 任务实体工厂
|
||||
*/
|
||||
class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DownloadGroupTaskEntity> {
|
||||
class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DGTaskWrapper> {
|
||||
private static final String TAG = "DTEFactory";
|
||||
private static volatile DGTEFactory INSTANCE = null;
|
||||
|
||||
@@ -47,39 +47,39 @@ class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DownloadGroupTaskE
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override public DownloadGroupTaskEntity getGTE(String groupName, List<String> urls) {
|
||||
@Override public DGTaskWrapper getGTE(String groupName, List<String> urls) {
|
||||
DownloadGroupEntity entity = createDGroupEntity(groupName, urls);
|
||||
List<DGTEWrapper> wrapper =
|
||||
DbEntity.findRelationData(DGTEWrapper.class, "DownloadGroupTaskEntity.key=?",
|
||||
DbEntity.findRelationData(DGTEWrapper.class, "DGTaskWrapper.key=?",
|
||||
entity.getGroupName());
|
||||
DownloadGroupTaskEntity gte;
|
||||
DGTaskWrapper gte;
|
||||
|
||||
if (wrapper != null && !wrapper.isEmpty()) {
|
||||
gte = wrapper.get(0).taskEntity;
|
||||
if (gte == null) {
|
||||
// 创建新的任务组任务实体
|
||||
gte = new DownloadGroupTaskEntity();
|
||||
gte = new DGTaskWrapper();
|
||||
}
|
||||
} else {
|
||||
gte = new DownloadGroupTaskEntity();
|
||||
gte = new DGTaskWrapper();
|
||||
}
|
||||
gte.setSubTaskEntities(createDGSubTaskEntity(entity));
|
||||
gte.setSubTaskWrapper(createDGSubTaskEntity(entity));
|
||||
gte.setKey(entity.getGroupName());
|
||||
gte.setEntity(entity);
|
||||
|
||||
return gte;
|
||||
}
|
||||
|
||||
@Override public DownloadGroupTaskEntity getFTE(String ftpUrl) {
|
||||
@Override public DGTaskWrapper getFTE(String ftpUrl) {
|
||||
List<DGTEWrapper> wrapper =
|
||||
DbEntity.findRelationData(DGTEWrapper.class, "DownloadGroupTaskEntity.key=?",
|
||||
DbEntity.findRelationData(DGTEWrapper.class, "DGTaskWrapper.key=?",
|
||||
ftpUrl);
|
||||
DownloadGroupTaskEntity fte;
|
||||
DGTaskWrapper fte;
|
||||
|
||||
if (wrapper != null && !wrapper.isEmpty()) {
|
||||
fte = wrapper.get(0).taskEntity;
|
||||
if (fte == null) {
|
||||
fte = new DownloadGroupTaskEntity();
|
||||
fte = new DGTaskWrapper();
|
||||
DownloadGroupEntity dge = new DownloadGroupEntity();
|
||||
dge.setGroupName(ftpUrl);
|
||||
fte.setEntity(dge);
|
||||
@@ -89,19 +89,19 @@ class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DownloadGroupTaskE
|
||||
fte.setEntity(dge);
|
||||
}
|
||||
} else {
|
||||
fte = new DownloadGroupTaskEntity();
|
||||
fte = new DGTaskWrapper();
|
||||
DownloadGroupEntity dge = new DownloadGroupEntity();
|
||||
dge.setGroupName(ftpUrl);
|
||||
fte.setEntity(dge);
|
||||
}
|
||||
fte.setKey(ftpUrl);
|
||||
fte.setUrlEntity(CommonUtil.getFtpUrlInfo(ftpUrl));
|
||||
fte.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(ftpUrl));
|
||||
|
||||
if (fte.getEntity().getSubEntities() == null) {
|
||||
fte.getEntity().setSubEntities(new ArrayList<DownloadEntity>());
|
||||
}
|
||||
if (fte.getSubTaskEntities() == null) {
|
||||
fte.setSubTaskEntities(new ArrayList<DownloadTaskEntity>());
|
||||
if (fte.getSubTaskWrapper() == null) {
|
||||
fte.setSubTaskWrapper(new ArrayList<DTaskWrapper>());
|
||||
}
|
||||
return fte;
|
||||
}
|
||||
@@ -109,10 +109,10 @@ class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DownloadGroupTaskE
|
||||
/**
|
||||
* 创建任务组子任务的任务实体
|
||||
*/
|
||||
private List<DownloadTaskEntity> createDGSubTaskEntity(DownloadGroupEntity dge) {
|
||||
List<DownloadTaskEntity> list = new ArrayList<>();
|
||||
private List<DTaskWrapper> createDGSubTaskEntity(DownloadGroupEntity dge) {
|
||||
List<DTaskWrapper> list = new ArrayList<>();
|
||||
for (DownloadEntity entity : dge.getSubEntities()) {
|
||||
DownloadTaskEntity taskEntity = new DownloadTaskEntity();
|
||||
DTaskWrapper taskEntity = new DTaskWrapper();
|
||||
taskEntity.setEntity(entity);
|
||||
taskEntity.setKey(entity.getDownloadPath());
|
||||
taskEntity.setGroupName(dge.getKey());
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.arialyy.aria.core.manager;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.AbsFileer;
|
||||
import com.arialyy.aria.core.common.TaskRecord;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.download.wrapper.DTEWrapper;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
@@ -31,7 +31,7 @@ import java.util.UUID;
|
||||
* Created by Aria.Lao on 2017/11/1.
|
||||
* 任务实体工厂
|
||||
*/
|
||||
class DTEFactory implements INormalTEFactory<DownloadEntity, DownloadTaskEntity> {
|
||||
class DTEFactory implements INormalTEFactory<DownloadEntity, DTaskWrapper> {
|
||||
private static final String TAG = "DTEFactory";
|
||||
private static volatile DTEFactory INSTANCE = null;
|
||||
|
||||
@@ -50,21 +50,21 @@ class DTEFactory implements INormalTEFactory<DownloadEntity, DownloadTaskEntity>
|
||||
/**
|
||||
* 通过下载实体创建任务实体
|
||||
*/
|
||||
private DownloadTaskEntity create(DownloadEntity entity) {
|
||||
private DTaskWrapper create(DownloadEntity entity) {
|
||||
List<DTEWrapper> wrapper = DbEntity.findRelationData(DTEWrapper.class,
|
||||
"DownloadTaskEntity.key=? and DownloadTaskEntity.isGroupTask='false' and DownloadTaskEntity.url=?",
|
||||
"DTaskWrapper.key=? and DTaskWrapper.isGroupTask='false' and DTaskWrapper.url=?",
|
||||
entity.getDownloadPath(), entity.getUrl());
|
||||
DownloadTaskEntity taskEntity;
|
||||
DTaskWrapper taskEntity;
|
||||
if (wrapper != null && !wrapper.isEmpty()) {
|
||||
taskEntity = wrapper.get(0).taskEntity;
|
||||
if (taskEntity == null) {
|
||||
taskEntity = new DownloadTaskEntity();
|
||||
taskEntity = new DTaskWrapper();
|
||||
} else if (taskEntity.getEntity() == null || TextUtils.isEmpty(
|
||||
taskEntity.getEntity().getUrl())) {
|
||||
taskEntity.setEntity(entity);
|
||||
}
|
||||
} else {
|
||||
taskEntity = new DownloadTaskEntity();
|
||||
taskEntity = new DTaskWrapper();
|
||||
}
|
||||
taskEntity.setKey(entity.getDownloadPath());
|
||||
taskEntity.setUrl(entity.getUrl());
|
||||
@@ -75,7 +75,7 @@ class DTEFactory implements INormalTEFactory<DownloadEntity, DownloadTaskEntity>
|
||||
/**
|
||||
* 通过下载地址创建任务实体
|
||||
*/
|
||||
@Override public DownloadTaskEntity create(String downloadUrl) {
|
||||
@Override public DTaskWrapper create(String downloadUrl) {
|
||||
return create(getEntity(downloadUrl));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
package com.arialyy.aria.core.manager;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 任务组通过组创建任务
|
||||
* Created by Aria.Lao on 2017/11/1.
|
||||
*/
|
||||
interface IGTEFactory<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>> {
|
||||
interface IGTEFactory<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskWrapper<ENTITY>> {
|
||||
|
||||
/**
|
||||
* 获取任务组的任务实体,
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
package com.arialyy.aria.core.manager;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/11/1.
|
||||
*/
|
||||
interface INormalTEFactory<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>> {
|
||||
interface INormalTEFactory<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskWrapper<ENTITY>> {
|
||||
|
||||
/**
|
||||
* 通过key创建任务,只适应于单任务
|
||||
|
||||
@@ -18,7 +18,7 @@ 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.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.List;
|
||||
@@ -29,10 +29,10 @@ import java.util.List;
|
||||
*/
|
||||
public class SubTaskManager {
|
||||
private String TAG = "SubTaskManager";
|
||||
private AbsGroupTaskEntity mEntity;
|
||||
private DGTaskWrapper mEntity;
|
||||
private String mTargetName;
|
||||
|
||||
public SubTaskManager(String targetName, AbsGroupTaskEntity entity) {
|
||||
public SubTaskManager(String targetName, DGTaskWrapper entity) {
|
||||
mTargetName = targetName;
|
||||
mEntity = entity;
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
package com.arialyy.aria.core.manager;
|
||||
|
||||
import android.support.v4.util.LruCache;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.List;
|
||||
@@ -33,7 +33,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
public class TEManager {
|
||||
private static final String TAG = "TaskManager";
|
||||
private static volatile TEManager INSTANCE = null;
|
||||
private LruCache<String, AbsTaskEntity> cache = new LruCache<>(1024);
|
||||
private LruCache<String, AbsTaskWrapper> cache = new LruCache<>(1024);
|
||||
private Lock lock;
|
||||
|
||||
public static TEManager getInstance() {
|
||||
@@ -54,11 +54,11 @@ public class TEManager {
|
||||
*
|
||||
* @return 如果任务实体创建失败,返回null
|
||||
*/
|
||||
private <TE extends AbsTaskEntity> TE createNormalTE(Class<TE> clazz, String key) {
|
||||
private <TE extends AbsTaskWrapper> TE createNormalTE(Class<TE> clazz, String key) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
AbsTaskEntity tEntity = cache.get(convertKey(key));
|
||||
AbsTaskWrapper tEntity = cache.get(convertKey(key));
|
||||
if (tEntity == null || tEntity.getClass() != clazz) {
|
||||
INormalTEFactory factory = chooseNormalFactory(clazz);
|
||||
if (factory == null) {
|
||||
@@ -79,7 +79,7 @@ public class TEManager {
|
||||
*
|
||||
* @return 如果任务实体创建失败,返回null
|
||||
*/
|
||||
public <TE extends AbsTaskEntity> TE createNormalNoCacheTE(Class<TE> clazz, String key) {
|
||||
public <TE extends AbsTaskWrapper> TE createNormalNoCacheTE(Class<TE> clazz, String key) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
@@ -88,7 +88,7 @@ public class TEManager {
|
||||
ALog.e(TAG, "任务实体创建失败");
|
||||
return null;
|
||||
}
|
||||
AbsTaskEntity tEntity = factory.create(key);
|
||||
AbsTaskWrapper tEntity = factory.create(key);
|
||||
return (TE) tEntity;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
@@ -100,12 +100,12 @@ public class TEManager {
|
||||
*
|
||||
* @return 如果任务实体创建失败,返回null
|
||||
*/
|
||||
private <TE extends AbsTaskEntity> TE createGTEntity(Class<TE> clazz, List<String> urls) {
|
||||
private <TE extends AbsTaskWrapper> TE createGTEntity(Class<TE> clazz, List<String> urls) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
String groupName = CommonUtil.getMd5Code(urls);
|
||||
AbsTaskEntity tEntity = cache.get(convertKey(groupName));
|
||||
AbsTaskWrapper tEntity = cache.get(convertKey(groupName));
|
||||
if (tEntity == null || tEntity.getClass() != clazz) {
|
||||
IGTEFactory factory = chooseGroupFactory(clazz);
|
||||
if (factory == null) {
|
||||
@@ -126,11 +126,11 @@ public class TEManager {
|
||||
*
|
||||
* @return 如果任务实体创建失败,返回null
|
||||
*/
|
||||
private <TE extends AbsTaskEntity> TE createFDTE(Class<TE> clazz, String key) {
|
||||
private <TE extends AbsTaskWrapper> TE createFDTE(Class<TE> clazz, String key) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
AbsTaskEntity tEntity = cache.get(convertKey(key));
|
||||
AbsTaskWrapper tEntity = cache.get(convertKey(key));
|
||||
if (tEntity == null || tEntity.getClass() != clazz) {
|
||||
IGTEFactory factory = chooseGroupFactory(clazz);
|
||||
if (factory == null) {
|
||||
@@ -147,16 +147,16 @@ public class TEManager {
|
||||
}
|
||||
|
||||
private IGTEFactory chooseGroupFactory(Class clazz) {
|
||||
if (clazz == DownloadGroupTaskEntity.class) {
|
||||
if (clazz == DGTaskWrapper.class) {
|
||||
return DGTEFactory.getInstance();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private INormalTEFactory chooseNormalFactory(Class clazz) {
|
||||
if (clazz == DownloadTaskEntity.class) {
|
||||
if (clazz == DTaskWrapper.class) {
|
||||
return DTEFactory.getInstance();
|
||||
} else if (clazz == UploadTaskEntity.class) {
|
||||
} else if (clazz == UTaskWrapper.class) {
|
||||
return UTEFactory.getInstance();
|
||||
}
|
||||
return null;
|
||||
@@ -165,13 +165,13 @@ public class TEManager {
|
||||
/**
|
||||
* 从缓存中获取单任务实体,如果任务实体不存在,则创建任务实体
|
||||
*
|
||||
* @return 创建失败,返回null;成功返回{@link DownloadTaskEntity}或者{@link UploadTaskEntity}
|
||||
* @return 创建失败,返回null;成功返回{@link DTaskWrapper}或者{@link UTaskWrapper}
|
||||
*/
|
||||
public <TE extends AbsTaskEntity> TE getTEntity(Class<TE> clazz, String key) {
|
||||
public <TE extends AbsTaskWrapper> TE getTEntity(Class<TE> clazz, String key) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
AbsTaskEntity tEntity = cache.get(convertKey(key));
|
||||
AbsTaskWrapper tEntity = cache.get(convertKey(key));
|
||||
if (tEntity == null) {
|
||||
return createNormalTE(clazz, key);
|
||||
} else {
|
||||
@@ -185,13 +185,13 @@ public class TEManager {
|
||||
/**
|
||||
* 从缓存中获取FTP文件夹任务实体,如果任务实体不存在,则创建任务实体
|
||||
*
|
||||
* @return 创建失败,返回null;成功返回{@link DownloadTaskEntity},
|
||||
* @return 创建失败,返回null;成功返回{@link DTaskWrapper},
|
||||
*/
|
||||
public <TE extends AbsTaskEntity> TE getFDTEntity(Class<TE> clazz, String key) {
|
||||
public <TE extends AbsTaskWrapper> TE getFDTEntity(Class<TE> clazz, String key) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
AbsTaskEntity tEntity = cache.get(convertKey(key));
|
||||
AbsTaskWrapper tEntity = cache.get(convertKey(key));
|
||||
if (tEntity == null) {
|
||||
return createFDTE(clazz, key);
|
||||
} else {
|
||||
@@ -207,9 +207,9 @@ public class TEManager {
|
||||
* 获取{}
|
||||
*
|
||||
* @param urls HTTP任务组的子任务下载地址列表
|
||||
* @return 地址列表为null或创建实体失败,返回null;成功返回{@link DownloadGroupTaskEntity}
|
||||
* @return 地址列表为null或创建实体失败,返回null;成功返回{@link DGTaskWrapper}
|
||||
*/
|
||||
public <TE extends AbsTaskEntity> TE getGTEntity(Class<TE> clazz, List<String> urls) {
|
||||
public <TE extends AbsTaskWrapper> TE getGTEntity(Class<TE> clazz, List<String> urls) {
|
||||
if (urls == null || urls.isEmpty()) {
|
||||
ALog.e(TAG, "获取HTTP任务组实体失败:任务组的子任务下载地址列表为null");
|
||||
return null;
|
||||
@@ -218,7 +218,7 @@ public class TEManager {
|
||||
lock.lock();
|
||||
try {
|
||||
String groupName = CommonUtil.getMd5Code(urls);
|
||||
AbsTaskEntity tEntity = cache.get(convertKey(groupName));
|
||||
AbsTaskWrapper tEntity = cache.get(convertKey(groupName));
|
||||
if (tEntity == null) {
|
||||
return createGTEntity(clazz, urls);
|
||||
} else {
|
||||
@@ -232,7 +232,7 @@ public class TEManager {
|
||||
/**
|
||||
* 更新任务实体
|
||||
*/
|
||||
public void putTEntity(String key, AbsTaskEntity tEntity) {
|
||||
public void putTEntity(String key, AbsTaskWrapper tEntity) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
@@ -247,7 +247,7 @@ public class TEManager {
|
||||
*
|
||||
* @return {@code false} 实体为null,添加失败
|
||||
*/
|
||||
public boolean addTEntity(AbsTaskEntity te) {
|
||||
public boolean addTEntity(AbsTaskWrapper te) {
|
||||
if (te == null) {
|
||||
ALog.e(TAG, "任务实体添加失败");
|
||||
return false;
|
||||
@@ -265,7 +265,7 @@ public class TEManager {
|
||||
* 通过key删除任务实体
|
||||
* 当任务complete或删除记录时将删除缓存
|
||||
*/
|
||||
public AbsTaskEntity removeTEntity(String key) {
|
||||
public AbsTaskWrapper removeTEntity(String key) {
|
||||
final Lock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.arialyy.aria.core.manager;
|
||||
|
||||
import com.arialyy.aria.core.common.AbsThreadTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.util.HashMap;
|
||||
@@ -54,7 +54,7 @@ public class ThreadTaskManager {
|
||||
/**
|
||||
* 启动线程任务
|
||||
*
|
||||
* @param key 任务对应的key{@link AbsTaskEntity#getKey()}
|
||||
* @param key 任务对应的key{@link AbsTaskWrapper#getKey()}
|
||||
* @param threadTask 线程任务{@link AbsThreadTask}
|
||||
*/
|
||||
public synchronized void startThread(String key, AbsThreadTask threadTask) {
|
||||
@@ -74,7 +74,7 @@ public class ThreadTaskManager {
|
||||
/**
|
||||
* 停止任务的所有线程
|
||||
*
|
||||
* @param key 任务对应的key{@link AbsTaskEntity#getKey()}
|
||||
* @param key 任务对应的key{@link AbsTaskWrapper#getKey()}
|
||||
*/
|
||||
public synchronized void stopTaskThread(String key) {
|
||||
if (mExePool.isShutdown()) {
|
||||
@@ -126,7 +126,7 @@ public class ThreadTaskManager {
|
||||
/**
|
||||
* map中的key
|
||||
*
|
||||
* @param key 任务的key{@link AbsTaskEntity#getKey()}
|
||||
* @param key 任务的key{@link AbsTaskWrapper#getKey()}
|
||||
* @return 转换后的map中的key
|
||||
*/
|
||||
private String getKey(String key) {
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
package com.arialyy.aria.core.manager;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
import com.arialyy.aria.core.upload.wrapper.UTEWrapper;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.Regular;
|
||||
@@ -28,7 +28,7 @@ import java.util.regex.Pattern;
|
||||
* Created by Aria.Lao on 2017/11/1.
|
||||
* 任务实体工厂
|
||||
*/
|
||||
class UTEFactory implements INormalTEFactory<UploadEntity, UploadTaskEntity> {
|
||||
class UTEFactory implements INormalTEFactory<UploadEntity, UTaskWrapper> {
|
||||
private static final String TAG = "DTEFactory";
|
||||
private static volatile UTEFactory INSTANCE = null;
|
||||
|
||||
@@ -44,29 +44,29 @@ class UTEFactory implements INormalTEFactory<UploadEntity, UploadTaskEntity> {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private UploadTaskEntity create(UploadEntity entity) {
|
||||
private UTaskWrapper create(UploadEntity entity) {
|
||||
List<UTEWrapper> wrapper =
|
||||
DbEntity.findRelationData(UTEWrapper.class, "UploadTaskEntity.key=?",
|
||||
DbEntity.findRelationData(UTEWrapper.class, "UTaskWrapper.key=?",
|
||||
entity.getFilePath());
|
||||
UploadTaskEntity uTaskEntity = null;
|
||||
UTaskWrapper uTaskEntity = null;
|
||||
if (wrapper != null && !wrapper.isEmpty()) {
|
||||
uTaskEntity = wrapper.get(0).taskEntity;
|
||||
if (uTaskEntity == null) {
|
||||
uTaskEntity = new UploadTaskEntity();
|
||||
uTaskEntity = new UTaskWrapper();
|
||||
uTaskEntity.setEntity(entity);
|
||||
} else if (uTaskEntity.getEntity() == null || TextUtils.isEmpty(
|
||||
uTaskEntity.getEntity().getFilePath())) {
|
||||
uTaskEntity.setEntity(entity);
|
||||
}
|
||||
} else {
|
||||
uTaskEntity = new UploadTaskEntity();
|
||||
uTaskEntity = new UTaskWrapper();
|
||||
uTaskEntity.setEntity(entity);
|
||||
}
|
||||
uTaskEntity.setKey(entity.getFilePath());
|
||||
return uTaskEntity;
|
||||
}
|
||||
|
||||
@Override public UploadTaskEntity create(String key) {
|
||||
@Override public UTaskWrapper create(String key) {
|
||||
return create(getUploadEntity(key));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.arialyy.aria.core.queue;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.inf.TaskSchedulerType;
|
||||
import com.arialyy.aria.core.queue.pool.BaseCachePool;
|
||||
@@ -31,7 +31,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Created by lyy on 2017/2/23. 任务队列
|
||||
*/
|
||||
abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity>
|
||||
abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskWrapper>
|
||||
implements ITaskQueue<TASK, TASK_ENTITY> {
|
||||
final int TYPE_D_QUEUE = 1;
|
||||
final int TYPE_DG_QUEUE = 2;
|
||||
@@ -68,7 +68,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
|
||||
*/
|
||||
@Override public void resumeTask(TASK task) {
|
||||
if (mExecutePool.size() >= getMaxTaskNum()) {
|
||||
task.getTaskEntity().getEntity().setState(IEntity.STATE_WAIT);
|
||||
task.getTaskWrapper().getEntity().setState(IEntity.STATE_WAIT);
|
||||
mCachePool.putTaskToFirst(task);
|
||||
stopTask(mExecutePool.pollTask());
|
||||
} else {
|
||||
@@ -188,7 +188,7 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
|
||||
@Override public void startTask(TASK task) {
|
||||
if (mExecutePool.putTask(task)) {
|
||||
mCachePool.removeTask(task);
|
||||
task.getTaskEntity().getEntity().setFailNum(0);
|
||||
task.getTaskWrapper().getEntity().setFailNum(0);
|
||||
task.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package com.arialyy.aria.core.queue;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTask;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.arialyy.aria.util.ALog;
|
||||
* 任务组下载队列
|
||||
*/
|
||||
public class DownloadGroupTaskQueue
|
||||
extends AbsTaskQueue<DownloadGroupTask, DownloadGroupTaskEntity> {
|
||||
extends AbsTaskQueue<DownloadGroupTask, DGTaskWrapper> {
|
||||
private static volatile DownloadGroupTaskQueue INSTANCE = null;
|
||||
|
||||
private final String TAG = "DownloadGroupTaskQueue";
|
||||
@@ -52,12 +52,12 @@ public class DownloadGroupTaskQueue
|
||||
return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
|
||||
}
|
||||
|
||||
@Override public DownloadGroupTask createTask(DownloadGroupTaskEntity entity) {
|
||||
@Override public DownloadGroupTask createTask(DGTaskWrapper wrapper) {
|
||||
DownloadGroupTask task = null;
|
||||
if (mCachePool.getTask(entity.getEntity().getKey()) == null
|
||||
&& mExecutePool.getTask(entity.getEntity().getKey()) == null) {
|
||||
if (mCachePool.getTask(wrapper.getEntity().getKey()) == null
|
||||
&& mExecutePool.getTask(wrapper.getEntity().getKey()) == null) {
|
||||
task = (DownloadGroupTask) TaskFactory.getInstance()
|
||||
.createTask(entity, DownloadGroupSchedulers.getInstance());
|
||||
.createTask(wrapper, DownloadGroupSchedulers.getInstance());
|
||||
mCachePool.putTask(task);
|
||||
} else {
|
||||
ALog.w(TAG, "任务已存在");
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package com.arialyy.aria.core.queue;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.TaskSchedulerType;
|
||||
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
@@ -30,7 +30,7 @@ import java.util.Set;
|
||||
* Created by lyy on 2016/8/17.
|
||||
* 下载任务队列
|
||||
*/
|
||||
public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DownloadTaskEntity> {
|
||||
public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DTaskWrapper> {
|
||||
private static final String TAG = "DownloadTaskQueue";
|
||||
private static volatile DownloadTaskQueue INSTANCE = null;
|
||||
|
||||
@@ -97,12 +97,12 @@ public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DownloadTaskEn
|
||||
}
|
||||
}
|
||||
|
||||
@Override public DownloadTask createTask(DownloadTaskEntity entity) {
|
||||
@Override public DownloadTask createTask(DTaskWrapper wrapper) {
|
||||
DownloadTask task = null;
|
||||
if (mCachePool.getTask(entity.getEntity().getKey()) == null
|
||||
&& mExecutePool.getTask(entity.getEntity().getKey()) == null) {
|
||||
if (mCachePool.getTask(wrapper.getEntity().getKey()) == null
|
||||
&& mExecutePool.getTask(wrapper.getEntity().getKey()) == null) {
|
||||
task = (DownloadTask) TaskFactory.getInstance()
|
||||
.createTask(entity, DownloadSchedulers.getInstance());
|
||||
.createTask(wrapper, DownloadSchedulers.getInstance());
|
||||
mCachePool.putTask(task);
|
||||
} else {
|
||||
ALog.w(TAG, "任务已存在");
|
||||
|
||||
@@ -18,17 +18,17 @@ package com.arialyy.aria.core.queue;
|
||||
|
||||
import com.arialyy.aria.core.download.DownloadGroupTask;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.upload.UploadTask;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/8/16.
|
||||
* 任务功能接口
|
||||
*/
|
||||
public interface ITaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity> {
|
||||
public interface ITaskQueue<TASK extends AbsTask, TASK_WRAPPER extends AbsTaskWrapper> {
|
||||
|
||||
/**
|
||||
* 通过key判断任务是否正在执行
|
||||
@@ -112,10 +112,10 @@ public interface ITaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
|
||||
/**
|
||||
* 创建一个新的任务,创建时只是将新任务存储到缓存池
|
||||
*
|
||||
* @param entity 任务实体{@link DownloadTaskEntity}、{@link UploadTaskEntity}
|
||||
* @param wrapper 任务实体{@link DTaskWrapper}、{@link UTaskWrapper}
|
||||
* @return {@link DownloadTask}、{@link UploadTask}
|
||||
*/
|
||||
TASK createTask(TASK_ENTITY entity);
|
||||
TASK createTask(TASK_WRAPPER wrapper);
|
||||
|
||||
/**
|
||||
* 通过工作实体缓存池或任务池搜索下载任务,如果缓存池或任务池都没有任务,则创建新任务
|
||||
|
||||
@@ -17,17 +17,17 @@
|
||||
package com.arialyy.aria.core.queue;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTask;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.ITask;
|
||||
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
||||
import com.arialyy.aria.core.scheduler.ISchedulers;
|
||||
import com.arialyy.aria.core.scheduler.UploadSchedulers;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
import com.arialyy.aria.core.upload.UploadTask;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2016/8/18.
|
||||
@@ -55,19 +55,19 @@ class TaskFactory {
|
||||
*
|
||||
* @param entity 下载实体
|
||||
* @param schedulers 对应的任务调度器
|
||||
* @param <TASK_ENTITY> {@link DownloadTaskEntity}、{@link UploadTaskEntity}、{@link
|
||||
* DownloadGroupTaskEntity}
|
||||
* @param <TASK_ENTITY> {@link DTaskWrapper}、{@link UTaskWrapper}、{@link
|
||||
* DGTaskWrapper}
|
||||
* @param <SCHEDULER> {@link DownloadSchedulers}、{@link UploadSchedulers}
|
||||
* @return {@link DownloadTask}、{@link UploadTask}、{@link DownloadGroupTask}
|
||||
*/
|
||||
<TASK_ENTITY extends AbsTaskEntity, SCHEDULER extends ISchedulers> ITask createTask(
|
||||
<TASK_ENTITY extends AbsTaskWrapper, SCHEDULER extends ISchedulers> ITask createTask(
|
||||
TASK_ENTITY entity, SCHEDULER schedulers) {
|
||||
if (entity instanceof DownloadTaskEntity) {
|
||||
return createDownloadTask((DownloadTaskEntity) entity, schedulers);
|
||||
} else if (entity instanceof UploadTaskEntity) {
|
||||
return createUploadTask((UploadTaskEntity) entity, schedulers);
|
||||
} else if (entity instanceof DownloadGroupTaskEntity) {
|
||||
return createDownloadGroupTask((DownloadGroupTaskEntity) entity, schedulers);
|
||||
if (entity instanceof DTaskWrapper) {
|
||||
return createDownloadTask((DTaskWrapper) entity, schedulers);
|
||||
} else if (entity instanceof UTaskWrapper) {
|
||||
return createUploadTask((UTaskWrapper) entity, schedulers);
|
||||
} else if (entity instanceof DGTaskWrapper) {
|
||||
return createDownloadGroupTask((DGTaskWrapper) entity, schedulers);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class TaskFactory {
|
||||
* @param entity 下载任务实体{@link DownloadGroupTask}
|
||||
* @param schedulers {@link ISchedulers}
|
||||
*/
|
||||
private DownloadGroupTask createDownloadGroupTask(DownloadGroupTaskEntity entity,
|
||||
private DownloadGroupTask createDownloadGroupTask(DGTaskWrapper entity,
|
||||
ISchedulers schedulers) {
|
||||
DownloadGroupTask.Builder builder = new DownloadGroupTask.Builder(entity);
|
||||
builder.setOutHandler(schedulers);
|
||||
@@ -86,10 +86,10 @@ class TaskFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entity 上传任务实体{@link UploadTaskEntity}
|
||||
* @param entity 上传任务实体{@link UTaskWrapper}
|
||||
* @param schedulers {@link ISchedulers}
|
||||
*/
|
||||
private UploadTask createUploadTask(UploadTaskEntity entity, ISchedulers schedulers) {
|
||||
private UploadTask createUploadTask(UTaskWrapper entity, ISchedulers schedulers) {
|
||||
UploadTask.Builder builder = new UploadTask.Builder();
|
||||
builder.setUploadTaskEntity(entity);
|
||||
builder.setOutHandler(schedulers);
|
||||
@@ -97,10 +97,10 @@ class TaskFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entity 下载任务实体{@link DownloadTaskEntity}
|
||||
* @param entity 下载任务实体{@link DTaskWrapper}
|
||||
* @param schedulers {@link ISchedulers}
|
||||
*/
|
||||
private DownloadTask createDownloadTask(DownloadTaskEntity entity, ISchedulers schedulers) {
|
||||
private DownloadTask createDownloadTask(DTaskWrapper entity, ISchedulers schedulers) {
|
||||
DownloadTask.Builder builder = new DownloadTask.Builder(entity);
|
||||
builder.setOutHandler(schedulers);
|
||||
return builder.build();
|
||||
|
||||
@@ -18,15 +18,15 @@ package com.arialyy.aria.core.queue;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.scheduler.UploadSchedulers;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
import com.arialyy.aria.core.upload.UploadTask;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/2/27.
|
||||
* 上传任务队列
|
||||
*/
|
||||
public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity> {
|
||||
public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UTaskWrapper> {
|
||||
private static final String TAG = "UploadTaskQueue";
|
||||
private static volatile UploadTaskQueue INSTANCE = null;
|
||||
|
||||
@@ -54,12 +54,12 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity>
|
||||
return AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum();
|
||||
}
|
||||
|
||||
@Override public UploadTask createTask(UploadTaskEntity entity) {
|
||||
@Override public UploadTask createTask(UTaskWrapper wrapper) {
|
||||
UploadTask task = null;
|
||||
if (mCachePool.getTask(entity.getEntity().getKey()) == null
|
||||
&& mExecutePool.getTask(entity.getEntity().getKey()) == null) {
|
||||
if (mCachePool.getTask(wrapper.getEntity().getKey()) == null
|
||||
&& mExecutePool.getTask(wrapper.getEntity().getKey()) == null) {
|
||||
task = (UploadTask) TaskFactory.getInstance()
|
||||
.createTask(entity, UploadSchedulers.getInstance());
|
||||
.createTask(wrapper, UploadSchedulers.getInstance());
|
||||
mCachePool.putTask(task);
|
||||
} else {
|
||||
ALog.w(TAG, "任务已存在");
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsNormalEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTask;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.GroupSendParams;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.inf.ITask;
|
||||
@@ -43,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
/**
|
||||
* Created by lyy on 2017/6/4. 事件调度器,用于处理任务状态的调度
|
||||
*/
|
||||
abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends AbsTask,
|
||||
abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskWrapper, TASK extends AbsTask,
|
||||
QUEUE extends ITaskQueue<TASK, TASK_ENTITY>> implements ISchedulers<TASK> {
|
||||
private final String TAG = "AbsSchedulers";
|
||||
|
||||
@@ -202,7 +202,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
|
||||
TEManager.getInstance().removeTEntity(task.getKey());
|
||||
} else {
|
||||
if (what != RUNNING) {
|
||||
TEManager.getInstance().putTEntity(task.getKey(), task.getTaskEntity());
|
||||
TEManager.getInstance().putTEntity(task.getKey(), task.getTaskWrapper());
|
||||
}
|
||||
}
|
||||
if (what != FAIL) {
|
||||
@@ -278,13 +278,13 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
|
||||
boolean canSend = manager.getDownloadConfig().isUseBroadcast();
|
||||
if (canSend) {
|
||||
AriaManager.APP.sendBroadcast(
|
||||
createData(state, task.getTaskType(), task.getTaskEntity().getEntity()));
|
||||
createData(state, task.getTaskType(), task.getTaskWrapper().getEntity()));
|
||||
}
|
||||
} else if (task.getTaskType() == ITask.UPLOAD) {
|
||||
boolean canSend = manager.getUploadConfig().isUseBroadcast();
|
||||
if (canSend) {
|
||||
AriaManager.APP.sendBroadcast(
|
||||
createData(state, task.getTaskType(), task.getTaskEntity().getEntity()));
|
||||
createData(state, task.getTaskType(), task.getTaskWrapper().getEntity()));
|
||||
}
|
||||
} else {
|
||||
ALog.w(TAG, "发送广播失败,没有对应的任务");
|
||||
@@ -337,7 +337,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
|
||||
|
||||
final int reTryNum = num;
|
||||
if ((!NetUtils.isConnected(AriaManager.APP) && !isNotNetRetry)
|
||||
|| task.getTaskEntity().getEntity().getFailNum() > reTryNum) {
|
||||
|| task.getTaskWrapper().getEntity().getFailNum() > reTryNum) {
|
||||
mQueue.removeTaskFormQueue(task.getKey());
|
||||
startNextTask(task);
|
||||
TEManager.getInstance().removeTEntity(task.getKey());
|
||||
@@ -351,7 +351,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
|
||||
}
|
||||
|
||||
@Override public void onFinish() {
|
||||
AbsEntity entity = task.getTaskEntity().getEntity();
|
||||
AbsEntity entity = task.getTaskWrapper().getEntity();
|
||||
if (entity.getFailNum() <= reTryNum) {
|
||||
ALog.d(TAG, String.format("任务【%s】开始重试", task.getTaskName()));
|
||||
TASK task = mQueue.getTask(entity.getKey());
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
package com.arialyy.aria.core.scheduler;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||
import com.arialyy.aria.core.download.DGTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTask;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||
|
||||
/**
|
||||
@@ -26,7 +25,7 @@ import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
|
||||
* 任务组调度器
|
||||
*/
|
||||
public class DownloadGroupSchedulers extends
|
||||
AbsSchedulers<DownloadGroupTaskEntity, DownloadGroupTask, DownloadGroupTaskQueue> {
|
||||
AbsSchedulers<DGTaskWrapper, DownloadGroupTask, DownloadGroupTaskQueue> {
|
||||
private final String TAG = "DownloadGroupSchedulers";
|
||||
private static volatile DownloadGroupSchedulers INSTANCE = null;
|
||||
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
package com.arialyy.aria.core.scheduler;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
|
||||
/**
|
||||
@@ -27,7 +26,7 @@ import com.arialyy.aria.core.download.DownloadTask;
|
||||
* 任务下载器,提供抽象的方法供具体的实现类操作
|
||||
*/
|
||||
public class DownloadSchedulers
|
||||
extends AbsSchedulers<DownloadTaskEntity, DownloadTask, DownloadTaskQueue> {
|
||||
extends AbsSchedulers<DTaskWrapper, DownloadTask, DownloadTaskQueue> {
|
||||
|
||||
private final String TAG = "DownloadSchedulers";
|
||||
private static volatile DownloadSchedulers INSTANCE = null;
|
||||
|
||||
@@ -17,14 +17,14 @@ package com.arialyy.aria.core.scheduler;
|
||||
|
||||
import com.arialyy.aria.core.AriaManager;
|
||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
import com.arialyy.aria.core.upload.UploadTask;
|
||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/2/27.
|
||||
* 上传任务调度器
|
||||
*/
|
||||
public class UploadSchedulers extends AbsSchedulers<UploadTaskEntity, UploadTask, UploadTaskQueue> {
|
||||
public class UploadSchedulers extends AbsSchedulers<UTaskWrapper, UploadTask, UploadTaskQueue> {
|
||||
private static final String TAG = "UploadSchedulers";
|
||||
private static volatile UploadSchedulers INSTANCE = null;
|
||||
|
||||
|
||||
@@ -17,12 +17,12 @@ package com.arialyy.aria.core.upload;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTarget;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/6/29.
|
||||
*/
|
||||
abstract class AbsUploadTarget<TARGET extends AbsUploadTarget, ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity>
|
||||
abstract class AbsUploadTarget<TARGET extends AbsUploadTarget, ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskWrapper>
|
||||
extends AbsTarget<TARGET, ENTITY, TASK_ENTITY> {
|
||||
|
||||
}
|
||||
|
||||
@@ -27,13 +27,13 @@ import java.io.File;
|
||||
* Created by AriaL on 2018/3/9.
|
||||
*/
|
||||
abstract class BaseNormalTarget<TARGET extends AbsUploadTarget>
|
||||
extends AbsUploadTarget<TARGET, UploadEntity, UploadTaskEntity> {
|
||||
extends AbsUploadTarget<TARGET, UploadEntity, UTaskWrapper> {
|
||||
|
||||
protected String mTempUrl;
|
||||
|
||||
void initTarget(String filePath) {
|
||||
mTaskEntity = TEManager.getInstance().getTEntity(UploadTaskEntity.class, filePath);
|
||||
mEntity = mTaskEntity.getEntity();
|
||||
mTaskWrapper = TEManager.getInstance().getTEntity(UTaskWrapper.class, filePath);
|
||||
mEntity = mTaskWrapper.getEntity();
|
||||
File file = new File(filePath);
|
||||
mEntity.setFileName(file.getName());
|
||||
mEntity.setFileSize(file.length());
|
||||
@@ -78,14 +78,13 @@ abstract class BaseNormalTarget<TARGET extends AbsUploadTarget>
|
||||
boolean b = checkUrl() && checkFilePath();
|
||||
if (b) {
|
||||
mEntity.save();
|
||||
mTaskEntity.save();
|
||||
}
|
||||
if (mTaskEntity.getUrlEntity() != null && mTaskEntity.getUrlEntity().isFtps) {
|
||||
//if (TextUtils.isEmpty(mTaskEntity.getUrlEntity().storePath)) {
|
||||
if (mTaskWrapper.asFtp().getUrlEntity() != null && mTaskWrapper.asFtp().getUrlEntity().isFtps) {
|
||||
//if (TextUtils.isEmpty(mTaskWrapper.getUrlEntity().storePath)) {
|
||||
// ALog.e(TAG, "证书路径为空");
|
||||
// return false;
|
||||
//}
|
||||
if (TextUtils.isEmpty(mTaskEntity.getUrlEntity().keyAlias)) {
|
||||
if (TextUtils.isEmpty(mTaskWrapper.asFtp().getUrlEntity().keyAlias)) {
|
||||
ALog.e(TAG, "证书别名为空");
|
||||
return false;
|
||||
}
|
||||
@@ -117,7 +116,7 @@ abstract class BaseNormalTarget<TARGET extends AbsUploadTarget>
|
||||
ALog.e(TAG, "上传失败,文件【" + filePath + "】不能是文件夹");
|
||||
return false;
|
||||
}
|
||||
mTaskEntity.setKey(mEntity.getFilePath());
|
||||
mTaskWrapper.setKey(mEntity.getFilePath());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,16 +17,14 @@ package com.arialyy.aria.core.upload;
|
||||
|
||||
import android.os.Handler;
|
||||
import com.arialyy.aria.core.common.BaseListener;
|
||||
import com.arialyy.aria.core.common.TaskRecord;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.inf.IUploadListener;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
|
||||
/**
|
||||
* 下载监听类
|
||||
*/
|
||||
class BaseUListener extends BaseListener<UploadEntity, UploadTaskEntity, UploadTask>
|
||||
class BaseUListener extends BaseListener<UploadEntity, UTaskWrapper, UploadTask>
|
||||
implements IUploadListener {
|
||||
|
||||
BaseUListener(UploadTask task, Handler outHandler) {
|
||||
@@ -51,6 +49,5 @@ class BaseUListener extends BaseListener<UploadEntity, UploadTaskEntity, UploadT
|
||||
} else if (location > 0) {
|
||||
mEntity.setCurrentProgress(location);
|
||||
}
|
||||
mTaskEntity.update();
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,8 @@ import com.arialyy.aria.core.FtpUrlEntity;
|
||||
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
|
||||
import com.arialyy.aria.core.common.ftp.FTPSConfig;
|
||||
import com.arialyy.aria.core.common.ftp.FtpDelegate;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.common.ftp.FtpTaskDelegate;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.core.inf.IFtpTarget;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import java.net.Proxy;
|
||||
@@ -44,7 +45,7 @@ public class FtpUploadTarget extends BaseNormalTarget<FtpUploadTarget>
|
||||
|
||||
private void initTask(String filePath) {
|
||||
initTarget(filePath);
|
||||
mTaskEntity.setRequestType(AbsTaskEntity.U_FTP);
|
||||
mTaskWrapper.setRequestType(AbsTaskWrapper.U_FTP);
|
||||
mDelegate = new FtpDelegate<>(this);
|
||||
}
|
||||
|
||||
@@ -54,7 +55,7 @@ public class FtpUploadTarget extends BaseNormalTarget<FtpUploadTarget>
|
||||
public void add() {
|
||||
if (checkEntity()) {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_CREATE,
|
||||
.setCmd(CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_CREATE,
|
||||
checkTaskType()))
|
||||
.exe();
|
||||
}
|
||||
@@ -65,7 +66,8 @@ public class FtpUploadTarget extends BaseNormalTarget<FtpUploadTarget>
|
||||
if (!b) {
|
||||
return false;
|
||||
}
|
||||
FtpUrlEntity temp = mTaskEntity.getUrlEntity();
|
||||
FtpTaskDelegate taskDelegate = mTaskWrapper.asFtp();
|
||||
FtpUrlEntity temp = taskDelegate.getUrlEntity();
|
||||
FtpUrlEntity newEntity = CommonUtil.getFtpUrlInfo(mTempUrl);
|
||||
if (temp != null) { //处理FTPS的信息
|
||||
newEntity.isFtps = temp.isFtps;
|
||||
@@ -74,11 +76,11 @@ public class FtpUploadTarget extends BaseNormalTarget<FtpUploadTarget>
|
||||
newEntity.protocol = temp.protocol;
|
||||
newEntity.storePath = temp.storePath;
|
||||
}
|
||||
mTaskEntity.setUrlEntity(newEntity);
|
||||
mTaskEntity.getUrlEntity().account = mAccount;
|
||||
mTaskEntity.getUrlEntity().user = mUser;
|
||||
mTaskEntity.getUrlEntity().password = mPw;
|
||||
mTaskEntity.getUrlEntity().needLogin = needLogin;
|
||||
taskDelegate.setUrlEntity(newEntity);
|
||||
taskDelegate.getUrlEntity().account = mAccount;
|
||||
taskDelegate.getUrlEntity().user = mUser;
|
||||
taskDelegate.getUrlEntity().password = mPw;
|
||||
taskDelegate.getUrlEntity().needLogin = needLogin;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -89,10 +91,10 @@ public class FtpUploadTarget extends BaseNormalTarget<FtpUploadTarget>
|
||||
*/
|
||||
@CheckResult
|
||||
public FTPSConfig<FtpUploadTarget> asFtps() {
|
||||
if (mTaskEntity.getUrlEntity() == null) {
|
||||
if (mTaskWrapper.asFtp().getUrlEntity() == null) {
|
||||
FtpUrlEntity urlEntity = new FtpUrlEntity();
|
||||
urlEntity.isFtps = true;
|
||||
mTaskEntity.setUrlEntity(urlEntity);
|
||||
mTaskWrapper.asFtp().setUrlEntity(urlEntity);
|
||||
}
|
||||
return new FTPSConfig<>(this);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.upload;
|
||||
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/2/9. 上传任务实体
|
||||
*/
|
||||
public class UTaskWrapper extends AbsTaskWrapper<UploadEntity> {
|
||||
|
||||
private UploadEntity entity;
|
||||
|
||||
private String filePath;
|
||||
|
||||
private String key;
|
||||
|
||||
public UTaskWrapper() {
|
||||
}
|
||||
|
||||
@Override public UploadEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setEntity(UploadEntity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package com.arialyy.aria.core.upload;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import com.arialyy.aria.core.inf.AbsNormalEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskEntity;
|
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||
import com.arialyy.aria.orm.annotation.Primary;
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ public class UploadEntity extends AbsNormalEntity implements Parcelable {
|
||||
}
|
||||
|
||||
@Override public int getTaskType() {
|
||||
return getUrl().startsWith("ftp") ? AbsTaskEntity.D_FTP : AbsTaskEntity.D_HTTP;
|
||||
return getUrl().startsWith("ftp") ? AbsTaskWrapper.D_FTP : AbsTaskWrapper.D_HTTP;
|
||||
}
|
||||
|
||||
public UploadEntity() {
|
||||
|
||||
@@ -89,7 +89,7 @@ public class UploadReceiver extends AbsReceiver {
|
||||
* @return {@code true}存在,{@code false} 不存在
|
||||
*/
|
||||
public boolean taskExists(String filePath) {
|
||||
return DbEntity.checkDataExist(UploadTaskEntity.class, "key=?", filePath);
|
||||
return DbEntity.checkDataExist(UTaskWrapper.class, "key=?", filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +123,7 @@ public class UploadReceiver extends AbsReceiver {
|
||||
public void stopAllTask() {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(NormalCmdFactory.getInstance()
|
||||
.createCmd(new UploadTaskEntity(), NormalCmdFactory.TASK_STOP_ALL,
|
||||
.createCmd(new UTaskWrapper(), NormalCmdFactory.TASK_STOP_ALL,
|
||||
ICmd.TASK_TYPE_UPLOAD))
|
||||
.exe();
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public class UploadReceiver extends AbsReceiver {
|
||||
public void removeAllTask(boolean removeFile) {
|
||||
final AriaManager am = AriaManager.getInstance(AriaManager.APP);
|
||||
CancelAllCmd cancelCmd =
|
||||
(CancelAllCmd) CommonUtil.createNormalCmd(new UploadTaskEntity(),
|
||||
(CancelAllCmd) CommonUtil.createNormalCmd(new UTaskWrapper(),
|
||||
NormalCmdFactory.TASK_CANCEL_ALL, ICmd.TASK_TYPE_UPLOAD);
|
||||
cancelCmd.removeFile = removeFile;
|
||||
am.setCmd(cancelCmd).exe();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user