/** Initializes future. */
  @SuppressWarnings({"unchecked"})
  void finish() {
    if (tx.onePhaseCommit()) {
      // No need to send messages as transaction was already committed on remote node.
      markInitialized();

      return;
    }

    if (mappings != null) {
      finish(mappings.values());

      markInitialized();

      if (!isSync()) {
        boolean complete = true;

        for (GridFuture<?> f : pending())
          // Mini-future in non-sync mode gets done when message gets sent.
          if (isMini(f) && !f.isDone()) complete = false;

        if (complete) onComplete();
      }
    } else {
      assert !commit;

      try {
        tx.rollback();
      } catch (GridException e) {
        U.error(log, "Failed to rollback empty transaction: " + tx, e);
      }

      markInitialized();
    }
  }
 /**
  * @param f Future.
  * @return {@code True} if mini-future.
  */
 private boolean isMini(GridFuture<?> f) {
   return f.getClass().equals(MiniFuture.class);
 }