use of lee.study.down.boot.AbstractHttpDownBootstrap in project proxyee-down by monkeyWie.
the class DownContent method init.
/**
* 从配置文件中加载信息
*/
public void init() {
downContent = new ConcurrentHashMap<>();
if (FileUtil.exists(HttpDownConstant.TASK_RECORD_PATH)) {
try {
List<HttpDownInfo> records = (List<HttpDownInfo>) ByteUtil.deserialize(HttpDownConstant.TASK_RECORD_PATH);
for (HttpDownInfo httpDownInfo : records) {
AbstractHttpDownBootstrap bootstrap = HttpDownBootstrapFactory.create(httpDownInfo, ContentManager.CONFIG.get().getRetryCount(), HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup, HttpDownConstant.httpDownCallback);
TaskInfo taskInfo = httpDownInfo.getTaskInfo();
if (taskInfo.getStatus() == HttpDownStatus.WAIT) {
continue;
}
// 下载未完成
if (taskInfo.getStatus() != HttpDownStatus.DONE) {
String taskDetailPath = taskInfo.buildTaskRecordFilePath();
String taskDetailBakPath = taskInfo.buildTaskRecordBakFilePath();
// 存在下载进度信息则更新,否则重新下载
if (FileUtil.existsAny(taskDetailPath, taskDetailBakPath)) {
try {
taskInfo = (TaskInfo) ByteUtil.deserialize(taskDetailPath, taskDetailBakPath);
httpDownInfo.setTaskInfo(taskInfo);
} catch (IOException | ClassNotFoundException e) {
taskInfo.reset();
}
} else {
taskInfo.reset();
}
if (taskInfo.getStatus() != HttpDownStatus.FAIL) {
// 设置为暂停状态
taskInfo.setStatus(HttpDownStatus.PAUSE);
taskInfo.getChunkInfoList().forEach((chunk) -> {
if (chunk.getStatus() != HttpDownStatus.DONE) {
chunk.setStatus(HttpDownStatus.PAUSE);
}
});
}
}
putBoot(bootstrap);
}
} catch (Exception e) {
LOGGER.warn("加载配置文件失败:", e);
}
}
}
use of lee.study.down.boot.AbstractHttpDownBootstrap in project proxyee-down by monkeyWie.
the class HttpDownController method pauseTask.
@RequestMapping("/pauseTask")
public ResultInfo pauseTask(@RequestParam String id) throws Exception {
ResultInfo resultInfo = new ResultInfo();
AbstractHttpDownBootstrap bootstrap = ContentManager.DOWN.getBoot(id);
if (bootstrap == null) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("任务不存在");
} else {
bootstrap.pauseDown();
}
return resultInfo;
}
use of lee.study.down.boot.AbstractHttpDownBootstrap in project proxyee-down by monkeyWie.
the class GithubUpdateService method update.
@Override
public AbstractHttpDownBootstrap update(UpdateInfo updateInfo, HttpDownCallback callback) throws Exception {
HttpRequestInfo requestInfo = HttpDownUtil.buildGetRequest(updateInfo.getUrl());
TaskInfo taskInfo = HttpDownUtil.getTaskInfo(requestInfo, null, null, HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup).setConnections(64).setFileName("proxyee-down-jar.zip").setFilePath(HttpDownConstant.HOME_PATH.substring(0, HttpDownConstant.HOME_PATH.length() - 1));
HttpDownInfo httpDownInfo = new HttpDownInfo(taskInfo, requestInfo, null);
AbstractHttpDownBootstrap bootstrap = HttpDownBootstrapFactory.create(httpDownInfo, 5, HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup, callback);
FileUtil.deleteIfExists(bootstrap.getHttpDownInfo().getTaskInfo().buildTaskFilePath());
bootstrap.startDown();
return bootstrap;
}
use of lee.study.down.boot.AbstractHttpDownBootstrap in project proxyee-down by monkeyWie.
the class DownContent method putBoot.
public void putBoot(HttpDownInfo httpDownInfo) {
AbstractHttpDownBootstrap bootstrap = HttpDownBootstrapFactory.create(httpDownInfo, ContentManager.CONFIG.get().getRetryCount(), HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup, HttpDownConstant.httpDownCallback);
TaskInfo taskInfo = bootstrap.getHttpDownInfo().getTaskInfo();
if (taskInfo.isSupportRange()) {
taskInfo.setConnections(ContentManager.CONFIG.get().getConnections());
}
taskInfo.setFilePath(ContentManager.CONFIG.get().getLastPath());
putBoot(bootstrap);
}
use of lee.study.down.boot.AbstractHttpDownBootstrap in project proxyee-down by monkeyWie.
the class HttpDownController method continueTask.
@RequestMapping("/continueTask")
public ResultInfo continueTask(@RequestParam String id) throws Exception {
ResultInfo resultInfo = new ResultInfo();
AbstractHttpDownBootstrap bootstrap = ContentManager.DOWN.getBoot(id);
if (bootstrap == null) {
resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("任务不存在");
} else {
bootstrap.continueDown();
}
return resultInfo;
}
Aggregations