Search in sources :

Example 6 with ChunkInfo

use of lee.study.down.model.ChunkInfo 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

ChunkInfo (lee.study.down.model.ChunkInfo)6 TaskInfo (lee.study.down.model.TaskInfo)6 File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 BootstrapException (lee.study.down.exception.BootstrapException)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)1 HttpContent (io.netty.handler.codec.http.HttpContent)1 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)1 SslContext (io.netty.handler.ssl.SslContext)1 NoopAddressResolverGroup (io.netty.resolver.NoopAddressResolverGroup)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1