use of lee.study.down.model.TaskInfo in project proxyee-down by monkeyWie.
the class HttpDownProgressEventTask method run.
@Override
public void run() {
while (true) {
try {
for (TaskInfo taskInfo : ContentManager.DOWN.getStartTasks()) {
if (taskInfo.getStatus() != HttpDownStatus.DONE && taskInfo.getStatus() != HttpDownStatus.FAIL && taskInfo.getStatus() != HttpDownStatus.PAUSE) {
taskInfo.setLastTime(System.currentTimeMillis());
for (ChunkInfo chunkInfo : taskInfo.getChunkInfoList()) {
if (chunkInfo.getStatus() != HttpDownStatus.DONE && chunkInfo.getStatus() != HttpDownStatus.PAUSE) {
chunkInfo.setLastTime(System.currentTimeMillis());
}
}
// 保存任务进度记录
synchronized (taskInfo) {
if (taskInfo.getStatus() != HttpDownStatus.DONE) {
ContentManager.DOWN.saveTask(taskInfo.getId());
}
}
}
}
ContentManager.WS.sendMsg(ContentManager.DOWN.buildDowningWsForm());
if (HttpDownController.updateBootstrap != null && HttpDownController.updateBootstrap.getHttpDownInfo().getTaskInfo().getStatus() != HttpDownStatus.DONE) {
ContentManager.WS.sendMsg(new WsForm(WsDataType.UPDATE_PROGRESS, HttpDownController.updateBootstrap.getHttpDownInfo().getTaskInfo()));
}
TimeUnit.MILLISECONDS.sleep(1000);
} catch (Exception e) {
LOGGER.error("eventTask:", e);
}
}
}
use of lee.study.down.model.TaskInfo 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.model.TaskInfo in project proxyee-down by monkeyWie.
the class AbstractHttpDownBootstrap method pauseDown.
/**
* 暂停下载
*/
public void pauseDown() throws Exception {
TaskInfo taskInfo = httpDownInfo.getTaskInfo();
synchronized (taskInfo) {
taskInfo.setStatus(HttpDownStatus.PAUSE);
for (ChunkInfo chunkInfo : taskInfo.getChunkInfoList()) {
synchronized (chunkInfo) {
if (chunkInfo.getStatus() != HttpDownStatus.DONE) {
chunkInfo.setStatus(HttpDownStatus.PAUSE);
}
}
}
close();
}
if (callback != null) {
callback.onPause(httpDownInfo);
}
}
use of lee.study.down.model.TaskInfo in project proxyee-down by monkeyWie.
the class AbstractHttpDownBootstrap method continueDown.
/**
* 继续下载
*/
public void continueDown() throws Exception {
TaskInfo taskInfo = httpDownInfo.getTaskInfo();
synchronized (taskInfo) {
if (!FileUtil.exists(taskInfo.buildTaskFilePath())) {
close();
startDown();
} else {
taskInfo.setStatus(HttpDownStatus.RUNNING);
taskInfo.getChunkInfoList().forEach((chunk) -> chunk.setErrorCount(0));
long curTime = System.currentTimeMillis();
taskInfo.setPauseTime(taskInfo.getPauseTime() + (curTime - taskInfo.getLastTime()));
taskInfo.setLastTime(curTime);
afterStart();
for (ChunkInfo chunkInfo : taskInfo.getChunkInfoList()) {
synchronized (chunkInfo) {
if (chunkInfo.getStatus() == HttpDownStatus.PAUSE || chunkInfo.getStatus() == HttpDownStatus.CONNECTING_FAIL) {
chunkInfo.setPauseTime(taskInfo.getPauseTime());
chunkInfo.setLastTime(curTime);
retryChunkDown(chunkInfo, HttpDownStatus.CONNECTING_NORMAL);
}
}
}
}
}
if (callback != null) {
callback.onContinue(httpDownInfo);
}
}
use of lee.study.down.model.TaskInfo in project proxyee-down by monkeyWie.
the class TimeoutCheckTask method run.
@Override
public void run() {
while (true) {
try {
for (AbstractHttpDownBootstrap bootstrap : bootstrapContent.values()) {
TaskInfo taskInfo = bootstrap.getHttpDownInfo().getTaskInfo();
if (taskInfo.getChunkInfoList() != null) {
for (ChunkInfo chunkInfo : taskInfo.getChunkInfoList()) {
// 30秒没有反应则重新建立连接下载
if (taskInfo.getStatus() == HttpDownStatus.RUNNING && chunkInfo.getStatus() != HttpDownStatus.DONE && chunkInfo.getStatus() != HttpDownStatus.WAIT && chunkInfo.getStatus() != HttpDownStatus.PAUSE) {
long nowTime = System.currentTimeMillis();
if (nowTime - chunkInfo.getLastDownTime() > seconds * 1000) {
LOGGER.debug(seconds + "秒内无响应重试:" + chunkInfo);
if (chunkInfo.getStatus() == HttpDownStatus.ERROR_WAIT_CONNECT) {
chunkInfo.setErrorCount(chunkInfo.getErrorCount() + 1);
}
// 重试下载
bootstrap.retryChunkDown(chunkInfo);
}
}
}
}
}
TimeUnit.MILLISECONDS.sleep(1000);
} catch (Exception e) {
LOGGER.error("checkTask:" + e);
}
}
}
Aggregations