/** * Adds a handler for tidying up when a device closes the HTTP connection before * a response could be sent. * <p> * The handler will close the message consumer and increment the metric for expired TTDs. * * @param ctx The context to retrieve cookies and the HTTP response from. * @param messageConsumer The message consumer to receive a command. If {@code null}, no handler is added. * @param tenantId The tenant that the device belongs to. * @param deviceId The identifier of the device. */ private void addConnectionCloseHandler( final RoutingContext ctx, final MessageConsumer messageConsumer, final String tenantId, final String deviceId) { if (messageConsumer != null) { if (!ctx.response().closed()) { ctx.response().closeHandler(v -> { LOG.debug("device [tenant: {}, device-id: {}] closed connection before response could be sent", tenantId, deviceId); cancelCommandReceptionTimer(ctx); messageConsumer.close(null); metrics.incrementNoCommandReceivedAndTTDExpired(tenantId); }); } } }
/** * Adds a handler for tidying up when a device closes the HTTP connection before * a response could be sent. * <p> * The handler will close the message consumer and increment the metric for expired TTDs. * * @param ctx The context to retrieve cookies and the HTTP response from. * @param messageConsumer The message consumer to receive a command. If {@code null}, no handler is added. * @param tenantId The tenant that the device belongs to. * @param deviceId The identifier of the device. * @param currentSpan The <em>OpenTracing</em> Span used for tracking the processing of the request. */ private void addConnectionCloseHandler( final RoutingContext ctx, final MessageConsumer messageConsumer, final String tenantId, final String deviceId, final Span currentSpan) { if (messageConsumer != null && !ctx.response().closed()) { ctx.response().closeHandler(v -> { LOG.debug("device [tenant: {}, device-id: {}] closed connection before response could be sent", tenantId, deviceId); currentSpan.log("device closed connection"); cancelCommandReceptionTimer(ctx); messageConsumer.close(null); metrics.incrementNoCommandReceivedAndTTDExpired(tenantId); }); } }
cancelCommandReceptionTimer(ctx); responseReady.tryComplete();
cancelCommandReceptionTimer(ctx); responseReady.tryComplete();