private CheckedFuture<Void, RpcException> connect(final UserToBitHandshake handshake, final DrillbitEndpoint endpoint) { final SettableFuture<Void> connectionSettable = SettableFuture.create(); final CheckedFuture<Void, RpcException> connectionFuture = new AbstractCheckedFuture<Void, RpcException>(connectionSettable) { @Override protected RpcException mapException(Exception e) { return RpcException.mapException(e); } }; final RpcConnectionHandler<UserToBitConnection> connectionHandler = new RpcConnectionHandler<UserToBitConnection>() { @Override public void connectionSucceeded(UserToBitConnection connection) { connectionSettable.set(null); } @Override public void connectionFailed(FailureType type, Throwable t) { connectionSettable .setException(new RpcException(String.format("%s : %s", type.name(), t.getMessage()), t)); } }; connectAsClient(queryResultHandler.getWrappedConnectionHandler(connectionHandler), handshake, endpoint.getAddress(), endpoint.getUserPort()); return connectionFuture; }