修改flop数组为单个对象 ,去除多余的 runner

This commit is contained in:
zhouxiunai
2019-01-08 10:06:02 +08:00
parent 02300928d3
commit cf31345289
4 changed files with 4 additions and 131 deletions
@@ -1,110 +0,0 @@
package com.gzzn.omms.msgexchangeapi.runner;
import java.util.Arrays;
import java.util.Date;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import com.gzzn.omms.msgexchangeapi.entity.Cminmsg;
import com.gzzn.omms.msgexchangeapi.redis.RedisKeyConstant;
import com.gzzn.omms.msgexchangeapi.redis.RedisService;
import com.gzzn.omms.msgexchangeapi.service.ICminmsgService;
import com.gzzn.omms.msgexchangeapi.service.flightInfo.IFlightInfoService;
import com.gzzn.omms.msgexchangeapi.utils.SpringUtil;
/**
* 等待航班日计划返回线程
* @author zhouxiunai
*
*/
public class SchdWaitRunner implements Runnable {
private static Logger logger = LoggerFactory.getLogger(SchdWaitRunner.class);
private RedisService redisService;
private ICminmsgService cminmsgService;
private IFlightInfoService flightInfoService;
private Long intervalSeconds;
public SchdWaitRunner()
{
Environment env = (Environment)SpringUtil.getBean("environment");
intervalSeconds = Long.valueOf(env.getProperty("msgExchange.intervalSeconds"));
flightInfoService = (IFlightInfoService) SpringUtil.getBean("flightInfoService");
redisService = (RedisService) SpringUtil.getBean("redisService");
cminmsgService = (ICminmsgService) SpringUtil.getBean("cminmsgService");
}
@Override
public void run() {
logger.info("获取日计划航班信息返回结果开始...,采集间隔{}",intervalSeconds);
Boolean isRun = true;
Long intervalMs = 30L;
Long tryTimes = 0L;
while (isRun) {
tryTimes++;
logger.info("尝试第{}次获取返回日计划消息",tryTimes);
//获取
Date waitSchdDate = (Date) redisService.get(RedisKeyConstant.KEY_WAITSCHDDATE);
Optional<Cminmsg> opCminmsg = cminmsgService.getRespSchdCminmsg(waitSchdDate,10,3000L);
if(!opCminmsg.isPresent())
{
sleepInMs(intervalMs);
continue ;
}
//更新
logger.info("找到返回的动态航班计划,开始更新动态航班信息...");
Boolean updateResult = flightInfoService.updateByDaySchd(opCminmsg.get());
if(false == updateResult)
{
logger.warn("更新动态航班信息失败,稍后重试...");
sleepInMs(intervalMs);
continue ;
}
//更新返回消息为已处理
cminmsgService.updateBatchProcessed(Arrays.asList(opCminmsg.get()));
//状态记录
Long beginId = opCminmsg.get().getCminmsgsId();
redisService.set(RedisKeyConstant.KEY_LASTBEGINID,beginId);
Boolean isWaitSchd = false;
redisService.set(RedisKeyConstant.KEY_ISWAITSCHD,isWaitSchd);
//启动消息采集线程
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
scheduledExecutorService.scheduleAtFixedRate(new MsgExchangeRunner(), 0, intervalSeconds , TimeUnit.SECONDS);
isRun = false; //退出
}
logger.info("获取日计划航班信息返回结果结束...");
} //end run
/**
* 休眠指定时间间隔-毫秒
* @param intervalMs
*/
private void sleepInMs(Long intervalMs)
{
try {
Thread.sleep(intervalMs);
} catch (InterruptedException e) {
logger.info("sleep error:{}",e.getMessage());
}
}
}