From 280792725bdf73c1ab9daeaf2542bbecf3a694fc Mon Sep 17 00:00:00 2001 From: skobow Date: Mon, 4 Dec 2023 14:46:58 +0100 Subject: [PATCH 1/3] Minor refactorings to improve code quality --- .../sparkplug/aware/AwareRequirements.java | 16 ++++++++++------ .../sparkplug/aware/SparkplugAwareMain.java | 4 ++-- .../SparkplugPublishInboundInterceptor.java | 4 ++-- .../SparkplugPublishOutboundInterceptor.java | 4 ++-- .../sparkplug/aware/utils/PayloadUtil.java | 13 ++++++++++--- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/hivemq/extensions/sparkplug/aware/AwareRequirements.java b/src/main/java/com/hivemq/extensions/sparkplug/aware/AwareRequirements.java index a6d2354..b01f6d3 100644 --- a/src/main/java/com/hivemq/extensions/sparkplug/aware/AwareRequirements.java +++ b/src/main/java/com/hivemq/extensions/sparkplug/aware/AwareRequirements.java @@ -15,10 +15,14 @@ */ package com.hivemq.extensions.sparkplug.aware; -public class AwareRequirements { - public final static String CONFORMANCE_MQTT_AWARE_NBIRTH_MQTT_TOPIC = "A Sparkplug Aware MQTT Server MUST make NBIRTH messages available on a topic of the form: $sparkplug/certificates/namespace/group_id/NBIRTH/edge_node_id"; - public final static String CONFORMANCE_MQTT_AWARE_NBIRTH_MQTT_RETAIN = "A Sparkplug Aware MQTT Server MUST make NBIRTH messages available on the topic: $sparkplug/certificates/namespace/group_id/NBIRTH/edge_node_id with the MQTT retain flag set to true"; - public final static String CONFORMANCE_MQTT_AWARE_DBIRTH_MQTT_TOPIC = "A Sparkplug Aware MQTT Server MUST make DBIRTH messages available on a topic of the form: $sparkplug/certificates/namespace/group_id/DBIRTH/edge_node_id/device_id"; - public final static String CONFORMANCE_MQTT_AWARE_DBIRTH_MQTT_RETAIN = "A Sparkplug Aware MQTT Server MUST make DBIRTH messages available on the topic: $sparkplug/certificates/namespace/group_id/DBIRTH/edge_node_id/device_id with the MQTT retain flag set to true"; - public final static String CONFORMANCE_MQTT_AWARE_NDEATH_TIMESTAMP = "A Sparkplug Aware MQTT Server MAY replace the timestamp of NDEATH messages. If it does, it MUST set the timestamp to the UTC time at which it attempts to deliver the NDEATH to subscribed clients"; +public final class AwareRequirements { + + AwareRequirements() { + } + + public static final String CONFORMANCE_MQTT_AWARE_NBIRTH_MQTT_TOPIC = "A Sparkplug Aware MQTT Server MUST make NBIRTH messages available on a topic of the form: $sparkplug/certificates/namespace/group_id/NBIRTH/edge_node_id"; + public static final String CONFORMANCE_MQTT_AWARE_NBIRTH_MQTT_RETAIN = "A Sparkplug Aware MQTT Server MUST make NBIRTH messages available on the topic: $sparkplug/certificates/namespace/group_id/NBIRTH/edge_node_id with the MQTT retain flag set to true"; + public static final String CONFORMANCE_MQTT_AWARE_DBIRTH_MQTT_TOPIC = "A Sparkplug Aware MQTT Server MUST make DBIRTH messages available on a topic of the form: $sparkplug/certificates/namespace/group_id/DBIRTH/edge_node_id/device_id"; + public static final String CONFORMANCE_MQTT_AWARE_DBIRTH_MQTT_RETAIN = "A Sparkplug Aware MQTT Server MUST make DBIRTH messages available on the topic: $sparkplug/certificates/namespace/group_id/DBIRTH/edge_node_id/device_id with the MQTT retain flag set to true"; + public static final String CONFORMANCE_MQTT_AWARE_NDEATH_TIMESTAMP = "A Sparkplug Aware MQTT Server MAY replace the timestamp of NDEATH messages. If it does, it MUST set the timestamp to the UTC time at which it attempts to deliver the NDEATH to subscribed clients"; } diff --git a/src/main/java/com/hivemq/extensions/sparkplug/aware/SparkplugAwareMain.java b/src/main/java/com/hivemq/extensions/sparkplug/aware/SparkplugAwareMain.java index ea2b5d1..c3cf219 100644 --- a/src/main/java/com/hivemq/extensions/sparkplug/aware/SparkplugAwareMain.java +++ b/src/main/java/com/hivemq/extensions/sparkplug/aware/SparkplugAwareMain.java @@ -55,7 +55,7 @@ public void extensionStart( addPublishModifier(); final ExtensionInformation extensionInformation = extensionStartInput.getExtensionInformation(); - log.info("Started " + extensionInformation.getName() + ":" + extensionInformation.getVersion()); + log.info("Started {}:{}", extensionInformation.getName(), extensionInformation.getVersion()); log.debug("Add Awareness: {} ", AwareRequirements.CONFORMANCE_MQTT_AWARE_DBIRTH_MQTT_TOPIC); log.debug("Add Awareness: {} ", AwareRequirements.CONFORMANCE_MQTT_AWARE_DBIRTH_MQTT_RETAIN); @@ -75,7 +75,7 @@ public void extensionStop( final @NotNull ExtensionStopOutput extensionStopOutput) { final ExtensionInformation extensionInformation = extensionStopInput.getExtensionInformation(); - log.info("Stopped " + extensionInformation.getName() + ":" + extensionInformation.getVersion()); + log.info("Stopped {}:{}", extensionInformation.getName(), extensionInformation.getVersion()); } private void addPublishModifier() { diff --git a/src/main/java/com/hivemq/extensions/sparkplug/aware/SparkplugPublishInboundInterceptor.java b/src/main/java/com/hivemq/extensions/sparkplug/aware/SparkplugPublishInboundInterceptor.java index 5aec7e0..84bfb0b 100644 --- a/src/main/java/com/hivemq/extensions/sparkplug/aware/SparkplugPublishInboundInterceptor.java +++ b/src/main/java/com/hivemq/extensions/sparkplug/aware/SparkplugPublishInboundInterceptor.java @@ -49,8 +49,8 @@ public class SparkplugPublishInboundInterceptor implements PublishInboundInterce private final PublishService publishService; private final @NotNull String sparkplugVersion; private final @NotNull String sysTopic; - private final Boolean useCompression; - private final Boolean jsonLogEnabled; + private final boolean useCompression; + private final boolean jsonLogEnabled; private final Long messageExpiry; public SparkplugPublishInboundInterceptor(final @NotNull SparkplugConfiguration configuration, diff --git a/src/main/java/com/hivemq/extensions/sparkplug/aware/SparkplugPublishOutboundInterceptor.java b/src/main/java/com/hivemq/extensions/sparkplug/aware/SparkplugPublishOutboundInterceptor.java index 71770e8..ef25959 100644 --- a/src/main/java/com/hivemq/extensions/sparkplug/aware/SparkplugPublishOutboundInterceptor.java +++ b/src/main/java/com/hivemq/extensions/sparkplug/aware/SparkplugPublishOutboundInterceptor.java @@ -44,8 +44,8 @@ public class SparkplugPublishOutboundInterceptor implements PublishOutboundInter private static final CompressionAlgorithm compressionAlgorithm = CompressionAlgorithm.GZIP; private final @NotNull String sparkplugVersion; - private final Boolean useCompression; - private final Boolean jsonLogEnabled; + private final boolean useCompression; + private final boolean jsonLogEnabled; public SparkplugPublishOutboundInterceptor(final @NotNull SparkplugConfiguration configuration) { this.sparkplugVersion = configuration.getSparkplugVersion(); diff --git a/src/main/java/com/hivemq/extensions/sparkplug/aware/utils/PayloadUtil.java b/src/main/java/com/hivemq/extensions/sparkplug/aware/utils/PayloadUtil.java index d944f58..d3c17dc 100644 --- a/src/main/java/com/hivemq/extensions/sparkplug/aware/utils/PayloadUtil.java +++ b/src/main/java/com/hivemq/extensions/sparkplug/aware/utils/PayloadUtil.java @@ -33,13 +33,20 @@ import java.nio.ByteBuffer; import java.util.Date; -public class PayloadUtil { +public final class PayloadUtil { private static final @NotNull Logger log = LoggerFactory.getLogger(PayloadUtil.class); private static final @NotNull Logger jsonLog = LoggerFactory.getLogger("com.hivemq.extensions.sparkplug.jsonLog"); private static final CompressionAlgorithm compressionAlgorithm = CompressionAlgorithm.GZIP; - public static ByteBuffer modifySparkplugTimestamp(Boolean useCompression, ByteBuffer byteBuffer) throws Exception { - SparkplugBPayload inboundPayload = getSparkplugBPayload(byteBuffer); + PayloadUtil(){ + } + + public static ByteBuffer modifySparkplugTimestamp(boolean useCompression, ByteBuffer byteBuffer) throws Exception { + final SparkplugBPayload inboundPayload = getSparkplugBPayload(byteBuffer); + if (inboundPayload == null) { + throw new IllegalArgumentException("Unable to get Sparkplug B Payload from byte buffer."); + } + //create the same payload with a new timestamp. SparkplugBPayload payload = new SparkplugBPayload(new Date(), From 14c8128f6a0d29fa5885cb04c8f4bdc9a78d16ed Mon Sep 17 00:00:00 2001 From: skobow Date: Mon, 4 Dec 2023 14:47:35 +0100 Subject: [PATCH 2/3] Remove production use disclaimer --- README.adoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.adoc b/README.adoc index 2acb17b..a612341 100644 --- a/README.adoc +++ b/README.adoc @@ -13,8 +13,6 @@ image:https://img.shields.io/github/v/release/hivemq/hivemq-sparkplug-aware-exte image:https://img.shields.io/github/license/hivemq/hivemq-sparkplug-aware-extension?style=for-the-badge&color=brightgreen[GitHub,link=LICENSE] image:https://img.shields.io/github/actions/workflow/status/hivemq/hivemq-sparkplug-aware-extension/check.yml?branch=master&style=for-the-badge[GitHub Workflow Status,link=https://github.com/hivemq/hivemq-sparkplug-aware-extension/actions/workflows/check.yml?query=branch%3Amaster] -*This extension is not yet ready for production use.* - == Purpose This HiveMQ Sparkplug aware extension has the purpose to fulfil the new link:https://github.com/eclipse/sparkplug[Sparkplug Release] of the Sparkplug specification extend HiveMQ with the functionality of a Sparkplug Aware Broker wich is an optional Requirement. From 9433c7e7a4b68bad978fac9e257c4bb69b4ec61a Mon Sep 17 00:00:00 2001 From: skobow Date: Mon, 4 Dec 2023 14:47:52 +0100 Subject: [PATCH 3/3] Update extension sdk version --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 963143f..33bfa25 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] commonsLang = "3.8.1" guava = "31.1-jre" -hivemq-extensionSdk = "4.9.1" +hivemq-extensionSdk = "4.22.0" jackson = "2.13.2" jacksonv1 = "1.9.13" jetbrains-annotations = "24.0.1"