Search in sources :

Example 11 with TaskInfo

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);
        }
    }
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) ChunkInfo(lee.study.down.model.ChunkInfo) WsForm(lee.study.down.mvc.form.WsForm)

Example 12 with TaskInfo

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;
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) AbstractHttpDownBootstrap(lee.study.down.boot.AbstractHttpDownBootstrap) HttpRequestInfo(lee.study.down.model.HttpRequestInfo) HttpDownInfo(lee.study.down.model.HttpDownInfo)

Example 13 with TaskInfo

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);
    }
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) ChunkInfo(lee.study.down.model.ChunkInfo)

Example 14 with TaskInfo

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);
    }
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) ChunkInfo(lee.study.down.model.ChunkInfo)

Example 15 with TaskInfo

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);
        }
    }
}
Also used : TaskInfo(lee.study.down.model.TaskInfo) ChunkInfo(lee.study.down.model.ChunkInfo)

Aggregations

TaskInfo (lee.study.down.model.TaskInfo)21 HttpDownInfo (lee.study.down.model.HttpDownInfo)6 ResultInfo (lee.study.down.model.ResultInfo)6 AbstractHttpDownBootstrap (lee.study.down.boot.AbstractHttpDownBootstrap)5 ChunkInfo (lee.study.down.model.ChunkInfo)5 HttpRequestInfo (lee.study.down.model.HttpRequestInfo)5 IOException (java.io.IOException)4 BootstrapException (lee.study.down.exception.BootstrapException)4 WsForm (lee.study.down.mvc.form.WsForm)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 HttpResponse (io.netty.handler.codec.http.HttpResponse)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Channel (io.netty.channel.Channel)2 HttpContent (io.netty.handler.codec.http.HttpContent)2 MalformedURLException (java.net.MalformedURLException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 TimeoutException (java.util.concurrent.TimeoutException)2 HttpDownCallback (lee.study.down.dispatch.HttpDownCallback)2