diff --git a/src/main/java/com/teragrep/rlp_03/client/ClientFactory.java b/src/main/java/com/teragrep/rlp_03/client/ClientFactory.java index ed093f7c..171e6a49 100644 --- a/src/main/java/com/teragrep/rlp_03/client/ClientFactory.java +++ b/src/main/java/com/teragrep/rlp_03/client/ClientFactory.java @@ -83,13 +83,8 @@ public ClientFactory(ConnectContextFactory connectContextFactory, EventLoop even * * @param inetSocketAddress destination {@link InetSocketAddress} to connect to. * @return a {@link Client} {@link CompletableFuture}. - * @throws IOException if connection attempt fails. - * @throws InterruptedException if waiting for connection establishment is interrupted. - * @throws ExecutionException if connection establishment fails to complete successfully. - * @throws TimeoutException if connection establishment times out. */ - public CompletableFuture open(InetSocketAddress inetSocketAddress) - throws IOException, InterruptedException, ExecutionException, TimeoutException { + public CompletableFuture open(InetSocketAddress inetSocketAddress) { // this is for returning ready connection CompletableFuture readyContextFuture = new CompletableFuture<>(); Consumer establishedContextConsumer = readyContextFuture::complete; @@ -100,14 +95,14 @@ public CompletableFuture open(InetSocketAddress inetSocketAddress) try { connectContext = connectContextFactory .create(inetSocketAddress, clientDelegate, establishedContextConsumer); + LOGGER.debug("registering to eventLoop <{}>", eventLoop); + eventLoop.register(connectContext); + LOGGER.debug("registered to eventLoop <{}>", eventLoop); } catch (IOException ioException) { clientDelegate.close(); - throw ioException; + readyContextFuture.completeExceptionally(ioException); } - LOGGER.debug("registering to eventLoop <{}>", eventLoop); - eventLoop.register(connectContext); - LOGGER.debug("registered to eventLoop <{}>", eventLoop); return readyContextFuture.thenApply(clientDelegate::create); }