StartCommand.java 1.81 KB
package com.bsth;


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 com.bsth.security.SecurityMetadataSourceService;
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
	SecurityMetadataSourceService invocationSecurityMetadataSourceService;
	@Autowired
	SignalPstThread signalPstThread;
	@Autowired
	LedHttpPushHandler ledHttpPushHandler;
	@Autowired
	BerthDataBuffer berthDataBuffer;
	@Autowired
	Car2BerthDataPstThread car2BerthDataPstThread;

	@Override
	public void run(String... arg0){
		
		try {
			//启动时加载所有资源
			invocationSecurityMetadataSourceService.loadResourceDefine();

			//同步屏 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);

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