org.eclipse.microprofile.reactive.streams.operators.ProcessorBuilder Java Examples

The following examples show how to use org.eclipse.microprofile.reactive.streams.operators.ProcessorBuilder. 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: DropWhileStageVerification.java    From microprofile-reactive-streams-operators with Apache License 2.0 6 votes vote down vote up
@Test
public void dropWhileStageBuilderShouldBeReusable() {
    ProcessorBuilder<Integer, Integer> dropWhile = rs.<Integer>builder()
        .dropWhile(i -> i < 3);

    assertEquals(await(rs.of(1, 2, 3, 4)
        .via(dropWhile)
        .toList()
        .run(getEngine())), Arrays.asList(3, 4));

    assertEquals(await(rs.of(0, 1, 6, 7)
        .via(dropWhile)
        .toList()
        .run(getEngine())), Arrays.asList(6, 7));

}
 
Example #2
Source File: Operators.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
public void via() {
    //tag::via[]
    ProcessorBuilder<Integer, String> processor = ReactiveStreams
            .<Integer>builder().map(i -> Integer.toString(i));

    ReactiveStreams.of(1, 2)
            .via(processor); // ("1", "2")
    //end::via[]
}
 
Example #3
Source File: PeekStageVerification.java    From microprofile-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test
public void peekStageShouldBeReusable() {
    ProcessorBuilder<Integer, Integer> peek = rs.<Integer>builder().peek(t -> {});

    assertEquals(await(rs.of(1, 2, 3).via(peek).toList().run(getEngine())), Arrays.asList(1, 2, 3));
    assertEquals(await(rs.of(4, 5, 6).via(peek).toList().run(getEngine())), Arrays.asList(4, 5, 6));
}
 
Example #4
Source File: FlatMapStageVerification.java    From microprofile-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test
public void flatMapStageBuilderShouldBeReusable() {
    ProcessorBuilder<PublisherBuilder<Integer>, Integer> flatMap =
        rs.<PublisherBuilder<Integer>>builder().flatMap(Function.identity());

    assertEquals(await(rs.of(rs.of(1, 2)).via(flatMap).toList().run(getEngine())), Arrays.asList(1, 2));
    assertEquals(await(rs.of(rs.of(3, 4)).via(flatMap).toList().run(getEngine())), Arrays.asList(3, 4));
}
 
Example #5
Source File: ProcessorBuilderVerification.java    From microprofile-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test
public void builderShouldBeImmutable() {
    ProcessorBuilder<Integer, Integer> builder = builder();
    ProcessorBuilder<Integer, Integer> mapped = builder.map(Function.identity());
    ProcessorBuilder<Integer, Integer> distinct = builder.distinct();
    SubscriberBuilder<Integer, Void> cancelled = builder.cancel();
    getAddedStage(Stage.Map.class, graphFor(mapped));
    getAddedStage(Stage.Distinct.class, graphFor(distinct));
    getAddedStage(Stage.Cancel.class, graphFor(cancelled));
}
 
Example #6
Source File: APITest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void testToStringProcessorFromSpec() throws ExecutionException, InterruptedException {
    ProcessorBuilder<Integer, String> toStringProcessor = ReactiveStreams.<Integer> builder().map(Object::toString);
    SubscriberBuilder<Integer, List<String>> toList = toStringProcessor.toList();

    CompletionStage<List<String>> stage = ReactiveStreams.of(1, 2, 3, 4, 5).to(toList).run();
    assertThat(stage.toCompletableFuture().get()).containsExactly("1", "2", "3", "4", "5");
}
 
Example #7
Source File: ProcessorBean.java    From microprofile-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("publisher-for-processor-builder-payload")
@Outgoing("processor-builder-payload")
public ProcessorBuilder<Integer, String> processorBuilderOfPayloads() {
  increment("publisher-for-processor-builder-payload");
  return ReactiveStreams.<Integer>builder()
    .map(i -> i + 1)
    .flatMap(i -> ReactiveStreams.of(i, i))
    .map(i -> Integer.toString(i));
}
 
Example #8
Source File: ProcessorBean.java    From microprofile-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("publisher-for-processor-builder-message")
@Outgoing("processor-builder-message")
public ProcessorBuilder<Message<Integer>, Message<String>> processorBuilderOfMessages() {
  increment("publisher-for-processor-builder-message");
  return ReactiveStreams.<Message<Integer>>builder()
    .map(Message::getPayload)
    .map(i -> i + 1)
    .flatMap(i -> ReactiveStreams.of(i, i))
    .map(i -> Integer.toString(i))
    .map(Message::of);
}
 
Example #9
Source File: ProcessorMediator.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private void processMethodReturningAProcessorBuilderOfMessages() {
    ProcessorBuilder<Message<?>, Message<?>> builder = Objects.requireNonNull(invoke(),
            msg.methodReturnedNull(configuration.methodAsString()));

    this.processor = ReactiveStreams.<Message<?>> builder()
            .flatMapCompletionStage(managePreProcessingAck())
            .via(builder)
            .buildRs();
}
 
