diff --git a/client/src/main/java/org/eclipse/hono/client/HonoConnection.java b/client/src/main/java/org/eclipse/hono/client/HonoConnection.java index 1e80706434..c0e7ba47a6 100644 --- a/client/src/main/java/org/eclipse/hono/client/HonoConnection.java +++ b/client/src/main/java/org/eclipse/hono/client/HonoConnection.java @@ -82,6 +82,25 @@ static HonoConnection newConnection(final Vertx vertx, final ClientConfigPropert return new HonoConnectionImpl(vertx, clientConfigProperties); } + /** + * Creates a new connection using the default implementation. + *

+ * Note: Instances of {@link ClientConfigProperties} are not thread safe and not immutable. + * They must therefore not be modified after calling this method. + * + * @param vertx The vert.x instance to use. + * @param clientConfigProperties The client properties to use. + * @param tracer The OpenTracing tracer. + * @return The newly created connection. Note that the underlying AMQP connection will not be established + * until one of its connect methods is invoked. + * @throws NullPointerException if any of the parameters is {@code null}. + */ + static HonoConnection newConnection(final Vertx vertx, final ClientConfigProperties clientConfigProperties, final Tracer tracer) { + final HonoConnectionImpl connection = new HonoConnectionImpl(vertx, clientConfigProperties); + connection.setTracer(tracer); + return connection; + } + /** * Gets the vert.x instance used by this connection. *

diff --git a/client/src/main/java/org/eclipse/hono/client/impl/AsyncCommandClientImpl.java b/client/src/main/java/org/eclipse/hono/client/impl/AsyncCommandClientImpl.java index c21fc17bfd..e72c83ede3 100644 --- a/client/src/main/java/org/eclipse/hono/client/impl/AsyncCommandClientImpl.java +++ b/client/src/main/java/org/eclipse/hono/client/impl/AsyncCommandClientImpl.java @@ -55,13 +55,9 @@ protected Future sendMessage(final Message message, final Span c @Override protected Span startSpan(final SpanContext parent, final Message message) { - if (connection.getTracer() == null) { - throw new IllegalStateException("no tracer configured"); - } else { - final Span span = newFollowingSpan(parent, "sending async command"); - Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_PRODUCER); - return span; - } + final Span span = newFollowingSpan(parent, "sending async command"); + Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_PRODUCER); + return span; } @Override diff --git a/client/src/main/java/org/eclipse/hono/client/impl/DelegatedCommandSenderImpl.java b/client/src/main/java/org/eclipse/hono/client/impl/DelegatedCommandSenderImpl.java index dcd139ee03..6925c29359 100644 --- a/client/src/main/java/org/eclipse/hono/client/impl/DelegatedCommandSenderImpl.java +++ b/client/src/main/java/org/eclipse/hono/client/impl/DelegatedCommandSenderImpl.java @@ -261,12 +261,8 @@ public static Future create( @Override protected Span startSpan(final SpanContext parent, final Message rawMessage) { - if (connection.getTracer() == null) { - throw new IllegalStateException("no tracer configured"); - } else { - final Span span = newChildSpan(parent, "delegate Command request"); - Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT); - return span; - } + final Span span = newChildSpan(parent, "delegate Command request"); + Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT); + return span; } } diff --git a/service-base-quarkus/src/main/java/org/eclipse/hono/service/quarkus/AbstractProtocolAdapterApplication.java b/service-base-quarkus/src/main/java/org/eclipse/hono/service/quarkus/AbstractProtocolAdapterApplication.java index 17290ba9db..946f5c58c4 100644 --- a/service-base-quarkus/src/main/java/org/eclipse/hono/service/quarkus/AbstractProtocolAdapterApplication.java +++ b/service-base-quarkus/src/main/java/org/eclipse/hono/service/quarkus/AbstractProtocolAdapterApplication.java @@ -166,7 +166,7 @@ protected ConnectionEventProducer connectionEventProducer() { */ protected TenantClient tenantClient() { return new ProtonBasedTenantClient( - HonoConnection.newConnection(vertx, config.tenant), + HonoConnection.newConnection(vertx, config.tenant, tracer), messageSamplerFactory, protocolAdapterProperties, newCaffeineCache(config.tenant)); @@ -179,7 +179,7 @@ protected TenantClient tenantClient() { */ protected DeviceRegistrationClient registrationClient() { return new ProtonBasedDeviceRegistrationClient( - HonoConnection.newConnection(vertx, config.registration), + HonoConnection.newConnection(vertx, config.registration, tracer), messageSamplerFactory, protocolAdapterProperties, newCaffeineCache(config.registration)); @@ -192,7 +192,7 @@ protected DeviceRegistrationClient registrationClient() { */ protected CredentialsClient credentialsClient() { return new ProtonBasedCredentialsClient( - HonoConnection.newConnection(vertx, config.credentials), + HonoConnection.newConnection(vertx, config.credentials, tracer), messageSamplerFactory, protocolAdapterProperties, newCaffeineCache(config.credentials)); @@ -205,7 +205,7 @@ protected CredentialsClient credentialsClient() { */ protected CommandRouterClient commandRouterClient() { return new ProtonBasedCommandRouterClient( - HonoConnection.newConnection(vertx, config.commandRouter), + HonoConnection.newConnection(vertx, config.commandRouter, tracer), messageSamplerFactory, protocolAdapterProperties); } @@ -217,7 +217,7 @@ protected CommandRouterClient commandRouterClient() { */ protected DeviceConnectionClient deviceConnectionClient() { return new ProtonBasedDeviceConnectionClient( - HonoConnection.newConnection(vertx, config.deviceConnection), + HonoConnection.newConnection(vertx, config.deviceConnection, tracer), messageSamplerFactory, protocolAdapterProperties); } @@ -229,7 +229,7 @@ protected DeviceConnectionClient deviceConnectionClient() { */ protected ProtonBasedDownstreamSender downstreamSender() { return new ProtonBasedDownstreamSender( - HonoConnection.newConnection(vertx, config.messaging), + HonoConnection.newConnection(vertx, config.messaging, tracer), messageSamplerFactory, protocolAdapterProperties); } @@ -240,7 +240,7 @@ protected ProtonBasedDownstreamSender downstreamSender() { * @return The connection. */ protected HonoConnection commandConsumerConnection() { - return HonoConnection.newConnection(vertx, config.command); + return HonoConnection.newConnection(vertx, config.command, tracer); } /** @@ -298,7 +298,7 @@ protected CommandTargetMapper commandTargetMapper() { */ protected CommandResponseSender commandResponseSender() { return new ProtonBasedCommandResponseSender( - HonoConnection.newConnection(vertx, config.command), + HonoConnection.newConnection(vertx, config.command, tracer), messageSamplerFactory, protocolAdapterProperties); }