From 2f662f2a75ca9af4d28a9af5eebe3d2a67c5c17c Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期一, 14 三月 2022 13:27:22 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/cache/MessageQueue.java |   79 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 75 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/zy/core/cache/MessageQueue.java b/src/main/java/com/zy/core/cache/MessageQueue.java
index deb09e8..ed5b018 100644
--- a/src/main/java/com/zy/core/cache/MessageQueue.java
+++ b/src/main/java/com/zy/core/cache/MessageQueue.java
@@ -7,6 +7,7 @@
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.LinkedBlockingQueue;
 
 /**
  * 娑堟伅闃熷垪
@@ -15,15 +16,19 @@
 public class MessageQueue {
 
     // 鍫嗗灈鏈簃q浜ゆ崲鏈�
-    private static final Map<Integer, ConcurrentLinkedQueue<Task>> CRN_EXCHANGE = new ConcurrentHashMap<>();
+    private static final Map<Integer, LinkedBlockingQueue<Task>> CRN_EXCHANGE = new ConcurrentHashMap<>();
+    // 绌挎杞q浜ゆ崲鏈�
+    private static final Map<Integer, LinkedBlockingQueue<Task>> STE_EXCHANGE = new ConcurrentHashMap<>();
     // 杈撻�佺嚎mq浜ゆ崲鏈�
     private static final Map<Integer, ConcurrentLinkedQueue<Task>> DEVP_EXCHANGE = new ConcurrentHashMap<>();
     // 鏉$爜鎵弿浠猰q浜ゆ崲鏈�
     private static final Map<Integer, ConcurrentLinkedQueue<Task>> BARCODE_EXCHANGE = new ConcurrentHashMap<>();
     // Led鐏� mq浜ゆ崲鏈�
-    private static final Map<Integer, ConcurrentLinkedQueue<Task>> LED_EXCHANGE = new ConcurrentHashMap<>();
+    private static final Map<Integer, LinkedBlockingQueue<Task>> LED_EXCHANGE = new ConcurrentHashMap<>();
     // 纾呯Оmq浜ゆ崲鏈�
     private static final Map<Integer, ConcurrentLinkedQueue<Task>> SCALE_EXCHANGE = new ConcurrentHashMap<>();
+    // 鍙拌溅mq浜ゆ崲鏈�
+    private static final Map<Integer, ConcurrentLinkedQueue<Task>> CAR_EXCHANGE = new ConcurrentHashMap<>();
 
     /**
      * mq 浜ゆ崲鏈哄垵濮嬪寲
@@ -31,7 +36,10 @@
     public static void init(SlaveType type, Slave slave) {
         switch (type) {
             case Crn:
-                CRN_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>());
+                CRN_EXCHANGE.put(slave.getId(), new LinkedBlockingQueue<>(1));
+                break;
+            case Ste:
+                STE_EXCHANGE.put(slave.getId(), new LinkedBlockingQueue<>(1));
                 break;
             case Devp:
                 DEVP_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>());
@@ -40,10 +48,13 @@
                 BARCODE_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>());
                 break;
             case Led:
-                LED_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>());
+                LED_EXCHANGE.put(slave.getId(), new LinkedBlockingQueue<>(1));
                 break;
             case Scale:
                 SCALE_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>());
+                break;
+            case Car:
+                CAR_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>());
                 break;
             default:
                 break;
@@ -58,6 +69,8 @@
         switch (type) {
             case Crn:
                 return CRN_EXCHANGE.get(id).offer(task);
+            case Ste:
+                return STE_EXCHANGE.get(id).offer(task);
             case Devp:
                 return DEVP_EXCHANGE.get(id).offer(task);
             case Barcode:
@@ -66,6 +79,8 @@
                 return LED_EXCHANGE.get(id).offer(task);
             case Scale:
                 return SCALE_EXCHANGE.get(id).offer(task);
+            case Car:
+                return CAR_EXCHANGE.get(id).offer(task);
             default:
                 return false;
         }
@@ -79,6 +94,8 @@
         switch (type) {
             case Crn:
                 return CRN_EXCHANGE.get(id).poll();
+            case Ste:
+                return STE_EXCHANGE.get(id).poll();
             case Devp:
                 return DEVP_EXCHANGE.get(id).poll();
             case Barcode:
@@ -87,9 +104,63 @@
                 return LED_EXCHANGE.get(id).poll();
             case Scale:
                 return SCALE_EXCHANGE.get(id).poll();
+            case Car:
+                return CAR_EXCHANGE.get(id).poll();
             default:
                 return null;
         }
     }
 
+    /**
+     * 鍙栧嚭鍏冪礌锛屽苟涓嶅垹闄�.
+     */
+    public static Task peek(SlaveType type, Integer id) {
+        switch (type) {
+            case Crn:
+                return CRN_EXCHANGE.get(id).peek();
+            case Ste:
+                return STE_EXCHANGE.get(id).peek();
+            case Devp:
+                return DEVP_EXCHANGE.get(id).peek();
+            case Barcode:
+                return BARCODE_EXCHANGE.get(id).peek();
+            case Led:
+                return LED_EXCHANGE.get(id).peek();
+            case Scale:
+                return SCALE_EXCHANGE.get(id).peek();
+            case Car:
+                return CAR_EXCHANGE.get(id).peek();
+            default:
+                return null;
+        }
+    }
+
+    public static void clear(SlaveType type, Integer id){
+        switch (type) {
+            case Crn:
+                CRN_EXCHANGE.get(id).clear();
+                break;
+            case Ste:
+                STE_EXCHANGE.get(id).clear();
+                break;
+            case Devp:
+                DEVP_EXCHANGE.get(id).clear();
+                break;
+            case Barcode:
+                BARCODE_EXCHANGE.get(id).clear();
+                break;
+            case Led:
+                LED_EXCHANGE.get(id).clear();
+                break;
+            case Scale:
+                SCALE_EXCHANGE.get(id).clear();
+                break;
+            case Car:
+                CAR_EXCHANGE.get(id).clear();
+                break;
+            default:
+                break;
+        }
+    }
+
 }

--
Gitblit v1.9.1