StartCommand.java 2.22 KB
package com.bsth;


import com.bsth.data.abnormal.rate_chart.thread.FixedCalcRateThread;
import com.bsth.data.abnormal.thread.AbnormalFixedScannerThread;
import com.bsth.data.in_out.buffer.BerthDataBuffer;
import com.bsth.data.in_out.thread.Car2BerthDataPstThread;
import com.bsth.data.in_out.thread.SignalPstThread;
import com.bsth.data.led_http.LedHttpPushHandler;
import com.bsth.data.msg_queue.SignalAndAttConsumeQueue;
import com.bsth.data.msg_queue.WebSocketPushQueue;
import org.joda.time.format.DateTimeFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;


/**
 * 随应用启动运行
 * @author PanZhao
 *
 */
@Component
public class StartCommand implements CommandLineRunner{

	@Autowired
	SignalPstThread signalPstThread;
	@Autowired
	LedHttpPushHandler ledHttpPushHandler;
	@Autowired
	BerthDataBuffer berthDataBuffer;
	@Autowired
	Car2BerthDataPstThread car2BerthDataPstThread;
	@Autowired
	AbnormalFixedScannerThread abnormalFixedScannerThread;
	@Autowired
	FixedCalcRateThread fixedCalcRateThread;

	@Override
	public void run(String... arg0){
		
		try {

			//同步屏 LED 推送服务
			//ledHttpPushHandler.start();

			//signal、牌照识别、查询一体机数据消费队列
			SignalAndAttConsumeQueue.start();
			//websocket 消费队列
			WebSocketPushQueue.start();

			//初始化泊位信息
			berthDataBuffer.init();

			ScheduledExecutorService sexec = Application.mainServices;
			//进出场数据入库线程
			sexec.scheduleWithFixedDelay(signalPstThread, 30, 100, TimeUnit.SECONDS);
			//实时车辆泊位数据入库
			sexec.scheduleWithFixedDelay(car2BerthDataPstThread, 20, 20, TimeUnit.SECONDS);

			/**
			 * 异常监管
			 */
			sexec.scheduleAtFixedRate(abnormalFixedScannerThread, 40, 60, TimeUnit.SECONDS);
			//定时计算统计率(第0秒开始)
			int seconeds = Integer.parseInt(DateTimeFormat.forPattern("mm").print(System.currentTimeMillis()));
			sexec.scheduleAtFixedRate(fixedCalcRateThread, 60 - seconeds, 60, TimeUnit.SECONDS);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}