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

The following examples show how to use org.eclipse.microprofile.reactive.streams.operators.spi.SubscriberWithCompletionStage. 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 File: Engine.java    From smallrye-mutiny with 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
Source File: Engine.java    From smallrye-reactive-streams-operators with 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<>();
    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 File: CoupledStageFactory.java    From smallrye-mutiny with 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
Source File: CoupledStageFactory.java    From smallrye-reactive-streams-operators with 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 -> Flowable.fromPublisher(
            new CouplingProcessor<>(upstream, subscriber.getSubscriber(), publisher));
}
 
Example #5
Source File: SubscriberBuilderImpl.java    From microprofile-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@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());
}