Example #10
Source File: FlatMapCompletionStageVerification.java    From microprofile-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test
public void flatMapCsStageBuilderShouldBeResuable() {
    ProcessorBuilder<Integer, Integer> mapper = rs.<Integer>builder()
        .flatMapCompletionStage(i -> CompletableFuture.completedFuture(i + 1));
    assertEquals(await(rs.of(1, 2, 3).via(mapper).toList().run(getEngine())), Arrays.asList(2, 3, 4));
    assertEquals(await(rs.of(4, 5, 6).via(mapper).toList().run(getEngine())), Arrays.asList(5, 6, 7));
}
 
Example #11
Source File: ProcessorMediator.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private void processMethodReturningAProcessorBuilderOfPayloads() {
    ProcessorBuilder returnedProcessorBuilder = invoke();
    Objects.requireNonNull(returnedProcessorBuilder, msg.methodReturnedNull(configuration.methodAsString()));

    this.processor = ReactiveStreams.<Message<?>> builder()
            .flatMapCompletionStage(managePreProcessingAck())
            .map(Message::getPayload)
            .via(returnedProcessorBuilder)
            .map(Message::of)
            .buildRs();
}
 
Example #12
Source File: InvalidBlockingProcessorShapeTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Blocking
@Incoming("count")
@Outgoing("sink")
public ProcessorBuilder<Integer, String> process() {
    return ReactiveStreams.<Integer> builder()
            .map(i -> i + 1)
            .flatMapRsPublisher(i -> Flowable.just(i, i))
            .map(i -> Integer.toString(i));
}
 
Example #13
Source File: SkipStageVerification.java    From microprofile-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test
public void skipStageShouldBeReusable() {
    ProcessorBuilder<Integer, Integer> skip = rs.<Integer>builder().skip(2);

    assertEquals(await(rs.of(1, 2, 3, 4).via(skip).toList().run(getEngine())), Arrays.asList(3, 4));
    assertEquals(await(rs.of(5, 6, 7, 8).via(skip).toList().run(getEngine())), Arrays.asList(7, 8));
}
 
Example #14
Source File: InvalidBlockingProcessorShapeTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Blocking
@Incoming("count")
@Outgoing("sink")
public ProcessorBuilder<Message<Integer>, Message<String>> process() {
    return ReactiveStreams.<Message<Integer>> builder()
            .map(Message::getPayload)
            .map(i -> i + 1)
            .flatMapRsPublisher(i -> Flowable.just(i, i))
            .map(i -> Integer.toString(i))
            .map(Message::of);
}
 
Example #15
Source File: BeanWithPayloadProcessors.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(NO_ACKNOWLEDGMENT_BUILDER)
@Acknowledgment(Acknowledgment.Strategy.NONE)
@Outgoing("sink-" + NO_ACKNOWLEDGMENT_BUILDER)
public ProcessorBuilder<String, String> processorWithNoAckWithBuilder() {
    return ReactiveStreams.<String> builder()
            .flatMap(m -> ReactiveStreams.of(m, m))
            .peek(m -> processed(NO_ACKNOWLEDGMENT_BUILDER, m));
}
 
Example #16
Source File: BeanWithPayloadProcessors.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(DEFAULT_ACKNOWLEDGMENT_BUILDER)
@Outgoing("sink-" + DEFAULT_ACKNOWLEDGMENT_BUILDER)
public ProcessorBuilder<String, String> processorWithAutoAckBuilder() {
    return ReactiveStreams.<String> builder()
            .flatMap(m -> ReactiveStreams.of(m, m))
            .peek(m -> processed(DEFAULT_ACKNOWLEDGMENT_BUILDER, m));
}
 
Example #17
Source File: BeanWithPayloadProcessors.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(PRE_ACKNOWLEDGMENT_BUILDER)
@Acknowledgment(Acknowledgment.Strategy.PRE_PROCESSING)
@Outgoing("sink-" + PRE_ACKNOWLEDGMENT_BUILDER)
public ProcessorBuilder<String, String> processorWithPreAckBuilder() {
    return ReactiveStreams.<String> builder()
            .flatMap(m -> ReactiveStreams.of(m, m))
            .peek(m -> processed(PRE_ACKNOWLEDGMENT_BUILDER, m));
}
 
Example #18
Source File: BeanProducingAProcessorBuilderOfPayloads.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("count")
@Outgoing("sink")
public ProcessorBuilder<Integer, String> process() {
    return ReactiveStreams.<Integer> builder()
            .map(i -> i + 1)
            .flatMapRsPublisher(i -> Flowable.just(i, i))
            .map(i -> Integer.toString(i));
}
 
Example #19
Source File: ReactiveStreamsFactoryImpl.java    From microprofile-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Override
public <T, R> ProcessorBuilder<T, R> coupled(SubscriberBuilder<? super T, ?> subscriber,
    PublisherBuilder<? extends R> publisher) {
    Graph sGraph = ReactiveStreamsGraphBuilder.rsBuilderToGraph(Objects.requireNonNull(subscriber,
        "Subscriber must not be null"));
    Graph pGraph = ReactiveStreamsGraphBuilder.rsBuilderToGraph(Objects.requireNonNull(publisher,
        "Publisher must not be null"));
    return new ProcessorBuilderImpl<>(new Stages.Coupled(sGraph, pGraph), null);
}
 
