Github user revans2 commented on a diff in the pull request: https://github.com/apache/storm/pull/1781#discussion_r88944857 --- Diff: external/storm-cassandra/src/main/java/org/apache/storm/cassandra/executor/AsyncExecutor.java --- @@ -138,6 +139,109 @@ public void onFailure(Throwable t) { } /** + * Asynchronously executes the specified select statements. Results will be passed to the {@link AsyncResultSetHandler} + * once each query has succeed or failed. + */ + public SettableFuture<List<T>> execAsync(final List<Statement> statements, final List<T> inputs, Integer maxParallelRequests, final AsyncResultSetHandler<T> handler) { + + final SettableFuture<List<T>> settableFuture = SettableFuture.create(); + final AsyncContext<T> asyncContext = new AsyncContext<>(inputs, maxParallelRequests, settableFuture); + + for (int i = 0; i < statements.size(); i++) { + + // Acquire a slot + if (asyncContext.acquire()) { + + + try { + pending.incrementAndGet(); + final int statementIndex = i; + final T input = inputs.get(i); + final Statement statement = statements.get(i); + ResultSetFuture future = session.executeAsync(statement); + Futures.addCallback(future, new FutureCallback<ResultSet>() { + @Override + public void onSuccess(ResultSet result) { + try { + handler.success(input, result); + } catch (Throwable throwable) { + asyncContext.exception(throwable); + } finally { + pending.decrementAndGet(); + asyncContext.release(); + } + } + + @Override + public void onFailure(Throwable throwable) { + handler.failure(throwable, input); + asyncContext + .exception(throwable) + .release(); + LOG.error(String.format("Failed to execute statement '%s' ", statement), throwable); --- End diff -- do we need a `pending.decrementAndGet();` here too?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---