fix 修复 有界队列与优先队列 错误使用问题

feature/model
疯狂的狮子Li 1 year ago
parent 818e681cdf
commit 5429bb091c

@ -142,6 +142,32 @@ public class QueueUtils {
return boundedBlockingQueue.trySetCapacity(capacity);
}
/**
* null()
*
* @param queueName
*/
public static <T> T getPriorityQueueObject(String queueName) {
RPriorityBlockingQueue<T> queue = CLIENT.getPriorityBlockingQueue(queueName);
return queue.poll();
}
/**
* ()
*/
public static <T> boolean removePriorityQueueObject(String queueName, T data) {
RPriorityBlockingQueue<T> queue = CLIENT.getPriorityBlockingQueue(queueName);
return queue.remove(data);
}
/**
* ()
*/
public static <T> boolean destroyPriorityQueue(String queueName) {
RPriorityBlockingQueue<T> queue = CLIENT.getPriorityBlockingQueue(queueName);
return queue.delete();
}
/**
*
*
@ -169,6 +195,32 @@ public class QueueUtils {
return boundedBlockingQueue.offer(data);
}
/**
* null()
*
* @param queueName
*/
public static <T> T getBoundedQueueObject(String queueName) {
RBoundedBlockingQueue<T> queue = CLIENT.getBoundedBlockingQueue(queueName);
return queue.poll();
}
/**
* ()
*/
public static <T> boolean removeBoundedQueueObject(String queueName, T data) {
RBoundedBlockingQueue<T> queue = CLIENT.getBoundedBlockingQueue(queueName);
return queue.remove(data);
}
/**
* ()
*/
public static <T> boolean destroyBoundedQueue(String queueName) {
RBoundedBlockingQueue<T> queue = CLIENT.getBoundedBlockingQueue(queueName);
return queue.delete();
}
/**
* ( : )
*/

@ -1,9 +1,11 @@
package org.dromara.demo.controller.queue;
import cn.dev33.satoken.annotation.SaIgnore;
import org.dromara.common.core.domain.R;
import org.dromara.common.redis.utils.QueueUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBoundedBlockingQueue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -19,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
* @author Lion Li
* @version 3.6.0
*/
@SaIgnore
@Slf4j
@RequiredArgsConstructor
@RestController
@ -35,7 +38,7 @@ public class BoundedQueueController {
@GetMapping("/add")
public R<Void> add(String queueName, int capacity) {
// 用完了一定要销毁 否则会一直存在
boolean b = QueueUtils.destroyQueue(queueName);
boolean b = QueueUtils.destroyBoundedQueue(queueName);
log.info("通道: {} , 删除: {}", queueName, b);
// 初始化设置一次即可
if (QueueUtils.trySetBoundedQueueCapacity(queueName, capacity)) {
@ -64,7 +67,7 @@ public class BoundedQueueController {
@GetMapping("/remove")
public R<Void> remove(String queueName) {
String data = "data-" + 5;
if (QueueUtils.removeQueueObject(queueName, data)) {
if (QueueUtils.removeBoundedQueueObject(queueName, data)) {
log.info("通道: {} , 删除数据: {}", queueName, data);
} else {
return R.fail("操作失败");
@ -81,7 +84,7 @@ public class BoundedQueueController {
public R<Void> get(String queueName) {
String data;
do {
data = QueueUtils.getQueueObject(queueName);
data = QueueUtils.getBoundedQueueObject(queueName);
log.info("通道: {} , 获取数据: {}", queueName, data);
} while (data != null);
return R.ok("操作成功");

@ -34,7 +34,7 @@ public class PriorityQueueController {
@GetMapping("/add")
public R<Void> add(String queueName) {
// 用完了一定要销毁 否则会一直存在
boolean b = QueueUtils.destroyQueue(queueName);
boolean b = QueueUtils.destroyPriorityQueue(queueName);
log.info("通道: {} , 删除: {}", queueName, b);
for (int i = 0; i < 10; i++) {
@ -63,7 +63,7 @@ public class PriorityQueueController {
PriorityDemo data = new PriorityDemo();
data.setName(name);
data.setOrderNum(orderNum);
if (QueueUtils.removeQueueObject(queueName, data)) {
if (QueueUtils.removePriorityQueueObject(queueName, data)) {
log.info("通道: {} , 删除数据: {}", queueName, data);
} else {
return R.fail("操作失败");
@ -80,7 +80,7 @@ public class PriorityQueueController {
public R<Void> get(String queueName) {
PriorityDemo data;
do {
data = QueueUtils.getQueueObject(queueName);
data = QueueUtils.getPriorityQueueObject(queueName);
log.info("通道: {} , 获取数据: {}", queueName, data);
} while (data != null);
return R.ok("操作成功");

Loading…
Cancel
Save