From 3aceaead7e8dddcd874e42d11a886f5fda3bba68 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 8 Aug 2024 11:33:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20IT=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?-=E5=A2=9E=E5=8A=A0=E5=9F=BA=E4=BA=8E=E9=98=9F=E5=88=97?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E6=AD=A5=E4=B8=8A=E6=8A=A5=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1212437796192256]IT服务-增加基于队列的异步上报工单方式 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1212437796192256 --- .../queue/NeatLogicBlockingQueue.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/main/java/neatlogic/framework/asynchronization/queue/NeatLogicBlockingQueue.java diff --git a/src/main/java/neatlogic/framework/asynchronization/queue/NeatLogicBlockingQueue.java b/src/main/java/neatlogic/framework/asynchronization/queue/NeatLogicBlockingQueue.java new file mode 100644 index 000000000..0dc938daa --- /dev/null +++ b/src/main/java/neatlogic/framework/asynchronization/queue/NeatLogicBlockingQueue.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.framework.asynchronization.queue; + +import neatlogic.framework.asynchronization.threadlocal.TenantContext; + +import java.util.concurrent.BlockingQueue; + +public class NeatLogicBlockingQueue { + + private final BlockingQueue> blockingQueue; + + public NeatLogicBlockingQueue(BlockingQueue> _blockingQueue) { + this.blockingQueue = _blockingQueue; + } + + public boolean offer(T id) { + return blockingQueue.offer(new Task<>(id)); + } + + public T take() throws InterruptedException { + Task task = blockingQueue.take(); + TenantContext tenantContext = TenantContext.get(); + if (tenantContext != null) { + tenantContext.switchTenant(task.getTenantUuid()); + } else { + TenantContext.init(task.getTenantUuid()); + } + return task.getT(); + } + + private static class Task { + private final T t; + private final String tenantUuid; + + public Task(T t) { + this.t = t; + this.tenantUuid = TenantContext.get().getTenantUuid(); + } + + public T getT() { + return t; + } + + public String getTenantUuid() { + return tenantUuid; + } + } +} -- Gitee From ad0777d1f08aec48d7e7a58678b32e161e1f423c Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 8 Aug 2024 11:44:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20IT=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?-=E5=A2=9E=E5=8A=A0=E5=9F=BA=E4=BA=8E=E9=98=9F=E5=88=97?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E6=AD=A5=E4=B8=8A=E6=8A=A5=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1212437796192256]IT服务-增加基于队列的异步上报工单方式 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1212437796192256 --- .../asynchronization/queue/NeatLogicBlockingQueue.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/neatlogic/framework/asynchronization/queue/NeatLogicBlockingQueue.java b/src/main/java/neatlogic/framework/asynchronization/queue/NeatLogicBlockingQueue.java index 0dc938daa..72ef2d459 100644 --- a/src/main/java/neatlogic/framework/asynchronization/queue/NeatLogicBlockingQueue.java +++ b/src/main/java/neatlogic/framework/asynchronization/queue/NeatLogicBlockingQueue.java @@ -29,8 +29,8 @@ public class NeatLogicBlockingQueue { this.blockingQueue = _blockingQueue; } - public boolean offer(T id) { - return blockingQueue.offer(new Task<>(id)); + public boolean offer(T t) { + return blockingQueue.offer(new Task<>(t)); } public T take() throws InterruptedException { -- Gitee