diff --git a/clients/application-amqp/src/main/java/org/eclipse/hono/application/client/amqp/AmqpApplicationClientFactory.java b/clients/application-amqp/src/main/java/org/eclipse/hono/application/client/amqp/AmqpApplicationClientFactory.java index 817e6ed66a..7d620bfc0b 100644 --- a/clients/application-amqp/src/main/java/org/eclipse/hono/application/client/amqp/AmqpApplicationClientFactory.java +++ b/clients/application-amqp/src/main/java/org/eclipse/hono/application/client/amqp/AmqpApplicationClientFactory.java @@ -13,58 +13,11 @@ package org.eclipse.hono.application.client.amqp; -import java.util.function.Consumer; - import org.eclipse.hono.application.client.ApplicationClientFactory; -import org.eclipse.hono.application.client.DownstreamMessage; -import org.eclipse.hono.application.client.MessageConsumer; - -import io.vertx.core.Future; -import io.vertx.core.Handler; +import org.eclipse.hono.util.Lifecycle; /** * A factory for creating clients for Hono's AMQP-based northbound APIs. */ -public interface AmqpApplicationClientFactory extends ApplicationClientFactory { - - /** - * Creates a client for consuming data from Hono's northbound Telemetry API. - * - * @param tenantId The tenant to consume data for. - * @param telemetryConsumer The handler to invoke with every message received. - * @param autoAccept {@code true} if received deliveries should be automatically accepted (and settled) after the - * message handler runs for them, if no other disposition has been applied during handling. NOTE: When - * using {@code false} here, make sure that deliveries (from {@link AmqpMessageContext#getDelivery()}) - * are quickly updated and settled, so that the messages don't remain in flight for long. - * @param closeHandler The handler invoked when the peer detaches the link. - * @return A future that will complete with the consumer once the link has been established. The future will fail if - * the link cannot be established, e.g. because this factory is not connected. - * @throws NullPointerException if any of the parameters is {@code null}. - */ - Future> createTelemetryConsumer( - String tenantId, - Consumer telemetryConsumer, - boolean autoAccept, - Handler closeHandler); - - /** - * Creates a client for consuming events from Hono's northbound Event API. - * - * @param tenantId The tenant to consume data for. - * @param eventConsumer The handler to invoke with every message received. - * @param autoAccept {@code true} if received deliveries should be automatically accepted (and settled) after the - * message handler runs for them, if no other disposition has been applied during handling. NOTE: When - * using {@code false} here, make sure that deliveries (from {@link AmqpMessageContext#getDelivery()}) - * are quickly updated and settled, so that the messages don't remain in flight for long. - * @param closeHandler The handler invoked when the peer detaches the link. - * @return A future that will complete with the consumer once the link has been established. The future will fail if - * the link cannot be established, e.g. because this factory is not connected. - * @throws NullPointerException if any of the parameters is {@code null}. - */ - Future> createEventConsumer( - String tenantId, - Consumer eventConsumer, - boolean autoAccept, - Handler closeHandler); - +public interface AmqpApplicationClientFactory extends ApplicationClientFactory, Lifecycle { } diff --git a/clients/application-kafka/src/main/java/org/eclipse/hono/application/client/kafka/KafkaApplicationClientFactory.java b/clients/application-kafka/src/main/java/org/eclipse/hono/application/client/kafka/KafkaApplicationClientFactory.java index b3669cd29e..70de934762 100644 --- a/clients/application-kafka/src/main/java/org/eclipse/hono/application/client/kafka/KafkaApplicationClientFactory.java +++ b/clients/application-kafka/src/main/java/org/eclipse/hono/application/client/kafka/KafkaApplicationClientFactory.java @@ -18,6 +18,6 @@ /** * A factory for creating clients for Hono's Kafka-based northbound APIs. */ -public interface KafkaApplicationClientFactory extends ApplicationClientFactory { +public interface KafkaApplicationClientFactory extends ApplicationClientFactory { } diff --git a/clients/application/src/main/java/org/eclipse/hono/application/client/ApplicationClientFactory.java b/clients/application/src/main/java/org/eclipse/hono/application/client/ApplicationClientFactory.java index 2b000f148e..6533c1a6d1 100644 --- a/clients/application/src/main/java/org/eclipse/hono/application/client/ApplicationClientFactory.java +++ b/clients/application/src/main/java/org/eclipse/hono/application/client/ApplicationClientFactory.java @@ -19,12 +19,14 @@ import io.vertx.core.Handler; /** - * A factory for creating clients for Hono's northbound APIs. + * A factory for creating clients for Hono's north bound APIs. + * + * @param The type of context that messages are being received in. */ -public interface ApplicationClientFactory { +public interface ApplicationClientFactory { /** - * Creates a client for consuming data from Hono's northbound Telemetry API. + * Creates a client for consuming data from Hono's north bound Telemetry API. *

* The messages passed in to the consumer will be acknowledged automatically if the consumer does not throw an * exception. @@ -38,9 +40,9 @@ public interface ApplicationClientFactory { * cannot be started. * @throws NullPointerException if any of the parameters is {@code null}. */ - Future> createTelemetryConsumer( + Future>> createTelemetryConsumer( String tenantId, - Consumer telemetryConsumer, + Consumer> telemetryConsumer, Handler closeHandler); /** @@ -58,9 +60,9 @@ Future> createTelemetryConsumer( * cannot be started. * @throws NullPointerException if any of the parameters is {@code null}. */ - Future> createEventConsumer( + Future>> createEventConsumer( String tenantId, - Consumer eventConsumer, + Consumer> eventConsumer, Handler closeHandler); // TODO add methods for command & control diff --git a/clients/application/src/main/java/org/eclipse/hono/application/client/DownstreamMessage.java b/clients/application/src/main/java/org/eclipse/hono/application/client/DownstreamMessage.java index 3bdd855ba4..c327d7096c 100644 --- a/clients/application/src/main/java/org/eclipse/hono/application/client/DownstreamMessage.java +++ b/clients/application/src/main/java/org/eclipse/hono/application/client/DownstreamMessage.java @@ -18,9 +18,12 @@ import io.vertx.core.buffer.Buffer; /** - * A message of Hono's northbound APIs, flowing from the messaging system to the backend application. + * A message being delivered to an application via Hono's north bound APIs. + * + * @param The type of context that the message is being received in. */ -public interface DownstreamMessage extends Message { +public interface DownstreamMessage extends Message { + /** * Gets the tenant that sent the message. * @@ -50,13 +53,7 @@ public interface DownstreamMessage extends Message { String getContentType(); /** - * {@inheritDoc} - */ - @Override - MessageContext getMessageContext(); - - /** - * Gets the quality of service level that the device requested. + * Gets the quality-of-service level used by the device that this message originates from. * * @return The QoS. */ diff --git a/clients/application/src/main/java/org/eclipse/hono/application/client/DownstreamMessageImpl.java b/clients/application/src/main/java/org/eclipse/hono/application/client/DownstreamMessageImpl.java index a72130edbc..e93d9e3061 100644 --- a/clients/application/src/main/java/org/eclipse/hono/application/client/DownstreamMessageImpl.java +++ b/clients/application/src/main/java/org/eclipse/hono/application/client/DownstreamMessageImpl.java @@ -20,15 +20,17 @@ import io.vertx.core.buffer.Buffer; /** - * A downstream message of Hono's northbound APIs. + * A downstream message of Hono's north bound APIs. + * + * @param The type of context that the message is being received in. */ -public class DownstreamMessageImpl implements DownstreamMessage { +public class DownstreamMessageImpl implements DownstreamMessage { private final String tenantId; private final String deviceId; private final MessageProperties properties; private final String contentType; - private final MessageContext messageContext; + private final T messageContext; private final QoS qos; private final Buffer payload; @@ -45,7 +47,7 @@ public class DownstreamMessageImpl implements DownstreamMessage { * @throws NullPointerException if any of the parameters, except payload, is {@code null}. */ public DownstreamMessageImpl(final String tenantId, final String deviceId, final MessageProperties properties, - final String contentType, final MessageContext messageContext, final QoS qos, final Buffer payload) { + final String contentType, final T messageContext, final QoS qos, final Buffer payload) { Objects.requireNonNull(tenantId); Objects.requireNonNull(deviceId); @@ -84,7 +86,7 @@ public final String getContentType() { } @Override - public final MessageContext getMessageContext() { + public final T getMessageContext() { return messageContext; } diff --git a/clients/application/src/main/java/org/eclipse/hono/application/client/Message.java b/clients/application/src/main/java/org/eclipse/hono/application/client/Message.java index ba5c00276d..5ac9bb00f7 100644 --- a/clients/application/src/main/java/org/eclipse/hono/application/client/Message.java +++ b/clients/application/src/main/java/org/eclipse/hono/application/client/Message.java @@ -14,15 +14,16 @@ package org.eclipse.hono.application.client; /** - * A message of Hono's northbound APIs, exchanged between the messaging system and the backend application. + * A message of Hono's north bound APIs, exchanged between the messaging system and the back end application. + * + * @param The type of context that the message is being received in. */ -public interface Message { +public interface Message { /** * Gets the message context which is specific for the messaging system in use. * * @return The context. */ - MessageContext getMessageContext(); - + T getMessageContext(); } diff --git a/clients/application/src/main/java/org/eclipse/hono/application/client/MessageConsumer.java b/clients/application/src/main/java/org/eclipse/hono/application/client/MessageConsumer.java index 5daa41b3c3..0b3d03b996 100644 --- a/clients/application/src/main/java/org/eclipse/hono/application/client/MessageConsumer.java +++ b/clients/application/src/main/java/org/eclipse/hono/application/client/MessageConsumer.java @@ -20,7 +20,7 @@ * * @param The type of messages consumed by this client. */ -public interface MessageConsumer { +public interface MessageConsumer> { /** * Closes the client.