From bd338dd9341a3473a2a504d55c00796dd7b98f5a Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 31 八月 2022 19:19:31 +0800 Subject: [PATCH] update 重构 QueueUtils 抽取通用方法 统一使用 适配优先队列新用法 --- ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/QueueUtils.java | 79 ++++++--------------------------------- 1 files changed, 12 insertions(+), 67 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/QueueUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/QueueUtils.java index acfc021..b8fa308 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/QueueUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/QueueUtils.java @@ -42,7 +42,7 @@ } /** - * 鑾峰彇涓�涓櫘閫氶槦鍒楁暟鎹� 娌℃湁鏁版嵁杩斿洖 null + * 閫氱敤鑾峰彇涓�涓槦鍒楁暟鎹� 娌℃湁鏁版嵁杩斿洖 null(涓嶆敮鎸佸欢杩熼槦鍒�) * * @param queueName 闃熷垪鍚� */ @@ -52,11 +52,19 @@ } /** - * 鍒犻櫎鏅�氶槦鍒楁暟鎹� + * 閫氱敤鍒犻櫎闃熷垪鏁版嵁(涓嶆敮鎸佸欢杩熼槦鍒�) */ public static <T> boolean removeQueueObject(String queueName, T data) { RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName); return queue.remove(data); + } + + /** + * 閫氱敤閿�姣侀槦鍒� 鎵�鏈夐樆濉炵洃鍚� 鎶ラ敊(涓嶆敮鎸佸欢杩熼槦鍒�) + */ + public static <T> boolean destroyQueue(String queueName) { + RBlockingQueue<T> queue = CLIENT.getBlockingQueue(queueName); + return queue.delete(); } /** @@ -118,23 +126,12 @@ * * @param queueName 闃熷垪鍚� * @param comparator 姣旇緝鍣� - */ - public static <T> boolean trySetPriorityQueueComparator(String queueName, Comparator<T> comparator) { - RPriorityBlockingQueue<T> priorityBlockingQueue = CLIENT.getPriorityBlockingQueue(queueName); - return priorityBlockingQueue.trySetComparator(comparator); - } - - /** - * 灏濊瘯璁剧疆 浼樺厛闃熷垪姣旇緝鍣� 鐢ㄤ簬鎺掑簭浼樺厛绾� - * - * @param queueName 闃熷垪鍚� - * @param comparator 姣旇緝鍣� * @param destroy 宸插瓨鍦ㄦ槸鍚﹂攢姣� */ public static <T> boolean trySetPriorityQueueComparator(String queueName, Comparator<T> comparator, boolean destroy) { RPriorityBlockingQueue<T> priorityBlockingQueue = CLIENT.getPriorityBlockingQueue(queueName); if (priorityBlockingQueue.isExists() && destroy) { - destroyPriorityQueueObject(queueName); + destroyQueue(queueName); } return priorityBlockingQueue.trySetComparator(comparator); } @@ -148,32 +145,6 @@ public static <T> boolean addPriorityQueueObject(String queueName, T data) { RPriorityBlockingQueue<T> priorityBlockingQueue = CLIENT.getPriorityBlockingQueue(queueName); return priorityBlockingQueue.offer(data); - } - - /** - * 鑾峰彇涓�涓紭鍏堥槦鍒楁暟鎹� 娌℃湁鏁版嵁杩斿洖 null - * - * @param queueName 闃熷垪鍚� - */ - public static <T> T getPriorityQueueObject(String queueName) { - RPriorityBlockingQueue<T> priorityBlockingQueue = CLIENT.getPriorityBlockingQueue(queueName); - return priorityBlockingQueue.poll(); - } - - /** - * 鍒犻櫎浼樺厛闃熷垪鏁版嵁 - */ - public static <T> boolean removePriorityQueueObject(String queueName, T data) { - RPriorityBlockingQueue<T> priorityBlockingQueue = CLIENT.getPriorityBlockingQueue(queueName); - return priorityBlockingQueue.remove(data); - } - - /** - * 閿�姣佷紭鍏堥槦鍒� - */ - public static boolean destroyPriorityQueueObject(String queueName) { - RPriorityBlockingQueue<?> priorityBlockingQueue = CLIENT.getPriorityBlockingQueue(queueName); - return priorityBlockingQueue.delete(); } /** @@ -197,7 +168,7 @@ public static <T> boolean trySetBoundedQueueCapacity(String queueName, int capacity, boolean destroy) { RBoundedBlockingQueue<T> boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName); if (boundedBlockingQueue.isExists() && destroy) { - destroyBoundedQueueObject(queueName); + destroyQueue(queueName); } return boundedBlockingQueue.trySetCapacity(capacity); } @@ -212,32 +183,6 @@ public static <T> boolean addBoundedQueueObject(String queueName, T data) { RBoundedBlockingQueue<T> boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName); return boundedBlockingQueue.offer(data); - } - - /** - * 鑾峰彇涓�涓湁鐣岄槦鍒楁暟鎹� 娌℃湁鏁版嵁杩斿洖 null - * - * @param queueName 闃熷垪鍚� - */ - public static <T> T getBoundedQueueObject(String queueName) { - RBoundedBlockingQueue<T> boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName); - return boundedBlockingQueue.poll(); - } - - /** - * 鍒犻櫎鏈夌晫闃熷垪鏁版嵁 - */ - public static <T> boolean removeBoundedQueueObject(String queueName, T data) { - RBoundedBlockingQueue<T> boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName); - return boundedBlockingQueue.remove(data); - } - - /** - * 閿�姣佹湁鐣岄槦鍒� - */ - public static boolean destroyBoundedQueueObject(String queueName) { - RBoundedBlockingQueue<?> boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName); - return boundedBlockingQueue.delete(); } /** -- Gitblit v1.9.3