Example #20
Source File: BeanProducingAProcessorBuilderOfMessages.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming("count")
@Outgoing("sink")
public ProcessorBuilder<Message<Integer>, Message<String>> process() {
    return ReactiveStreams.<Message<Integer>> builder()
            .map(Message::getPayload)
            .map(i -> i + 1)
            .flatMapRsPublisher(i -> Flowable.just(i, i))
            .map(i -> Integer.toString(i))
            .map(Message::of);
}
 
Example #21
Source File: BeanWithMessageProcessors.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(PRE_ACKNOWLEDGMENT_BUILDER)
@Acknowledgment(Acknowledgment.Strategy.PRE_PROCESSING)
@Outgoing("sink-" + PRE_ACKNOWLEDGMENT_BUILDER)
public ProcessorBuilder<Message<String>, Message<String>> processorWithPreAckBuilder() {
    return ReactiveStreams.<Message<String>> builder()
            .flatMap(m -> ReactiveStreams.of(Message.of(m.getPayload()), Message.of(m.getPayload())))
            .peek(m -> processed(PRE_ACKNOWLEDGMENT_BUILDER, m));
}
 
Example #22
Source File: BeanWithMessageProcessors.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(DEFAULT_ACKNOWLEDGMENT_BUILDER)
@Outgoing("sink-" + DEFAULT_ACKNOWLEDGMENT_BUILDER)
public ProcessorBuilder<Message<String>, Message<String>> processorWithAutoAckBuilder() {
    return ReactiveStreams.<Message<String>> builder()
            .flatMap(m -> ReactiveStreams.of(Message.of(m.getPayload()), Message.of(m.getPayload())).onComplete(
                    m::ack))
            .peek(m -> processed(DEFAULT_ACKNOWLEDGMENT_BUILDER, m));
}
 
Example #23
Source File: BeanWithMessageProcessors.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(NO_ACKNOWLEDGMENT_BUILDER)
@Acknowledgment(Acknowledgment.Strategy.NONE)
@Outgoing("sink-" + NO_ACKNOWLEDGMENT_BUILDER)
public ProcessorBuilder<Message<String>, Message<String>> processorWithNoAckWithBuilder() {
    return ReactiveStreams.<Message<String>> builder()
            .flatMap(m -> ReactiveStreams.of(Message.of(m.getPayload()), Message.of(m.getPayload())))
            .peek(m -> processed(NO_ACKNOWLEDGMENT_BUILDER, m));
}
 
Example #24
Source File: BeanWithMessageProcessors.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Incoming(MANUAL_ACKNOWLEDGMENT_BUILDER)
@Acknowledgment(Acknowledgment.Strategy.MANUAL)
@Outgoing("sink-" + MANUAL_ACKNOWLEDGMENT_BUILDER)
public ProcessorBuilder<Message<String>, Message<String>> processorWithAckWithBuilder() {
    return ReactiveStreams.<Message<String>> builder()
            .flatMapCompletionStage(m -> m.ack().thenApply(x -> m))
            .flatMap(m -> ReactiveStreams.of(Message.of(m.getPayload()), Message.of(m.getPayload())))
            .peek(m -> processed(MANUAL_ACKNOWLEDGMENT_BUILDER, m));
}
 
Example #25
Source File: ProcessorMediator.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
private boolean isReturningAProcessorOrAProcessorBuilder() {
    Class<?> returnType = configuration.getReturnType();
    return ClassUtils.isAssignable(returnType, Processor.class)
            || ClassUtils.isAssignable(returnType, ProcessorBuilder.class);
}
 
Example #26
Source File: MockedSender.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
public ProcessorBuilder<Void, Message<T>> createWrappedProcessor() {
    return ReactiveStreams.fromProcessor(new MessageProcessor());
}
 
Example #27
Source File: ProcessorBuilderImpl.java    From microprofile-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessorBuilder<T, R> onComplete(Runnable action) {
    return addStage(new Stages.OnComplete(action));
}
 
Example #28
Source File: ProcessorBuilderImpl.java    From microprofile-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessorBuilder<T, R> onTerminate(Runnable action) {
    return addStage(new Stages.OnTerminate(action));
}
 
Example #29
Source File: ProcessorBuilderImpl.java    From microprofile-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessorBuilder<T, R> onErrorResumeWithRsPublisher(Function<Throwable, ? extends Publisher<? extends R>> errorHandler) {
    return addStage(new Stages.OnErrorResumeWith(errorHandler.andThen(ReactiveStreamsGraphBuilder::publisherToGraph)));
}
 
Example #30
Source File: ProcessorBuilderImpl.java    From microprofile-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@Override
public <S> ProcessorBuilder<T, S> via(Processor<? super R, ? extends S> processor) {
    return addStage(new Stages.ProcessorStage(processor));
}