| | |
| | | package com.zy.asrs.wcs.rcs.cache; |
| | | |
| | | import com.zy.asrs.wcs.rcs.model.Task; |
| | | import com.zy.asrs.wcs.rcs.model.MessageTask; |
| | | import com.zy.asrs.wcs.rcs.model.enums.SlaveType; |
| | | |
| | | import java.util.Map; |
| | |
| | | public class MessageQueue { |
| | | |
| | | // 输送线mq交换机 |
| | | private static final Map<Integer, ConcurrentLinkedQueue<Task>> DEVP_EXCHANGE = new ConcurrentHashMap<>(); |
| | | private static final Map<Integer, ConcurrentLinkedQueue<MessageTask>> CONVEYOR_EXCHANGE = new ConcurrentHashMap<>(); |
| | | // 条码扫描仪mq交换机 |
| | | private static final Map<Integer, ConcurrentLinkedQueue<Task>> BARCODE_EXCHANGE = new ConcurrentHashMap<>(); |
| | | private static final Map<Integer, ConcurrentLinkedQueue<MessageTask>> BARCODE_EXCHANGE = new ConcurrentHashMap<>(); |
| | | // Led灯 mq交换机 |
| | | private static final Map<Integer, LinkedBlockingQueue<Task>> LED_EXCHANGE = new ConcurrentHashMap<>(); |
| | | private static final Map<Integer, LinkedBlockingQueue<MessageTask>> LED_EXCHANGE = new ConcurrentHashMap<>(); |
| | | // 磅称mq交换机 |
| | | private static final Map<Integer, ConcurrentLinkedQueue<Task>> SCALE_EXCHANGE = new ConcurrentHashMap<>(); |
| | | private static final Map<Integer, ConcurrentLinkedQueue<MessageTask>> SCALE_EXCHANGE = new ConcurrentHashMap<>(); |
| | | // 台车mq交换机 |
| | | private static final Map<Integer, ConcurrentLinkedQueue<Task>> CAR_EXCHANGE = new ConcurrentHashMap<>(); |
| | | private static final Map<Integer, ConcurrentLinkedQueue<MessageTask>> CAR_EXCHANGE = new ConcurrentHashMap<>(); |
| | | //四向穿梭车mq交换机 |
| | | private static final Map<Integer, ConcurrentLinkedQueue<Task>> SHUTTLE_EXCHANGE = new ConcurrentHashMap<>(); |
| | | private static final Map<Integer, ConcurrentLinkedQueue<MessageTask>> SHUTTLE_EXCHANGE = new ConcurrentHashMap<>(); |
| | | //提升机mq交换机 |
| | | private static final Map<Integer, ConcurrentLinkedQueue<Task>> LIFT_EXCHANGE = new ConcurrentHashMap<>(); |
| | | private static final Map<Integer, ConcurrentLinkedQueue<MessageTask>> LIFT_EXCHANGE = new ConcurrentHashMap<>(); |
| | | |
| | | /** |
| | | * mq 交换机初始化 |
| | | */ |
| | | public static void init(SlaveType type, Integer id) { |
| | | switch (type) { |
| | | case Devp: |
| | | DEVP_EXCHANGE.put(id, new ConcurrentLinkedQueue<>()); |
| | | case Conveyor: |
| | | CONVEYOR_EXCHANGE.put(id, new ConcurrentLinkedQueue<>()); |
| | | break; |
| | | case Barcode: |
| | | BARCODE_EXCHANGE.put(id, new ConcurrentLinkedQueue<>()); |
| | |
| | | * 添加元素 |
| | | * 如果发现队列已满无法添加的话,会直接返回false。 |
| | | */ |
| | | public static boolean offer(SlaveType type, Integer id, Task task) { |
| | | public static boolean offer(SlaveType type, Integer id, MessageTask task) { |
| | | switch (type) { |
| | | case Devp: |
| | | return DEVP_EXCHANGE.get(id).offer(task); |
| | | case Conveyor: |
| | | return CONVEYOR_EXCHANGE.get(id).offer(task); |
| | | case Barcode: |
| | | return BARCODE_EXCHANGE.get(id).offer(task); |
| | | case Led: |
| | |
| | | * 移除元素 |
| | | * 若队列为空,返回null。 |
| | | */ |
| | | public static Task poll(SlaveType type, Integer id) { |
| | | public static MessageTask poll(SlaveType type, Integer id) { |
| | | switch (type) { |
| | | case Devp: |
| | | return DEVP_EXCHANGE.get(id).poll(); |
| | | case Conveyor: |
| | | return CONVEYOR_EXCHANGE.get(id).poll(); |
| | | case Barcode: |
| | | return BARCODE_EXCHANGE.get(id).poll(); |
| | | case Led: |
| | |
| | | /** |
| | | * 取出元素,并不删除. |
| | | */ |
| | | public static Task peek(SlaveType type, Integer id) { |
| | | public static MessageTask peek(SlaveType type, Integer id) { |
| | | switch (type) { |
| | | case Devp: |
| | | return DEVP_EXCHANGE.get(id).peek(); |
| | | case Conveyor: |
| | | return CONVEYOR_EXCHANGE.get(id).peek(); |
| | | case Barcode: |
| | | return BARCODE_EXCHANGE.get(id).peek(); |
| | | case Led: |
| | |
| | | |
| | | public static void clear(SlaveType type, Integer id){ |
| | | switch (type) { |
| | | case Devp: |
| | | DEVP_EXCHANGE.get(id).clear(); |
| | | case Conveyor: |
| | | CONVEYOR_EXCHANGE.get(id).clear(); |
| | | break; |
| | | case Barcode: |
| | | BARCODE_EXCHANGE.get(id).clear(); |