diff --git a/src/main/java/software/amazon/awssdk/crt/mqtt/MqttClientConnection.java b/src/main/java/software/amazon/awssdk/crt/mqtt/MqttClientConnection.java index fab5fb87e..990a6f3f9 100644 --- a/src/main/java/software/amazon/awssdk/crt/mqtt/MqttClientConnection.java +++ b/src/main/java/software/amazon/awssdk/crt/mqtt/MqttClientConnection.java @@ -8,12 +8,10 @@ import software.amazon.awssdk.crt.AsyncCallback; import software.amazon.awssdk.crt.CrtResource; import software.amazon.awssdk.crt.CrtRuntimeException; -import software.amazon.awssdk.crt.http.HttpHeader; import software.amazon.awssdk.crt.http.HttpProxyOptions; import software.amazon.awssdk.crt.http.HttpRequest; import software.amazon.awssdk.crt.io.SocketOptions; import software.amazon.awssdk.crt.io.TlsContext; -import software.amazon.awssdk.crt.mqtt.MqttConnectionConfig; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; @@ -25,7 +23,8 @@ * MqttClientConnection represents a single connection from one MqttClient to an * MQTT service endpoint */ -public class MqttClientConnection extends CrtResource { +public class MqttClientConnection extends CrtResource implements MqttPublishInterface, MqttSubscribeHandlerInterface, + MqttSubscribeInterface { private MqttConnectionConfig config; @@ -51,7 +50,7 @@ void deliver(String topic, byte[] payload) { /** * Constructs a new MqttClientConnection. Connections are reusable after being * disconnected. - * + * * @param config Configuration to use * @throws MqttException If mqttClient is null */ @@ -209,14 +208,7 @@ public CompletableFuture disconnect() { } /** - * Subscribes to a topic - * - * @param topic The topic to subscribe to - * @param qos {@link QualityOfService} for this subscription - * @param handler A handler which can recieve an MqttMessage when a message is - * published to the topic - * @return Future result is the packet/message id associated with the subscribe - * operation + * {@inheritDoc} */ public CompletableFuture subscribe(String topic, QualityOfService qos, Consumer handler) { CompletableFuture future = new CompletableFuture<>(); @@ -238,13 +230,7 @@ public CompletableFuture subscribe(String topic, QualityOfService qos, } /** - * Subscribes to a topic without a handler (messages will only be delivered to - * the OnMessage handler) - * - * @param topic The topic to subscribe to - * @param qos {@link QualityOfService} for this subscription - * @return Future result is the packet/message id associated with the subscribe - * operation + * {@inheritDoc} */ public CompletableFuture subscribe(String topic, QualityOfService qos) { return subscribe(topic, qos, null); @@ -280,15 +266,7 @@ public CompletableFuture unsubscribe(String topic) { } /** - * Publishes a message to a topic - * - * @param message The message to publish. The message contains the topic to - * publish to. - * @param qos The {@link QualityOfService} to use for the publish operation - * @param retain Whether or not the message should be retained by the broker to - * be delivered to future subscribers - * @return Future value is the packet/message id associated with the publish - * operation + * {@inheritDoc} */ public CompletableFuture publish(MqttMessage message, QualityOfService qos, boolean retain) { CompletableFuture future = new CompletableFuture<>(); diff --git a/src/main/java/software/amazon/awssdk/crt/mqtt/MqttPublishInterface.java b/src/main/java/software/amazon/awssdk/crt/mqtt/MqttPublishInterface.java new file mode 100644 index 000000000..64a41538e --- /dev/null +++ b/src/main/java/software/amazon/awssdk/crt/mqtt/MqttPublishInterface.java @@ -0,0 +1,23 @@ +/* + * Copyright Amazon.com Inc. or its affiliates. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.awssdk.crt.mqtt; + +import java.util.concurrent.CompletableFuture; + +public interface MqttPublishInterface { + /** + * Publishes a message to a topic + * + * @param message The message to publish. The message contains the topic to + * publish to. + * @param qos The {@link QualityOfService} to use for the publish operation + * @param retain Whether or not the message should be retained by the broker to + * be delivered to future subscribers + * @return Future value is the packet/message id associated with the publish + * operation + */ + CompletableFuture publish(MqttMessage message, QualityOfService qos, boolean retain); +} diff --git a/src/main/java/software/amazon/awssdk/crt/mqtt/MqttSubscribeHandlerInterface.java b/src/main/java/software/amazon/awssdk/crt/mqtt/MqttSubscribeHandlerInterface.java new file mode 100644 index 000000000..e12f24393 --- /dev/null +++ b/src/main/java/software/amazon/awssdk/crt/mqtt/MqttSubscribeHandlerInterface.java @@ -0,0 +1,23 @@ +/* + * Copyright Amazon.com Inc. or its affiliates. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.awssdk.crt.mqtt; + +import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; + +public interface MqttSubscribeHandlerInterface { + /** + * Subscribes to a topic + * + * @param topic The topic to subscribe to + * @param qos {@link QualityOfService} for this subscription + * @param handler A handler which can receive an MqttMessage when a message is + * published to the topic + * @return Future result is the packet/message id associated with the subscribe + * operation + */ + CompletableFuture subscribe(String topic, QualityOfService qos, Consumer handler); +} diff --git a/src/main/java/software/amazon/awssdk/crt/mqtt/MqttSubscribeInterface.java b/src/main/java/software/amazon/awssdk/crt/mqtt/MqttSubscribeInterface.java new file mode 100644 index 000000000..7d45ac03d --- /dev/null +++ b/src/main/java/software/amazon/awssdk/crt/mqtt/MqttSubscribeInterface.java @@ -0,0 +1,21 @@ +/* + * Copyright Amazon.com Inc. or its affiliates. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.awssdk.crt.mqtt; + +import java.util.concurrent.CompletableFuture; + +public interface MqttSubscribeInterface { + /** + * Subscribes to a topic without a handler (messages will only be delivered to + * the OnMessage handler) + * + * @param topic The topic to subscribe to + * @param qos {@link QualityOfService} for this subscription + * @return Future result is the packet/message id associated with the subscribe + * operation + */ + CompletableFuture subscribe(String topic, QualityOfService qos); +}