- Collection<CanCommit> messages = registry.createCanCommitMessages(txId, tip, schema);
- // FIXME: Optimize empty collection list with pre-created futures, containing success.
- Future<Iterable<Object>> canCommitsFuture = Futures.traverse(messages,
- input -> Patterns.ask(input.getCohort(), input, timeout).recover(EXCEPTION_TO_MESSAGE,
- ExecutionContexts.global()), ExecutionContexts.global());
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("{}: canCommit - candidate: {}", txId, tip);
+ } else {
+ LOG.debug("{}: canCommit - candidate rootPath: {}", txId, tip.getRootPath());
+ }
+
+ final List<CanCommit> messages = registry.createCanCommitMessages(txId, tip, schema);
+ LOG.debug("{}: canCommit - messages: {}", txId, messages);
+ if (messages.isEmpty()) {
+ successfulFromPrevious = ImmutableList.of();
+ changeStateFrom(State.IDLE, State.CAN_COMMIT_SUCCESSFUL);
+ return;
+ }
+
+ final List<Entry<ActorRef, Future<Object>>> futures = new ArrayList<>(messages.size());
+ for (CanCommit message : messages) {
+ final ActorRef actor = message.getCohort();
+ final Future<Object> future = Patterns.ask(actor, message, timeout).recover(EXCEPTION_TO_MESSAGE,
+ ExecutionContexts.global());
+ LOG.trace("{}: requesting canCommit from {}", txId, actor);
+ futures.add(new SimpleImmutableEntry<>(actor, future));
+ }
+