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

org.jetlinks.rule.engine.defaults.LambdaTaskExecutor Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package org.jetlinks.rule.engine.defaults;

import org.jetlinks.rule.engine.api.RuleData;
import org.jetlinks.rule.engine.api.task.ExecutionContext;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;

import java.util.function.Function;
import java.util.function.Supplier;

public class LambdaTaskExecutor extends FunctionTaskExecutor {
    Supplier>> supplier;

    Function> function;

    public LambdaTaskExecutor(String name,
                              ExecutionContext context,
                              Function> function) {
        this(name, context, () -> function);

    }

    public LambdaTaskExecutor(String name,
                              ExecutionContext context,
                              Supplier>> supplier) {
        super(name, context);
        this.supplier = supplier;
        this.function = this.supplier.get();
    }

    @Override
    public void reload() {
        super.reload();
        this.function = this.supplier.get();
    }

    @Override
    protected Publisher apply(RuleData input) {
        return Flux.from(function.apply(input))
                .map(t -> {
                    if (t instanceof RuleData) {
                        return context.newRuleData(t);
                    }
                    return context.newRuleData(input.newData(t));
                });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy