From 9efec4755a1d7fd7db4a56f308064e491f30663c Mon Sep 17 00:00:00 2001 From: chenggwang <90715678+chenggwang@users.noreply.github.com> Date: Wed, 27 Sep 2023 23:21:39 +0800 Subject: [PATCH 1/2] CompletableFuture compliant scheduling tasks CompletableFuture compliant scheduling tasks --- .../org/thingsboard/mqtt/MqttHandler.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/netty-mqtt/src/main/java/org/thingsboard/mqtt/MqttHandler.java b/netty-mqtt/src/main/java/org/thingsboard/mqtt/MqttHandler.java index 21c07a17cd..5bd249ff5c 100644 --- a/netty-mqtt/src/main/java/org/thingsboard/mqtt/MqttHandler.java +++ b/netty-mqtt/src/main/java/org/thingsboard/mqtt/MqttHandler.java @@ -15,10 +15,30 @@ */ package org.thingsboard.mqtt; -import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.Future; import io.netty.buffer.ByteBuf; public interface MqttHandler { - - ListenableFuture onMessage(String topic, ByteBuf payload); + /** + * Changing ListenableFuture to Future allows you to choose CompletableFuture, + * which gives developers the freedom to choose the orchestration method. + * CompletableFuture is a newer, more evolved version that eliminates callback hell, + * is easier to use, and comes with the JDK. jdk 1.8 was previously used with the Before JDK1.8, + * use ListenableFuture, after that, it is recommended to use CompletableFuture. + * ListenableFuture It's still written that way.{@link MqttMessageListener#onMessage(topic, payload)} + * public ListenableFuture onMessage(String topic, ByteBuf message) { + * log.info("MQTT message [{}], topic [{}]", message.toString(StandardCharsets.UTF_8), topic); + * events.add(new MqttEvent(topic, message.toString(StandardCharsets.UTF_8))); + * return Futures.immediateVoidFuture(); + * } + * CompletableFuture It's like this. + * public CompletableFuture onMessage(String topic, ByteBuf message) { + * log.info("MQTT message [{}], topic [{}]", message.toString(StandardCharsets.UTF_8), topic); + * events.add(new MqttEvent(topic, message.toString(StandardCharsets.UTF_8))); + * return CompletableFuture.completedFuture(null); + * } + * This change does not affect the system's current use of ListenableFuture so that it is free to choose between ListenableFuture or + * CompletableFuture in new development. + */ + Future onMessage(String topic, ByteBuf payload); } From 189778efb9ca9fda662fb8508e5ba1f812aa64a2 Mon Sep 17 00:00:00 2001 From: ThingsBoard Bot Date: Mon, 9 Sep 2024 14:57:22 +0000 Subject: [PATCH 2/2] License header format --- .../server/queue/rabbitmq/TbRabbitMqConsumerTemplateTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/queue/src/test/java/org/thingsboard/server/queue/rabbitmq/TbRabbitMqConsumerTemplateTest.java b/common/queue/src/test/java/org/thingsboard/server/queue/rabbitmq/TbRabbitMqConsumerTemplateTest.java index ab132912fc..2d6a50cea4 100644 --- a/common/queue/src/test/java/org/thingsboard/server/queue/rabbitmq/TbRabbitMqConsumerTemplateTest.java +++ b/common/queue/src/test/java/org/thingsboard/server/queue/rabbitmq/TbRabbitMqConsumerTemplateTest.java @@ -1,5 +1,5 @@ /** - * Copyright © 2016-2023 The Thingsboard Authors + * Copyright © 2016-2024 The Thingsboard Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.