All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetlinks.rule.engine.api.task.CompositeOutput Maven / Gradle / Ivy

The newest version!
package org.jetlinks.rule.engine.api.task;

import lombok.AllArgsConstructor;
import org.jetlinks.rule.engine.api.RuleData;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

@AllArgsConstructor(staticName = "of")
public class CompositeOutput implements Output {

    private final List outputs;

    @Override
    public Mono write(Publisher dataStream) {
        return Flux.from(dataStream)
                .flatMap(data -> Flux.fromIterable(outputs)
                        .flatMap(out -> out.write(data)))
                .reduce(Boolean::equals)
                ;
    }

    @Override
    public Mono write(String nodeId, Publisher dataStream) {
        return Flux.from(dataStream)
                .flatMap(data -> Flux.fromIterable(outputs)
                        .flatMap(out -> out.write(nodeId, Mono.just(data))))
                .then();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy