Start a reactive dataflow from a stream of CompletableFutures.

@param stream of CompletableFutures that will be used to drive the reactive dataflow
@return Next stage in the reactive flow
496707
public <U> BaseSimpleReactStream<U> fromStream(final Stream<CompletableFuture<U>> stream) {

        final Stream s = stream;
        return construct(s);
    }
1192982
@Override
    public CompletableFuture<T> newIncompleteFuture() {
        if (JAVA8)
            return new ManagedCompletionStage<T>(new CompletableFuture<T>(), defaultExecutor, null);
        else
            return new ManagedCompletionStage<T>(defaultExecutor);
    }
43262
public ReactiveTask requestAsync(final long n) {
        return withSubscriptionAndTask(subscriptionAndTask.map2(c -> CompletableFuture.runAsync(() -> subscriptionAndTask._1().join()
                                                                                                                            .request(n),
                                                                                                exec)));
    }
261735
private CompletableFuture<Void> commitTransactions(String scope, String stream, List<Long> segments,
                                                                     List<UUID> transactionsToCommit) {
        // Chain all transaction commit futures one after the other. This will ensure that order of commit
        // if honoured and is based on the order in the list.
        CompletableFuture<Void> future = CompletableFuture.completedFuture(null);
        for (UUID txnId : transactionsToCommit) {
            log.debug("Committing transaction {} on stream {}/{}", txnId, scope, stream);
            // commit transaction in segment store
            future = future
                    // Note, we can use the same segments and transaction id as only
                    // primary id is taken for creation of txn-segment name and secondary part is erased and replaced with
                    // transaction's epoch.
                    // And we are creating duplicates of txn epoch keeping the primary same.
                    .thenCompose(v -> streamMetadataTasks.notifyTxnCommit(scope, stream, segments, txnId));
        }
        return future;
    }
584480
private <R, U> CompletionStage<U> doApplyToEitherAsync(
            CompletionStage<? extends R> first,
            CompletionStage<? extends R> second,
            Function<? super R, U> fn,
            Executor executor) {
    	CompletableCompletionStage<R> nextStage = newCompletableCompletionStage();

        // only the first result is accepted by completion stage,
        // the other one is ignored
        BiConsumer<R, Throwable> action = completeHandler(nextStage);
        first.whenComplete(action);
        second.whenComplete(action);

        return nextStage.thenApplyAsync(fn, executor);
    }
708802
@Override
    public Future<M> getDataFuture() {
        try {
            return FutureProcessor.completedFuture(getData());
        } catch (NotAvailableException ex) {
            CompletableFuture future = new CompletableFuture();
            future.completeExceptionally(ex);
            return future;
        }
    }
90112
@NotNull
  public CompletableFuture<Meta> upload(@NotNull final StreamProvider streamProvider) {
    final CompletableFuture<Meta> future = new CompletableFuture<>();
    getPool().submit(() -> {
      try {
        future.complete(Client.generateMeta(streamProvider));
      } catch (Throwable e) {
        future.completeExceptionally(e);
      }
    });
    return future.thenCompose(meta -> upload(meta, streamProvider));
  }
1189459
@Override
    public CompletableFuture<List<Map.Entry<UUID, Long>>> getNext() {
        return this.indexIterator
                .getNext()
                .thenApply(this::mix);
    }
541825
CompletableFuture<ClientConnection> getConnection() throws SegmentSealedException {
        if (state.isClosed()) {
            throw new IllegalStateException("SegmentOutputStream is already closed", state.getException());
        }
        if (state.isAlreadySealed()) {
            throw new SegmentSealedException(this.segmentName);
        }
        if (state.getConnection() == null) {
            reconnect();
        }
        CompletableFuture<ClientConnection> future =  new CompletableFuture<>();
        state.setupConnection.register(future);
        return future;
    }
1101966
private CompletableFuture<Void> listen() {
    CompletableFuture<Void> future = new CompletableFuture<>();
    context.getThreadContext().executor().execute(() -> {
      internalServer.listen(cluster().member().serverAddress(), context::connectServer).whenComplete((internalResult, internalError) -> {
        if (internalError == null) {
          // If the client address is different than the server address, start a separate client server.
          if (clientServer != null) {
            clientServer.listen(cluster().member().clientAddress(), context::connectClient).whenComplete((clientResult, clientError) -> {
              started = true;
              future.complete(null);
            });
          } else {
            started = true;
            future.complete(null);
          }
        } else {
          future.completeExceptionally(internalError);
        }
      });
    });

    return future;
  }
1357233
public static CompletableFuture<Void> runAsync(Runnable runnable,
            Consumer<Throwable> failureConsumer, Executor executor) {
        return CompletableFuture.runAsync(runnable, executor)
                .exceptionally(e -> {
                    ifNotNull(failureConsumer, c -> c.accept(e));
                    return (Void) new Object();
                });
    }
163079
private CompletableFuture<Void> copyTxnEpochSegmentsAndCommitTxns(String scope, String stream, List<UUID> transactionsToCommit,
                                                                      List<Long> segmentIds) {
        // 1. create duplicate segments
        // 2. merge transactions in those segments
        // 3. seal txn epoch segments
        String delegationToken = streamMetadataTasks.retrieveDelegationToken();
        CompletableFuture<Void> createSegmentsFuture = Futures.allOf(segmentIds.stream().map(segment -> {
            // Use fixed scaling policy for these segments as they are created, merged into and sealed and are not
            // supposed to auto scale.
            return streamMetadataTasks.notifyNewSegment(scope, stream, segment, ScalingPolicy.fixed(1), delegationToken);
        }).collect(Collectors.toList()));

        return createSegmentsFuture
                .thenCompose(v -> {
                    log.debug("Rolling transaction, successfully created duplicate txn epoch {} for stream {}/{}", segmentIds, scope, stream);
                    // now commit transactions into these newly created segments
                    return commitTransactions(scope, stream, segmentIds, transactionsToCommit);
                })
                .thenCompose(v -> streamMetadataTasks.notifySealedSegments(scope, stream, segmentIds, delegationToken));
    }
447973
@SuppressWarnings("unchecked")
  public CompletableFuture<A> connect() {
    return registry.createPrimitive(name(), type())
        .thenApply(v -> (A) this);
  }
1011120
public JMProgressiveManager<T, R> start() {
		info(log, "start");
		this.completableFuture = JMThread
				.runAsync(() -> targetCollection.stream()
						.filter(negate(isStopped())).map(this::moveNextTarget)
						.map(t -> JMMap.putGetNew(resultMap, t, process(t)))
						.forEach(lastResult::set))
				.thenRun(this::setStopped)
				.thenRun(() -> Optional.ofNullable(completedConsumerList)
						.ifPresent(list -> list.parallelStream()
								.forEach(c -> c.accept(this))));
		return this;
	}
547339
public static <T> CompletableFuture<T> toCompletableFuture(ApiFuture<T> apiFuture) {
        return Java8FutureUtils.createCompletableFuture(ApiFutureUtils.createValueSourceFuture(apiFuture));
    }
730479
@Override
    public DataStreamingEvent<E> next() throws DataSourceReadException {
        lockChain();
        updateCurrentIterator();
        lastUsedIterator = currentIterator;
        return currentIterator.next();
    }
187519
public static <T> FlowableTransformer<T,T> doOnTerminateFx(Action onTerminate) {
        return obs -> obs.doOnTerminate(() -> runOnFx(onTerminate));
    }