自动化立体仓库 - WCS系统
#
zjj
2024-01-15 855bf7559274cbc7e3008eaac313e49e48d14e33
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.zy.core.cache;
 
import com.zy.core.Slave;
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;
 
/**
 * 消息队列
 * Created by vincent on 2020/8/5
 */
public class MessageQueue {
 
    // 堆垛机mq交换机
    private static final Map<Integer, LinkedBlockingQueue<Task>> CRN_EXCHANGE = new ConcurrentHashMap<>();
    // 输送线mq交换机
    private static final Map<Integer, ConcurrentLinkedQueue<Task>> DEVP_EXCHANGE = new ConcurrentHashMap<>();
    // 条码扫描仪mq交换机
    private static final Map<Integer, ConcurrentLinkedQueue<Task>> BARCODE_EXCHANGE = new ConcurrentHashMap<>();
    // Led灯 mq交换机
    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<>();
 
    private static final Map<Integer, LinkedBlockingQueue<Task>> RGV_EXCHANGE = new ConcurrentHashMap<>();
 
    /**
     * mq 交换机初始化
     */
    public static void init(SlaveType type, Slave slave) {
        switch (type) {
            case Crn:
                CRN_EXCHANGE.put(slave.getId(), new LinkedBlockingQueue<>(1));
                break;
            case Rgv:
                RGV_EXCHANGE.put(slave.getId(), new LinkedBlockingQueue<>(1));
                break;
            case Devp:
                DEVP_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>());
                break;
            case Barcode:
                BARCODE_EXCHANGE.put(slave.getId(), new ConcurrentLinkedQueue<>());
                break;
            case Led:
                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;
        }
    }
 
    /**
     * 添加元素
     * 如果发现队列已满无法添加的话,会直接返回false。
     */
    public static boolean offer(SlaveType type, Integer id, Task task) {
        switch (type) {
            case Crn:
                return CRN_EXCHANGE.get(id).offer(task);
            case Rgv:
                return RGV_EXCHANGE.get(id).offer(task);
            case Devp:
                return DEVP_EXCHANGE.get(id).offer(task);
            case Barcode:
                return BARCODE_EXCHANGE.get(id).offer(task);
            case Led:
                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;
        }
    }
 
    /**
     * 移除元素
     * 若队列为空,返回null。
     */
    public static Task poll(SlaveType type, Integer id) {
        switch (type) {
            case Crn:
                return CRN_EXCHANGE.get(id).poll();
            case Rgv:
                return RGV_EXCHANGE.get(id).poll();
            case Devp:
                return DEVP_EXCHANGE.get(id).poll();
            case Barcode:
                return BARCODE_EXCHANGE.get(id).poll();
            case Led:
                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 Rgv:
                return RGV_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 Rgv:
                RGV_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;
        }
    }
 
}