mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-24 07:19:46 +08:00
update 重构 QueueUtils 抽取通用方法 统一使用 适配优先队列新用法
This commit is contained in:
@ -35,7 +35,7 @@ public class BoundedQueueController {
|
||||
@GetMapping("/add")
|
||||
public R<Void> add(String queueName, int capacity) {
|
||||
// 用完了一定要销毁 否则会一直存在
|
||||
boolean b = QueueUtils.destroyBoundedQueueObject(queueName);
|
||||
boolean b = QueueUtils.destroyQueue(queueName);
|
||||
log.info("通道: {} , 删除: {}", queueName, b);
|
||||
// 初始化设置一次即可
|
||||
if (QueueUtils.trySetBoundedQueueCapacity(queueName, capacity)) {
|
||||
@ -64,7 +64,7 @@ public class BoundedQueueController {
|
||||
@GetMapping("/remove")
|
||||
public R<Void> remove(String queueName) {
|
||||
String data = "data-" + 5;
|
||||
if (QueueUtils.removeBoundedQueueObject(queueName, data)) {
|
||||
if (QueueUtils.removeQueueObject(queueName, data)) {
|
||||
log.info("通道: {} , 删除数据: {}", queueName, data);
|
||||
} else {
|
||||
return R.fail("操作失败");
|
||||
@ -81,7 +81,7 @@ public class BoundedQueueController {
|
||||
public R<Void> get(String queueName) {
|
||||
String data;
|
||||
do {
|
||||
data = QueueUtils.getBoundedQueueObject(queueName);
|
||||
data = QueueUtils.getQueueObject(queueName);
|
||||
log.info("通道: {} , 获取数据: {}", queueName, data);
|
||||
} while (data != null);
|
||||
return R.ok("操作成功");
|
||||
|
@ -2,6 +2,7 @@ package com.ruoyi.demo.controller.queue;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 实体类 注意不允许使用内部类 否则会找不到类
|
||||
@ -11,7 +12,12 @@ import lombok.NoArgsConstructor;
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class PriorityDemo {
|
||||
public class PriorityDemo implements Comparable<PriorityDemo> {
|
||||
private String name;
|
||||
private Integer orderNum;
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull PriorityDemo other) {
|
||||
return Integer.compare(getOrderNum(), other.getOrderNum());
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
package com.ruoyi.demo.controller.queue;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* 比较器 注意不允许使用 内部类或匿名类或lambda表达式 会找不到类
|
||||
*
|
||||
* @author Lion Li
|
||||
* @version 3.6.0
|
||||
*/
|
||||
public class PriorityDemoComparator implements Comparator<PriorityDemo> {
|
||||
@Override
|
||||
public int compare(PriorityDemo pd1, PriorityDemo pd2) {
|
||||
return Integer.compare(pd1.getOrderNum(), pd2.getOrderNum());
|
||||
}
|
||||
}
|
@ -34,16 +34,9 @@ public class PriorityQueueController {
|
||||
@GetMapping("/add")
|
||||
public R<Void> add(String queueName) {
|
||||
// 用完了一定要销毁 否则会一直存在
|
||||
boolean b = QueueUtils.destroyPriorityQueueObject(queueName);
|
||||
boolean b = QueueUtils.destroyQueue(queueName);
|
||||
log.info("通道: {} , 删除: {}", queueName, b);
|
||||
// 初始化设置一次即可 此处注意 不允许用内部类或匿名类
|
||||
boolean flag = QueueUtils.trySetPriorityQueueComparator(queueName, new PriorityDemoComparator());
|
||||
if (flag) {
|
||||
log.info("通道: {} , 设置比较器成功", queueName);
|
||||
} else {
|
||||
log.info("通道: {} , 设置比较器失败", queueName);
|
||||
return R.fail("操作失败");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int randomNum = RandomUtil.randomInt(10);
|
||||
PriorityDemo data = new PriorityDemo();
|
||||
@ -70,7 +63,7 @@ public class PriorityQueueController {
|
||||
PriorityDemo data = new PriorityDemo();
|
||||
data.setName(name);
|
||||
data.setOrderNum(orderNum);
|
||||
if (QueueUtils.removePriorityQueueObject(queueName, data)) {
|
||||
if (QueueUtils.removeQueueObject(queueName, data)) {
|
||||
log.info("通道: {} , 删除数据: {}", queueName, data);
|
||||
} else {
|
||||
return R.fail("操作失败");
|
||||
@ -87,7 +80,7 @@ public class PriorityQueueController {
|
||||
public R<Void> get(String queueName) {
|
||||
PriorityDemo data;
|
||||
do {
|
||||
data = QueueUtils.getPriorityQueueObject(queueName);
|
||||
data = QueueUtils.getQueueObject(queueName);
|
||||
log.info("通道: {} , 获取数据: {}", queueName, data);
|
||||
} while (data != null);
|
||||
return R.ok("操作成功");
|
||||
|
Reference in New Issue
Block a user