private Handler<ProtonConnection> getHandlerForDisconnectHonoService( final HonoClient client, final String serviceName, final Handler<HonoClient> connectHandler, final Handler<HonoClient> connectionLostHandler) { return (connection) -> { connectionLostHandler.handle(client); vertx.setTimer(Constants.DEFAULT_RECONNECT_INTERVAL_MILLIS, reconnect -> { LOG.info("attempting to reconnect to {}", serviceName); client.connect(getHandlerForDisconnectHonoService(client, serviceName, connectHandler, connectionLostHandler)).setHandler(connectAttempt -> { if (connectAttempt.succeeded()) { LOG.info("reconnected to {}", serviceName); connectHandler.handle(connectAttempt.result()); } else { LOG.debug("cannot reconnect to {}: {}", serviceName, connectAttempt.cause().getMessage()); } }); }); }; }
private Handler<ProtonConnection> getHandlerForDisconnectHonoService( final HonoClient client, final String serviceName, final Handler<HonoClient> connectHandler, final Handler<HonoClient> connectionLostHandler) { return (connection) -> { connectionLostHandler.handle(client); vertx.setTimer(Constants.DEFAULT_RECONNECT_INTERVAL_MILLIS, reconnect -> { LOG.info("attempting to reconnect to {}", serviceName); client.connect(getHandlerForDisconnectHonoService(client, serviceName, connectHandler, connectionLostHandler)).setHandler(connectAttempt -> { if (connectAttempt.succeeded()) { LOG.info("reconnected to {}", serviceName); connectHandler.handle(connectAttempt.result()); } else { LOG.debug("cannot reconnect to {}: {}", serviceName, connectAttempt.cause().getMessage()); } }); }); }; }
Objects.requireNonNull(connectionLostHandler); final Handler<ProtonConnection> disconnectHandler = getHandlerForDisconnectHonoService(client, serviceName, connectionEstablishedHandler, connectionLostHandler);
Objects.requireNonNull(connectionLostHandler); final Handler<ProtonConnection> disconnectHandler = getHandlerForDisconnectHonoService(client, serviceName, connectionEstablishedHandler, connectionLostHandler);