From 71333f8fbfc321bced0d7a3916e996de7fdac284 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期六, 15 八月 2020 11:17:08 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/ServerBootstrap.java |   68 +++++++++++++++++++++++++++++++--
 1 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/zy/core/ServerBootstrap.java b/src/main/java/com/zy/core/ServerBootstrap.java
index b532458..02129a1 100644
--- a/src/main/java/com/zy/core/ServerBootstrap.java
+++ b/src/main/java/com/zy/core/ServerBootstrap.java
@@ -1,12 +1,17 @@
 package com.zy.core;
 
-import com.alibaba.fastjson.JSON;
+import com.zy.core.cache.MessageQueue;
+import com.zy.core.cache.SlaveConnection;
+import com.zy.core.enums.SlaveType;
+import com.zy.core.model.CrnSlave;
 import com.zy.core.properties.SlaveProperties;
+import com.zy.core.thread.BarcodeThread;
+import com.zy.core.thread.CrnThread;
+import com.zy.core.thread.DevpThread;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 
 /**
@@ -18,14 +23,67 @@
 
     @Autowired
     private SlaveProperties slaveProperties;
+    @Autowired
+    private MainProcess mainProcess;
 
 
-    @PostConstruct
+//    @PostConstruct
     public void init(){
-        System.out.println(JSON.toJSONString(slaveProperties));
-
+        // 鍒濆鍖栨秷鎭槦鍒�
+        initMq();
+        // 鍒濆鍖栦笅浣嶆満绾跨▼
+        initThread();
+        // 寮�濮嬩富娴佺▼杩涚▼
+        mainProcess.start();
     }
 
+    private void initMq(){
+        // 鍒濆鍖栧爢鍨涙満mq
+        for (Slave crn : slaveProperties.getCrn()) {
+            MessageQueue.init(SlaveType.Crn, crn);
+        }
+        // 鍒濆鍖栬緭閫佺嚎mq
+        for (Slave devp : slaveProperties.getDevp()) {
+            MessageQueue.init(SlaveType.Devp, devp);
+        }
+        // 鍒濆鍖栨潯鐮佹壂鎻忎华mq
+        for (Slave barcode : slaveProperties.getBarcode()) {
+            MessageQueue.init(SlaveType.Barcode, barcode);
+        }
+        // 鍒濆鍖朙ed鐏痬q
+        for (Slave led : slaveProperties.getLed()) {
+            MessageQueue.init(SlaveType.Led, led);
+        }
+        // 鍒濆鍖栫绉癿q
+        for (Slave scale : slaveProperties.getScale()) {
+            MessageQueue.init(SlaveType.Scale, scale);
+        }
+    }
+
+    private void initThread(){
+        // 鍒濆鍖栧爢鍨涙満绾跨▼
+        for (CrnSlave crn : slaveProperties.getCrn()) {
+            CrnThread crnThread = new CrnThread(crn);
+            new Thread(crnThread).start();
+            SlaveConnection.put(SlaveType.Crn, crn.getId(), crnThread);
+        }
+
+        // 鍒濆鍖栬緭閫佺嚎绾跨▼
+        for (Slave devp : slaveProperties.getDevp()) {
+            DevpThread devpThread = new DevpThread(devp);
+            new Thread(devpThread).start();
+            SlaveConnection.put(SlaveType.Devp, devp.getId(), devpThread);
+        }
+
+        // 鍒濆鍖栨潯鐮佹壂鎻忎华绾跨▼
+        for (Slave barcode : slaveProperties.getBarcode()) {
+            BarcodeThread barcodeThread = new BarcodeThread(barcode);
+            new Thread(barcodeThread).start();
+            SlaveConnection.put(SlaveType.Barcode, barcode.getId(), barcodeThread);
+        }
+    }
+
+
     @PreDestroy
     public void destroy() {
     }

--
Gitblit v1.9.1