#
luxiaotao1123
2020-09-03 968072c0fb57b0a95ce2d45daed8f3e2e735b27c
src/main/java/com/zy/core/cache/MessageQueue.java
@@ -1,13 +1,13 @@
package com.zy.core.cache;
import com.zy.core.Slave;
import com.zy.core.ThreadHandler;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.Task;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingQueue;
/**
 * 消息队列
@@ -22,13 +22,13 @@
    // 条码扫描仪mq交换机
    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 交换机初始化
     **/
     * mq 交换机初始化
     */
    public static void init(SlaveType type, Slave slave) {
        switch (type) {
            case Crn:
@@ -41,7 +41,7 @@
                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<>());
@@ -93,4 +93,46 @@
        }
    }
    /**
     * 取出元素,并不删除.
     */
    public static Task peek(SlaveType type, Integer id) {
        switch (type) {
            case Crn:
                return CRN_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();
            default:
                return null;
        }
    }
    public static void clear(SlaveType type, Integer id){
        switch (type) {
            case Crn:
                CRN_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;
            default:
                break;
        }
    }
}