|
|
@@ -1,174 +0,0 @@
|
|
|
-package com.utic.ptis.server.process.dbms;
|
|
|
-
|
|
|
-import com.utic.common.dto.ProcessStateDto;
|
|
|
-import com.utic.common.spring.SpringUtils;
|
|
|
-import com.utic.common.utils.Elapsed;
|
|
|
-import com.utic.ptis.server.config.ThreadPoolInitializer;
|
|
|
-import com.utic.ptis.server.dao.mapper.utic.ProcessMapper;
|
|
|
-import com.utic.ptis.server.dao.mapper.utic.batch.UticPtisServerDao;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.slf4j.MDC;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.concurrent.Executors;
|
|
|
-import java.util.concurrent.LinkedBlockingQueue;
|
|
|
-import java.util.concurrent.ThreadPoolExecutor;
|
|
|
-
|
|
|
-@Slf4j
|
|
|
-@SuppressWarnings("unchecked")
|
|
|
-@RequiredArgsConstructor
|
|
|
-@Service
|
|
|
-public class DbmsDataProcess {
|
|
|
-
|
|
|
- private final LinkedBlockingQueue<DbmsData> dbmsDataBlockingQueue = new LinkedBlockingQueue<>(1000);
|
|
|
- private final ThreadPoolExecutor taskExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);
|
|
|
-
|
|
|
- private final DbmsDataAsyncTask asyncTask;
|
|
|
- private final ProcessMapper processMapper;
|
|
|
- private final UticPtisServerDao uticPtisServerDao;
|
|
|
-
|
|
|
- private int maxCore = Runtime.getRuntime().availableProcessors();
|
|
|
-
|
|
|
- public void run() {
|
|
|
- log.info("DbmsDataProcess.run: Start.");
|
|
|
- if (this.maxCore < 8) {
|
|
|
- this.maxCore = 8;
|
|
|
- }
|
|
|
- ThreadPoolInitializer poolInitializer = SpringUtils.getBean(ThreadPoolInitializer.class);
|
|
|
- int executePool = poolInitializer.getDbms();
|
|
|
- for (int ii = 0; ii < executePool; ii++) {
|
|
|
- log.info("DbmsDataProcess.Task: {}", ii);
|
|
|
- this.taskExecutor.execute(() -> {
|
|
|
- boolean isRunning = true;
|
|
|
- while (isRunning) {
|
|
|
- try {
|
|
|
- DbmsData data = dbmsDataBlockingQueue.take();
|
|
|
- this.asyncTask.run(this, data);
|
|
|
- }
|
|
|
- catch (Exception e) {
|
|
|
- log.error("DbmsDataProcess.Task: Exception: {}", e.getMessage(), e);
|
|
|
- Thread.currentThread().interrupt();
|
|
|
- isRunning = false;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- log.info("DbmsDataProcess.run: ..End.");
|
|
|
- }
|
|
|
-
|
|
|
- public void runJob(DbmsData data) {
|
|
|
- if (data.getType() == DbmsData.DBMS_DATA_PROCESS_STTS) {
|
|
|
- ProcessStateDto stts = (ProcessStateDto) data.getData();
|
|
|
- this.processMapper.updateProcessState(stts);
|
|
|
- }
|
|
|
- else {
|
|
|
- process(data);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void process(DbmsData data) {
|
|
|
- int result = -1;
|
|
|
- int type = -1;
|
|
|
-// RegionCenter center = data.getCenter();
|
|
|
- try {
|
|
|
-// MDC.put("id", center.getLogKey());
|
|
|
- Elapsed elapsed1 = new Elapsed();
|
|
|
-
|
|
|
- type = data.getType();
|
|
|
- switch(type) {
|
|
|
- case DbmsData.DBMS_DATA_INT_PHASE_CHANGE:
|
|
|
- List<HashMap<String, Object>> changeLists = (List<HashMap<String, Object>>)data.getData();
|
|
|
-// result = this.uticPtisServerDao.updateIntPhaseChange(center.getRegionCd(), changeLists);
|
|
|
-// List<IntStatusDto> intStatusLists = (List<IntStatusDto>)data.getData();
|
|
|
-// result = this.sigCommServerDao.updateIntPhaseChange(center.getRegionCd(), intStatusLists);
|
|
|
- break;
|
|
|
- case DbmsData.DBMS_DATA_INT_PHASE_CYCLE:
|
|
|
- List<HashMap<String, Object>> cycleLists = (List<HashMap<String, Object>>)data.getData();
|
|
|
-// result = this.uticPtisServerDao.updateIntStaticCycle(center.getRegionCd(), cycleLists);
|
|
|
- break;
|
|
|
-
|
|
|
- case DbmsData.DBMS_DATA_INT_EVENT_INFO:
|
|
|
- List<HashMap<String, Object>> eventLists = (List<HashMap<String, Object>>)data.getData();
|
|
|
-// result = this.uticPtisServerDao.insertIntEventHist(center.getRegionCd(), eventLists);
|
|
|
- break;
|
|
|
-
|
|
|
-
|
|
|
- case DbmsData.DBMS_DATA_INT_OPER_PLAN:
|
|
|
- List<HashMap<String, Object>> operPlanLists = (List<HashMap<String, Object>>)data.getData();
|
|
|
-// result = this.uticPtisServerDao.updateIntTodPlan(center.getRegionCd(), operPlanLists);
|
|
|
-// result = this.uticPtisServerDao.updateIntOperPlan(center.getRegionCd(), operPlanLists);
|
|
|
- break;
|
|
|
- case DbmsData.DBMS_DATA_INT_HOLIDAY:
|
|
|
- List<HashMap<String, Object>> holidayLists = (List<HashMap<String, Object>>)data.getData();
|
|
|
-// result = this.uticPtisServerDao.updateIntHolidayPlan(center.getRegionCd(), holidayLists);
|
|
|
- break;
|
|
|
- case DbmsData.DBMS_DATA_INT_WEEKDAY:
|
|
|
- List<HashMap<String, Object>> weekdayLists = (List<HashMap<String, Object>>)data.getData();
|
|
|
-// result = this.uticPtisServerDao.updateIntWeekdayPlan(center.getRegionCd(), weekdayLists);
|
|
|
- break;
|
|
|
- case DbmsData.DBMS_DATA_INT_FUNCTION:
|
|
|
- List<HashMap<String, Object>> functionLists = (List<HashMap<String, Object>>)data.getData();
|
|
|
-// result = this.uticPtisServerDao.updateIntReservedPlan(center.getRegionCd(), functionLists);
|
|
|
- break;
|
|
|
- case DbmsData.DBMS_DATA_INT_SIGNALMAP:
|
|
|
- List<HashMap<String, Object>> signalMapLists = (List<HashMap<String, Object>>)data.getData();
|
|
|
-// result = this.uticPtisServerDao.updateIntSignalMap(center.getRegionCd(), signalMapLists);
|
|
|
- break;
|
|
|
- case DbmsData.DBMS_DATA_INT_TYPE:
|
|
|
-// List<HashMap<String, Object>> intTypeLists = (List<HashMap<String, Object>>)data.getData();
|
|
|
-// result = this.uticPtisServerDao.updateIntType(center.getRegionCd(), intTypeLists);
|
|
|
- break;
|
|
|
-
|
|
|
- case DbmsData.DBMS_DATA_CENTER_STTS_UPDATE:
|
|
|
-// TbRegionCenterComm updStts = (TbRegionCenterComm) data.getData();
|
|
|
-// this.centerMapper.updateCommState(updStts);
|
|
|
- break;
|
|
|
-
|
|
|
- case DbmsData.DBMS_DATA_CENTER_STTS:
|
|
|
-// TbRegionCenterComm stts = (TbRegionCenterComm) data.getData();
|
|
|
-// if (TbRegionCenterComm.CENTER_COMM_START.equals(stts.getCommState())) {
|
|
|
-//// result = this.centerMapper.updateCommStateConnect(stts);
|
|
|
-// }
|
|
|
-// else if (TbRegionCenterComm.CENTER_COMM_STOP.equals(stts.getCommState())) {
|
|
|
-//// result = this.centerMapper.updateCommStateDisconnect(stts);
|
|
|
-//// // 통신 Offline 인 센터에 속한 교차로 통신상태를 모두 Offline 으로 업데이트 한다.
|
|
|
-//// result = this.intMapper.updateRegionIntSttsOffline(stts.getRegionCd());
|
|
|
-// }
|
|
|
- break;
|
|
|
- default:
|
|
|
- log.error("DbmsJobProcess.process: Unknown Request {}.", type);
|
|
|
- break;
|
|
|
- }
|
|
|
-// log.info("DbmsDataProcess.run: [{}]. {}, {} EA. {}",
|
|
|
-// center.getLogKey(), type, result, Elapsed.elapsedStr(elapsed1.nanoSeconds()));
|
|
|
- }
|
|
|
- catch (Exception e) {
|
|
|
-// log.error("DbmsJobProcess.process: [{}]. {}, Exception: {}", center.getLogKey(), type, e.toString());
|
|
|
- }
|
|
|
- finally {
|
|
|
-// MDC.remove(center.getLogKey());
|
|
|
- MDC.clear();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- * 작업큐에 데이터 추가
|
|
|
- */
|
|
|
- public boolean add(DbmsData data) {
|
|
|
- boolean offer = false;
|
|
|
- try {
|
|
|
- offer = dbmsDataBlockingQueue.offer(data);
|
|
|
- if (!offer) {
|
|
|
- log.error("DbmsDataProcess.add: Queue Full Error, Size: {} EA", dbmsDataBlockingQueue.size());
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e) {
|
|
|
- log.error("DbmsDataProcess.add: Exception: {}", e.getMessage(), e);
|
|
|
- }
|
|
|
- return offer;
|
|
|
- }
|
|
|
-
|
|
|
-}
|