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);
}
}
}
Aggregations