Java Code Examples for org.eclipse.microprofile.reactive.streams.operators.spi.SubscriberWithCompletionStage

The following examples show how to use org.eclipse.microprofile.reactive.streams.operators.spi.SubscriberWithCompletionStage. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: smallrye-mutiny   Source File: Engine.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public <T, R> SubscriberWithCompletionStage<T, R> buildSubscriber(Graph graph) {
    Processor<T, T> processor = new ConnectableProcessor<>();
    Multi<T> flowable = Multi.createFrom().publisher(processor);
    for (Stage stage : graph.getStages()) {
        Operator operator = Stages.lookup(stage);
        if (operator instanceof ProcessorOperator) {
            flowable = applyProcessors(flowable, stage, (ProcessorOperator) operator);
        } else if (operator instanceof TerminalOperator) {
            CompletionStage<R> result = applySubscriber(Transformer.apply(flowable), stage,
                    (TerminalOperator) operator);
            return new DefaultSubscriberWithCompletionStage<>(processor, result);
        } else {
            throw new UnsupportedStageException(stage);
        }
    }

    throw new IllegalArgumentException("The graph does not have a valid final stage");
}
 
Example 2
@Override
public <T, R> SubscriberWithCompletionStage<T, R> buildSubscriber(Graph graph) {
    Processor<T, T> processor = new ConnectableProcessor<>();
    Flowable<T> flowable = Flowable.fromPublisher(processor);
    for (Stage stage : graph.getStages()) {
        Operator operator = Stages.lookup(stage);
        if (operator instanceof ProcessorOperator) {
            flowable = applyProcessors(flowable, stage, (ProcessorOperator) operator);
        } else if (operator instanceof TerminalOperator) {
            CompletionStage<R> result = applySubscriber(Transformer.apply(flowable), stage,
                    (TerminalOperator) operator);
            return new DefaultSubscriberWithCompletionStage<>(processor, result);
        } else {
            throw new UnsupportedStageException(stage);
        }
    }

    throw new IllegalArgumentException("The graph does not have a valid final stage");
}
 
Example 3
Source Project: smallrye-mutiny   Source File: CoupledStageFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <I, O> ProcessingStage<I, O> create(Engine engine, Stage.Coupled stage) {
    Graph source = Objects.requireNonNull(stage.getPublisher());
    Graph sink = Objects.requireNonNull(stage.getSubscriber());

    Publisher<O> publisher = engine.buildPublisher(source);
    SubscriberWithCompletionStage<I, ?> subscriber = engine.buildSubscriber(sink);

    return upstream -> Multi.createFrom().publisher(
            new CouplingProcessor<>(upstream, subscriber.getSubscriber(), publisher));
}
 
Example 4
@Override
public <I, O> ProcessingStage<I, O> create(Engine engine, Stage.Coupled stage) {
    Graph source = Objects.requireNonNull(stage.getPublisher());
    Graph sink = Objects.requireNonNull(stage.getSubscriber());

    Publisher<O> publisher = engine.buildPublisher(source);
    SubscriberWithCompletionStage<I, ?> subscriber = engine.buildSubscriber(sink);

    return upstream -> Flowable.fromPublisher(
            new CouplingProcessor<>(upstream, subscriber.getSubscriber(), publisher));
}
 
Example 5
@Override
public CompletionSubscriber<T, R> build(ReactiveStreamsEngine engine) {
    Objects.requireNonNull(engine, "Engine must not be null");
    SubscriberWithCompletionStage<T, R> subscriberWithCompletionStage = engine.buildSubscriber(toGraph());
    return CompletionSubscriber.of(subscriberWithCompletionStage.getSubscriber(), subscriberWithCompletionStage.getCompletion());
}