mirror of https://gitee.com/dromara/liteFlow
feature #IBI6A3 新的基于原生态形式的javax插件
This commit is contained in:
parent
f6ebb06045
commit
5805a1e539
|
@ -45,17 +45,6 @@ public class CommonBenchmark {
|
|||
flowExecutor.execute2Resp("chain1");
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void test2(){
|
||||
flowExecutor.execute2Resp("chain2");
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void test3(){
|
||||
flowExecutor.execute2Resp("chain3");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(CommonBenchmark.class.getSimpleName())
|
||||
|
|
|
@ -7,14 +7,37 @@
|
|||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@LiteflowComponent("a")
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
int v1 = 2;
|
||||
int v2 = 3;
|
||||
DefaultContext ctx = this.getFirstContextBean();
|
||||
ctx.setData("s1", v1 * v2);
|
||||
|
||||
TestDomain domain = ContextAwareHolder.loadContextAware().getBean(TestDomain.class);
|
||||
String str = domain.sayHello("jack");
|
||||
ctx.setData("hi", str);
|
||||
|
||||
List<Person> personList = ListUtil.toList(
|
||||
new Person("jack", 15000),
|
||||
new Person("tom", 13500),
|
||||
new Person("peter", 18600)
|
||||
);
|
||||
|
||||
int totalSalary = personList.stream().mapToInt(Person::getSalary).sum();
|
||||
|
||||
ctx.setData("salary", totalSalary);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeIteratorComponent;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@LiteflowComponent("d")
|
||||
public class DCmp extends NodeIteratorComponent {
|
||||
@Override
|
||||
public Iterator<?> processIterator() throws Exception {
|
||||
return ListUtil.toList("1","2","3").iterator();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class TestDomain {
|
||||
|
||||
public String sayHello(String name){
|
||||
return "hello," + name;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Person> personList = ListUtil.toList(
|
||||
new Person("jack", 15000),
|
||||
new Person("tom", 13500),
|
||||
new Person("peter", 18600)
|
||||
);
|
||||
|
||||
int totalSalary = personList.stream().mapToInt(Person::getSalary).sum();
|
||||
System.out.println(totalSalary);
|
||||
}
|
||||
}
|
|
@ -1,37 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language="java">
|
||||
<![CDATA[
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.yomahub.liteflow.benchmark.cmp.Person;
|
||||
import com.yomahub.liteflow.script.body.CommonScriptBody;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
public class Demo implements CommonScriptBody {
|
||||
public Void body(ScriptExecuteWrap wrap) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(a,b,c);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(a,b,s1);
|
||||
</chain>
|
||||
|
||||
<chain name="chain3">
|
||||
ITERATOR(d).parallel(true).DO(THEN(a,b,c));
|
||||
THEN(a);
|
||||
</chain>
|
||||
</flow>
|
|
@ -47,19 +47,6 @@ public class ScriptGroovyBenchmark {
|
|||
flowExecutor.execute2Resp("chain1");
|
||||
}
|
||||
|
||||
//LF动态创建组件和规则,并执行
|
||||
@Benchmark
|
||||
public void test2(){
|
||||
String scriptContent = ResourceUtil.readUtf8Str("classpath:script.groovy");
|
||||
LiteFlowNodeBuilder.createScriptNode().setId("ds").setScript(scriptContent).build();
|
||||
|
||||
if(!FlowBus.containChain("chain2")){
|
||||
LiteFlowChainELBuilder.createChain().setChainId("chain2").setEL("THEN(ds)").build();
|
||||
}
|
||||
flowExecutor.execute2Resp("chain2");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(ScriptGroovyBenchmark.class.getSimpleName())
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("a")
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
}
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
|
||||
private Integer salary;
|
||||
|
||||
public Person(String name, Integer salary) {
|
||||
this.name = name;
|
||||
this.salary = salary;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getSalary() {
|
||||
return salary;
|
||||
}
|
||||
|
||||
public void setSalary(Integer salary) {
|
||||
this.salary = salary;
|
||||
}
|
||||
}
|
|
@ -35,21 +35,9 @@
|
|||
defaultContext.setData("s1", a * b)
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s2" name="循环脚本1" type="for_script" language="groovy">
|
||||
<![CDATA[
|
||||
return 2
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s3" name="选择脚本" type="switch_script" language="groovy">
|
||||
<![CDATA[
|
||||
return "b"
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(FOR(s2).DO(THEN(a, b, c, s1)), SWITCH(s3).TO(a,b));
|
||||
THEN(s1);
|
||||
</chain>
|
||||
</flow>
|
|
@ -1,29 +0,0 @@
|
|||
import cn.hutool.core.collection.ListUtil
|
||||
import cn.hutool.core.date.DateUtil
|
||||
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Function
|
||||
import java.util.stream.Collectors
|
||||
|
||||
def date = DateUtil.parse("2022-10-17 13:31:43")
|
||||
defaultContext.setData("demoDate", date)
|
||||
|
||||
List<String> list = ListUtil.toList("a", "b", "c")
|
||||
|
||||
List<String> resultList = list.stream().map(s -> "hello," + s).collect(Collectors.toList())
|
||||
|
||||
defaultContext.setData("resultList", resultList)
|
||||
|
||||
class Student {
|
||||
int studentID
|
||||
String studentName
|
||||
}
|
||||
|
||||
Student student = new Student()
|
||||
student.studentID = 100301
|
||||
student.studentName = "张三"
|
||||
defaultContext.setData("student", student)
|
||||
|
||||
def a = 3
|
||||
def b = 2
|
||||
defaultContext.setData("s1", a * b)
|
|
@ -48,7 +48,7 @@ public class ScriptJavaBenchmark {
|
|||
}
|
||||
|
||||
//LF动态创建组件和规则,并执行
|
||||
@Benchmark
|
||||
/*@Benchmark
|
||||
public void test2(){
|
||||
String scriptContent = ResourceUtil.readUtf8Str("classpath:javaScript.java");
|
||||
LiteFlowNodeBuilder.createScriptNode().setId("ds").setScript(scriptContent).build();
|
||||
|
@ -57,7 +57,7 @@ public class ScriptJavaBenchmark {
|
|||
LiteFlowChainELBuilder.createChain().setChainId("chain2").setEL("THEN(ds)").build();
|
||||
}
|
||||
flowExecutor.execute2Resp("chain2");
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
|
@ -67,7 +67,7 @@ public class ScriptJavaBenchmark {
|
|||
.warmupIterations(1)//预热次数
|
||||
.measurementIterations(3)//执行次数
|
||||
.measurementTime(new TimeValue(10, TimeUnit.SECONDS))//每次执行多少时间
|
||||
.threads(300)//多少个线程
|
||||
.threads(100)//多少个线程
|
||||
.forks(1)//多少个进程
|
||||
.timeUnit(TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
|
|
@ -4,12 +4,16 @@
|
|||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language="java">
|
||||
<![CDATA[
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.yomahub.liteflow.benchmark.cmp.Person;
|
||||
import com.yomahub.liteflow.benchmark.cmp.TestDomain;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
import com.yomahub.liteflow.script.body.JaninoCommonScriptBody;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Demo implements JaninoCommonScriptBody {
|
||||
public Void body(ScriptExecuteWrap wrap) {
|
||||
int v1 = 2;
|
||||
|
@ -21,40 +25,28 @@
|
|||
String str = domain.sayHello("jack");
|
||||
ctx.setData("hi", str);
|
||||
|
||||
List<Person> personList = ListUtil.toList(
|
||||
new Person("jack", 15000),
|
||||
new Person("tom", 13500),
|
||||
new Person("peter", 18600)
|
||||
);
|
||||
|
||||
int totalSalary = 0;
|
||||
for (int i = 0; i < personList.size(); i++) {
|
||||
Person p = (Person)personList.get(i);
|
||||
totalSalary += p.getSalary();
|
||||
}
|
||||
|
||||
ctx.setData("salary", totalSalary);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s2" name="循环脚本1" type="for_script" language="java">
|
||||
<![CDATA[
|
||||
import com.yomahub.liteflow.script.body.JaninoForScriptBody;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
|
||||
public class Demo implements JaninoForScriptBody{
|
||||
public Integer body(ScriptExecuteWrap wrap){
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s3" name="选择脚本" type="switch_script" language="java">
|
||||
<![CDATA[
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.body.JaninoSwitchScriptBody;
|
||||
|
||||
public class Demo implements JaninoSwitchScriptBody {
|
||||
public String body(ScriptExecuteWrap wrap) {
|
||||
return "b";
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(FOR(s2).DO(THEN(a, b, c, s1)), SWITCH(s3).TO(a,b));
|
||||
THEN(s1);
|
||||
</chain>
|
||||
</flow>
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>liteflow-benchmark</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>liteflow-benchmark-script-javax-pro</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-javax-pro</artifactId>
|
||||
<version>${revision}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,59 @@
|
|||
package com.yomahub.liteflow.benchmark;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
import org.openjdk.jmh.runner.options.TimeValue;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
@EnableAutoConfiguration
|
||||
@PropertySource(value = "classpath:application.properties")
|
||||
@ComponentScan("com.yomahub.liteflow.benchmark.cmp")
|
||||
public class ScriptJavaxProBenchmark {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
applicationContext = SpringApplication.run(ScriptJavaxProBenchmark.class);
|
||||
flowExecutor = applicationContext.getBean(FlowExecutor.class);
|
||||
}
|
||||
|
||||
@TearDown
|
||||
public void tearDown() {
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
//普通执行
|
||||
@Benchmark
|
||||
public void test1(){
|
||||
flowExecutor.execute2Resp("chain1");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(ScriptJavaxProBenchmark.class.getSimpleName())
|
||||
.mode(Mode.Throughput)
|
||||
.warmupIterations(1)//预热次数
|
||||
.measurementIterations(3)//执行次数
|
||||
.measurementTime(new TimeValue(10, TimeUnit.SECONDS))//每次执行多少时间
|
||||
.threads(100)//多少个线程
|
||||
.forks(1)//多少个进程
|
||||
.timeUnit(TimeUnit.SECONDS)
|
||||
.build();
|
||||
new Runner(opt).run();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
|
||||
private Integer salary;
|
||||
|
||||
public Person(String name, Integer salary) {
|
||||
this.name = name;
|
||||
this.salary = salary;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getSalary() {
|
||||
return salary;
|
||||
}
|
||||
|
||||
public void setSalary(Integer salary) {
|
||||
this.salary = salary;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class TestDomain {
|
||||
|
||||
public String sayHello(String name){
|
||||
return "hello," + name;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Person> personList = ListUtil.toList(
|
||||
new Person("jack", 15000),
|
||||
new Person("tom", 13500),
|
||||
new Person("peter", 18600)
|
||||
);
|
||||
|
||||
int totalSalary = personList.stream().mapToInt(Person::getSalary).sum();
|
||||
System.out.println(totalSalary);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
liteflow.rule-source=flow.xml
|
||||
liteflow.print-execution-log=false
|
||||
liteflow.script-setting.javax-is-cache=false
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language="java">
|
||||
<![CDATA[
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.yomahub.liteflow.benchmark.cmp.Person;
|
||||
import com.yomahub.liteflow.benchmark.cmp.TestDomain;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
public class Demo extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
int v1 = 2;
|
||||
int v2 = 3;
|
||||
DefaultContext ctx = this.getFirstContextBean();
|
||||
ctx.setData("s1", v1 * v2);
|
||||
|
||||
TestDomain domain = ContextAwareHolder.loadContextAware().getBean(TestDomain.class);
|
||||
String str = domain.sayHello("jack");
|
||||
ctx.setData("hi", str);
|
||||
|
||||
List<Person> personList = ListUtil.toList(
|
||||
new Person("jack", 15000),
|
||||
new Person("tom", 13500),
|
||||
new Person("peter", 18600)
|
||||
);
|
||||
|
||||
int totalSalary = personList.stream().mapToInt(Person::getSalary).sum();
|
||||
|
||||
ctx.setData("salary", 47100);
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(s1);
|
||||
</chain>
|
||||
</flow>
|
|
@ -49,18 +49,6 @@ public class ScriptJavaxBenchmark {
|
|||
flowExecutor.execute2Resp("chain1");
|
||||
}
|
||||
|
||||
//LF动态创建组件和规则,并执行
|
||||
@Benchmark
|
||||
public void test2(){
|
||||
String scriptContent = ResourceUtil.readUtf8Str("classpath:javaxScript.java");
|
||||
LiteFlowNodeBuilder.createScriptNode().setId("ds").setScript(scriptContent).build();
|
||||
|
||||
if(!FlowBus.containChain("chain2")){
|
||||
LiteFlowChainELBuilder.createChain().setChainId("chain2").setEL("THEN(ds)").build();
|
||||
}
|
||||
flowExecutor.execute2Resp("chain2");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
}
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
}
|
||||
|
||||
}
|
|
@ -41,35 +41,9 @@
|
|||
}
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s2" name="循环脚本1" type="for_script" language="java">
|
||||
<![CDATA[
|
||||
import com.yomahub.liteflow.script.body.ForScriptBody;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
|
||||
public class Demo implements ForScriptBody {
|
||||
public Integer body(ScriptExecuteWrap wrap) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s3" name="选择脚本" type="switch_script" language="java">
|
||||
<![CDATA[
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.body.SwitchScriptBody;
|
||||
|
||||
public class Demo implements SwitchScriptBody {
|
||||
public String body(ScriptExecuteWrap wrap) {
|
||||
return "b";
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(FOR(s2).DO(THEN(a, b, c, s1)), SWITCH(s3).TO(a,b));
|
||||
THEN(s1);
|
||||
</chain>
|
||||
</flow>
|
|
@ -1,6 +1,9 @@
|
|||
package com.yomahub.liteflow.core;
|
||||
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
|
||||
/**
|
||||
|
@ -11,17 +14,68 @@ import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
|||
*/
|
||||
public class ScriptBooleanComponent extends NodeBooleanComponent implements ScriptComponent {
|
||||
|
||||
private final LFLog LOG = LFLoggerManager.getLogger(this.getClass());
|
||||
|
||||
private ScriptExecutor scriptExecutor;
|
||||
|
||||
@Override
|
||||
public boolean processBoolean() throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return (boolean) ScriptExecutorFactory.loadInstance()
|
||||
.getScriptExecutor(this.getRefNode().getLanguage())
|
||||
.execute(wrap);
|
||||
return (boolean) scriptExecutor.execute(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadScript(String script, String language) {
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
|
||||
LOG.info("load script for component[{}]", getDisplayName());
|
||||
scriptExecutor = ScriptExecutorFactory.loadInstance().getScriptExecutor(language);
|
||||
scriptExecutor.load(getNodeId(), script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccess() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return scriptExecutor.executeIsAccess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContinueOnError() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return scriptExecutor.executeIsContinueOnError(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnd() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return scriptExecutor.executeIsEnd(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeProcess() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeBeforeProcess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeAfterProcess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeOnSuccess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeOnError(wrap, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeRollback(wrap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,14 +3,11 @@ package com.yomahub.liteflow.core;
|
|||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 脚本组件类
|
||||
* 普通脚本组件类
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.0
|
||||
|
@ -19,16 +16,66 @@ public class ScriptCommonComponent extends NodeComponent implements ScriptCompon
|
|||
|
||||
private final LFLog LOG = LFLoggerManager.getLogger(this.getClass());
|
||||
|
||||
private ScriptExecutor scriptExecutor;
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap);
|
||||
scriptExecutor.execute(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadScript(String script, String language) {
|
||||
LOG.info("load script for component[{}]", getDisplayName());
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
|
||||
scriptExecutor = ScriptExecutorFactory.loadInstance().getScriptExecutor(language);
|
||||
scriptExecutor.load(getNodeId(), script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccess() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return scriptExecutor.executeIsAccess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContinueOnError() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return scriptExecutor.executeIsContinueOnError(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnd() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return scriptExecutor.executeIsEnd(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeProcess() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeBeforeProcess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeAfterProcess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeOnSuccess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeOnError(wrap, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeRollback(wrap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,16 +32,16 @@ public interface ScriptComponent {
|
|||
*/
|
||||
void loadScript(String script, String language);
|
||||
|
||||
default ScriptExecuteWrap buildWrap(NodeComponent cmp){
|
||||
default ScriptExecuteWrap buildWrap(NodeComponent thisCmp) {
|
||||
ScriptExecuteWrap wrap = new ScriptExecuteWrap();
|
||||
wrap.setCurrChainId(cmp.getCurrChainId());
|
||||
wrap.setNodeId(cmp.getNodeId());
|
||||
wrap.setSlotIndex(cmp.getSlotIndex());
|
||||
wrap.setTag(cmp.getTag());
|
||||
wrap.setCmpData(cmp.getCmpData(Map.class));
|
||||
wrap.setLoopIndex(cmp.getLoopIndex());
|
||||
wrap.setLoopObject(cmp.getCurrLoopObj());
|
||||
wrap.setCmp(cmp);
|
||||
wrap.setCurrChainId(thisCmp.getCurrChainId());
|
||||
wrap.setNodeId(thisCmp.getNodeId());
|
||||
wrap.setSlotIndex(thisCmp.getSlotIndex());
|
||||
wrap.setTag(thisCmp.getTag());
|
||||
wrap.setLoopIndex(thisCmp.getLoopIndex());
|
||||
wrap.setLoopObject(thisCmp.getCurrLoopObj());
|
||||
wrap.setCmpData(thisCmp.getCmpData(Map.class));
|
||||
wrap.setCmp(thisCmp);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.yomahub.liteflow.core;
|
||||
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -13,17 +16,68 @@ import java.util.Map;
|
|||
*/
|
||||
public class ScriptForComponent extends NodeForComponent implements ScriptComponent {
|
||||
|
||||
private final LFLog LOG = LFLoggerManager.getLogger(this.getClass());
|
||||
|
||||
private ScriptExecutor scriptExecutor;
|
||||
|
||||
@Override
|
||||
public int processFor() throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return (int) ScriptExecutorFactory.loadInstance()
|
||||
.getScriptExecutor(this.getRefNode().getLanguage())
|
||||
.execute(wrap);
|
||||
return (int) scriptExecutor.execute(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadScript(String script, String language) {
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
|
||||
LOG.info("load script for component[{}]", getDisplayName());
|
||||
scriptExecutor = ScriptExecutorFactory.loadInstance().getScriptExecutor(language);
|
||||
scriptExecutor.load(getNodeId(), script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccess() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return scriptExecutor.executeIsAccess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContinueOnError() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return scriptExecutor.executeIsContinueOnError(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnd() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return scriptExecutor.executeIsEnd(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeProcess() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeBeforeProcess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeAfterProcess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeOnSuccess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeOnError(wrap, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeRollback(wrap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.yomahub.liteflow.core;
|
||||
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -13,17 +16,68 @@ import java.util.Map;
|
|||
*/
|
||||
public class ScriptSwitchComponent extends NodeSwitchComponent implements ScriptComponent {
|
||||
|
||||
private final LFLog LOG = LFLoggerManager.getLogger(this.getClass());
|
||||
|
||||
private ScriptExecutor scriptExecutor;
|
||||
|
||||
@Override
|
||||
public String processSwitch() throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return (String) ScriptExecutorFactory.loadInstance()
|
||||
.getScriptExecutor(this.getRefNode().getLanguage())
|
||||
.execute(wrap);
|
||||
return (String) scriptExecutor.execute(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadScript(String script, String language) {
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script);
|
||||
LOG.info("load script for component[{}]", getDisplayName());
|
||||
scriptExecutor = ScriptExecutorFactory.loadInstance().getScriptExecutor(language);
|
||||
scriptExecutor.load(getNodeId(), script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccess() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return scriptExecutor.executeIsAccess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContinueOnError() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return scriptExecutor.executeIsContinueOnError(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnd() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
return scriptExecutor.executeIsEnd(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeProcess() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeBeforeProcess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess() {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeAfterProcess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeOnSuccess(wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeOnError(wrap, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws Exception {
|
||||
ScriptExecuteWrap wrap = this.buildWrap(this);
|
||||
scriptExecutor.executeRollback(wrap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.yomahub.liteflow.exception.LiteFlowException;
|
|||
import com.yomahub.liteflow.lifecycle.LifeCycleHolder;
|
||||
import com.yomahub.liteflow.slot.DataBus;
|
||||
import com.yomahub.liteflow.slot.Slot;
|
||||
import com.yomahub.liteflow.spi.holder.CmpAroundAspectHolder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -99,4 +100,36 @@ public abstract class ScriptExecutor {
|
|||
* @throws Exception 例外
|
||||
*/
|
||||
public abstract Object compile(String script) throws Exception;
|
||||
|
||||
public boolean executeIsAccess(ScriptExecuteWrap wrap){
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean executeIsContinueOnError(ScriptExecuteWrap wrap){
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean executeIsEnd(ScriptExecuteWrap wrap){
|
||||
return false;
|
||||
}
|
||||
|
||||
public void executeBeforeProcess(ScriptExecuteWrap wrap){
|
||||
CmpAroundAspectHolder.loadCmpAroundAspect().beforeProcess(wrap.getCmp());
|
||||
}
|
||||
|
||||
public void executeAfterProcess(ScriptExecuteWrap wrap){
|
||||
CmpAroundAspectHolder.loadCmpAroundAspect().afterProcess(wrap.getCmp());
|
||||
}
|
||||
|
||||
public void executeOnSuccess(ScriptExecuteWrap wrap) throws Exception{
|
||||
CmpAroundAspectHolder.loadCmpAroundAspect().onSuccess(wrap.getCmp());
|
||||
}
|
||||
|
||||
public void executeOnError(ScriptExecuteWrap wrap, Exception e) throws Exception{
|
||||
CmpAroundAspectHolder.loadCmpAroundAspect().onError(wrap.getCmp(), e);
|
||||
}
|
||||
|
||||
public void executeRollback(ScriptExecuteWrap wrap) throws Exception{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-plugin</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>liteflow-script-javax-pro</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-core</artifactId>
|
||||
<version>${revision}</version>
|
||||
<optional>true</optional>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.noear</groupId>
|
||||
<artifactId>liquor-eval</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,169 @@
|
|||
package com.yomahub.liteflow.script.javaxpro;
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.enums.ScriptTypeEnum;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
import com.yomahub.liteflow.script.exception.ScriptLoadException;
|
||||
import com.yomahub.liteflow.script.javaxpro.vo.JavaxProSettingMapKey;
|
||||
import com.yomahub.liteflow.util.CopyOnWriteHashMap;
|
||||
import org.noear.liquor.eval.CodeSpec;
|
||||
import org.noear.liquor.eval.Scripts;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Javax语言执行器,基于liquor
|
||||
* 和静态类完全一样的定义模式
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.13.0
|
||||
*/
|
||||
public class JavaxProExecutor extends ScriptExecutor {
|
||||
private final Map<String, NodeComponent> compiledScriptMap = new CopyOnWriteHashMap<>();
|
||||
|
||||
private boolean isCache;
|
||||
|
||||
@Override
|
||||
public ScriptExecutor init() {
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
String isCacheValue = liteflowConfig.getScriptSetting().get(JavaxProSettingMapKey.IS_CACHE);
|
||||
isCache = Boolean.parseBoolean(isCacheValue);
|
||||
//如果有生命周期则执行相应生命周期实现
|
||||
super.lifeCycle(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(String nodeId, String script) {
|
||||
try{
|
||||
compiledScriptMap.put(nodeId, (NodeComponent) compile(script));
|
||||
}catch (InvocationTargetException e){
|
||||
String errorMsg = StrUtil.format("script loading error for node[{}],error msg:{}", nodeId, e.getTargetException().getMessage());
|
||||
throw new ScriptLoadException(errorMsg);
|
||||
}catch (Exception e){
|
||||
String errorMsg = StrUtil.format("script loading error for node[{}],error msg:{}", nodeId, e.getMessage());
|
||||
throw new ScriptLoadException(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unLoad(String nodeId) {
|
||||
compiledScriptMap.remove(nodeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNodeIds() {
|
||||
return new ArrayList<>(compiledScriptMap.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object executeScript(ScriptExecuteWrap wrap) throws Exception {
|
||||
NodeComponent cmp = getExecutableCmp(wrap);
|
||||
cmp.process();
|
||||
return cmp.getItemResultMetaValue(wrap.slotIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanCache() {
|
||||
compiledScriptMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptTypeEnum scriptType() {
|
||||
return ScriptTypeEnum.JAVA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object compile(String script) throws Exception {
|
||||
CodeSpec codeSpec = new CodeSpec(convertScript(script))
|
||||
.returnType(Object.class)
|
||||
.cached(isCache);
|
||||
return Scripts.eval(codeSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeIsAccess(ScriptExecuteWrap wrap) {
|
||||
NodeComponent cmp = getExecutableCmp(wrap);
|
||||
return cmp.isAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeIsContinueOnError(ScriptExecuteWrap wrap) {
|
||||
NodeComponent cmp = getExecutableCmp(wrap);
|
||||
return cmp.isContinueOnError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeIsEnd(ScriptExecuteWrap wrap) {
|
||||
NodeComponent cmp = getExecutableCmp(wrap);
|
||||
return cmp.isEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeBeforeProcess(ScriptExecuteWrap wrap) {
|
||||
NodeComponent cmp = getExecutableCmp(wrap);
|
||||
cmp.beforeProcess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeAfterProcess(ScriptExecuteWrap wrap) {
|
||||
NodeComponent cmp = getExecutableCmp(wrap);
|
||||
cmp.afterProcess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeOnSuccess(ScriptExecuteWrap wrap) throws Exception {
|
||||
NodeComponent cmp = getExecutableCmp(wrap);
|
||||
cmp.onSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeOnError(ScriptExecuteWrap wrap, Exception e) throws Exception {
|
||||
NodeComponent cmp = getExecutableCmp(wrap);
|
||||
cmp.onError(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeRollback(ScriptExecuteWrap wrap) throws Exception {
|
||||
NodeComponent cmp = getExecutableCmp(wrap);
|
||||
cmp.rollback();
|
||||
}
|
||||
|
||||
private NodeComponent getExecutableCmp(ScriptExecuteWrap wrap){
|
||||
if (!compiledScriptMap.containsKey(wrap.getNodeId())) {
|
||||
String errorMsg = StrUtil.format("script for node[{}] is not loaded", wrap.getNodeId());
|
||||
throw new ScriptLoadException(errorMsg);
|
||||
}
|
||||
NodeComponent cmp = compiledScriptMap.get(wrap.getNodeId());
|
||||
cmp.setRefNode(wrap.getCmp().getRefNode());
|
||||
cmp.setNodeId(wrap.getNodeId());
|
||||
cmp.setType(wrap.getCmp().getType());
|
||||
cmp.setSelf(cmp);
|
||||
return cmp;
|
||||
}
|
||||
|
||||
private String convertScript(String script){
|
||||
//替换掉public,private,protected等修饰词
|
||||
String script1 = script.replaceAll("public class", "class")
|
||||
.replaceAll("private class", "class")
|
||||
.replaceAll("protected class", "class");
|
||||
|
||||
//分析出class的具体名称
|
||||
String className = ReUtil.getGroup1("class\\s+(\\w+)\\s+(implements|extends)", script1);
|
||||
|
||||
if (StrUtil.isBlank(className)){
|
||||
throw new RuntimeException("cannot find class defined");
|
||||
}
|
||||
|
||||
return script1 + "\n" +
|
||||
StrUtil.format("{} item = new {}();\n", className, className) +
|
||||
"return item;";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.yomahub.liteflow.script.javaxpro.vo;
|
||||
|
||||
/**
|
||||
* Javax语言特殊配置项的Key
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.12.4
|
||||
*/
|
||||
public interface JavaxProSettingMapKey {
|
||||
|
||||
String IS_CACHE = "javax-is-cache";
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
# Javax-pro的实现
|
||||
com.yomahub.liteflow.script.javaxpro.JavaxProExecutor
|
|
@ -1,6 +1,5 @@
|
|||
package com.yomahub.liteflow.script.javax;
|
||||
|
||||
import cn.hutool.core.util.BooleanUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.enums.ScriptTypeEnum;
|
||||
|
|
|
@ -23,7 +23,9 @@
|
|||
<module>liteflow-script-lua</module>
|
||||
<module>liteflow-script-aviator</module>
|
||||
<module>liteflow-script-java</module>
|
||||
<module>liteflow-script-javax</module>
|
||||
<module>liteflow-script-kotlin</module>
|
||||
<module>liteflow-script-javax-pro</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>liteflow-testcase-el</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>liteflow-testcase-el-script-javaxpro-springboot</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-spring-boot-starter</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-javax-pro</artifactId>
|
||||
<version>${revision}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.39</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,26 @@
|
|||
package com.yomahub.liteflow.test;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowInitHook;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.lifecycle.LifeCycleHolder;
|
||||
import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||
import com.yomahub.liteflow.spi.holder.SpiFactoryInitializing;
|
||||
import com.yomahub.liteflow.spring.ComponentScanner;
|
||||
import com.yomahub.liteflow.thread.ExecutorHelper;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
|
||||
public class BaseTest {
|
||||
|
||||
@AfterAll
|
||||
public static void cleanScanCache() {
|
||||
ComponentScanner.cleanCache();
|
||||
FlowBus.cleanCache();
|
||||
ExecutorHelper.loadInstance().clearExecutorServiceMap();
|
||||
SpiFactoryInitializing.clean();
|
||||
LiteflowConfigGetter.clean();
|
||||
FlowInitHook.cleanHook();
|
||||
FlowBus.clearStat();
|
||||
LifeCycleHolder.clean();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.yomahub.liteflow.test.script.javaxpro.common;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/common/application.properties")
|
||||
@SpringBootTest(classes = ScriptJavaxProCommonELTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({ "com.yomahub.liteflow.test.script.javaxpro.common.cmp" })
|
||||
public class ScriptJavaxProCommonELTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test
|
||||
public void testCommon1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals(6, (int)context.getData("s1"));
|
||||
Assertions.assertEquals("hello,jack", context.getData("hi"));
|
||||
Assertions.assertEquals(47100, (Integer) context.getData("salary"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommon2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
package com.yomahub.liteflow.test.script.javaxpro.common.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
@ -15,6 +15,7 @@ public class ACmp extends NodeComponent {
|
|||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("ACmp executed!");
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
package com.yomahub.liteflow.test.script.javaxpro.common.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
@ -15,6 +15,7 @@ public class BCmp extends NodeComponent {
|
|||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
package com.yomahub.liteflow.test.script.javaxpro.common.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
@ -15,6 +15,7 @@ public class CCmp extends NodeComponent {
|
|||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.benchmark.cmp;
|
||||
package com.yomahub.liteflow.test.script.javaxpro.common.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
@ -18,6 +18,7 @@ public class DCmp extends NodeComponent {
|
|||
public void process() {
|
||||
DefaultContext context = this.getFirstContextBean();
|
||||
context.setData("count", 198);
|
||||
System.out.println("DCmp executed!");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.yomahub.liteflow.test.script.javaxpro.common.cmp;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
|
||||
private Integer salary;
|
||||
|
||||
public Person(String name, Integer salary) {
|
||||
this.name = name;
|
||||
this.salary = salary;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getSalary() {
|
||||
return salary;
|
||||
}
|
||||
|
||||
public void setSalary(Integer salary) {
|
||||
this.salary = salary;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.yomahub.liteflow.test.script.javaxpro.common.cmp;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class TestDomain {
|
||||
|
||||
public String sayHello(String name){
|
||||
return "hello," + name;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Person> personList = ListUtil.toList(
|
||||
new Person("jack", 15000),
|
||||
new Person("tom", 13500),
|
||||
new Person("peter", 18600)
|
||||
);
|
||||
|
||||
int totalSalary = personList.stream().mapToInt(Person::getSalary).sum();
|
||||
System.out.println(totalSalary);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
liteflow.rule-source=common/flow.xml
|
|
@ -0,0 +1,119 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="s1" name="普通脚本1" type="script" language="java">
|
||||
<![CDATA[
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
import com.yomahub.liteflow.test.script.javaxpro.common.cmp.Person;
|
||||
import com.yomahub.liteflow.test.script.javaxpro.common.cmp.TestDomain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Demo extends NodeComponent {
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
int v1 = 2;
|
||||
int v2 = 3;
|
||||
DefaultContext ctx = this.getFirstContextBean();
|
||||
ctx.setData("s1", v1 * v2);
|
||||
|
||||
TestDomain domain = ContextAwareHolder.loadContextAware().getBean(TestDomain.class);
|
||||
System.out.println(domain);
|
||||
String str = domain.sayHello("jack");
|
||||
ctx.setData("hi", str);
|
||||
|
||||
List<Person> personList = ListUtil.toList(
|
||||
new Person("jack", 15000),
|
||||
new Person("tom", 13500),
|
||||
new Person("peter", 18600)
|
||||
);
|
||||
|
||||
int totalSalary = personList.stream().mapToInt(Person::getSalary).sum();
|
||||
|
||||
System.out.println(totalSalary);
|
||||
ctx.setData("salary", 47100);
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s2" name="循环脚本1" type="for_script" language="java">
|
||||
<![CDATA[
|
||||
import com.yomahub.liteflow.core.NodeForComponent;
|
||||
|
||||
public class Demo extends NodeForComponent {
|
||||
@Override
|
||||
public int processFor() throws Exception {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="s3" name="选择脚本" type="switch_script" language="java">
|
||||
<![CDATA[
|
||||
import com.yomahub.liteflow.core.NodeSwitchComponent;
|
||||
|
||||
public class Demo extends NodeSwitchComponent {
|
||||
@Override
|
||||
public String processSwitch() throws Exception {
|
||||
return "b";
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="t1" name="测试脚本T1" type="script" language="java">
|
||||
<![CDATA[
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.core.NodeSwitchComponent;
|
||||
|
||||
public class Demo extends NodeComponent {
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
System.out.println(this.getTag());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeProcess() {
|
||||
System.out.println("beforeProcess:" + this.getTag());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() throws Exception {
|
||||
System.out.println("success! oh yeah");
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="t2" name="测试脚本T2" type="script" language="java">
|
||||
<![CDATA[
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.core.NodeSwitchComponent;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Demo extends NodeComponent {
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
Map map = this.getCmpData(Map.class);
|
||||
System.out.println(map.get("age"));
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(FOR(s2).DO(THEN(a, b, c, s1)), SWITCH(s3).TO(a,b));
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(t1.tag("1111"), t2.data("{\"name\":\"jack\",\"age\":31}"));
|
||||
</chain>
|
||||
</flow>
|
|
@ -44,6 +44,7 @@
|
|||
<module>liteflow-testcase-el-sql-solon</module>
|
||||
<module>liteflow-testcase-el-script-javax-springboot</module>
|
||||
<module>liteflow-testcase-el-sql-springboot-sharding-jdbc</module>
|
||||
<module>liteflow-testcase-el-script-javaxpro-springboot</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
|
|
3
pom.xml
3
pom.xml
|
@ -451,7 +451,8 @@
|
|||
<module>liteflow-el-builder</module>
|
||||
<module>liteflow-script-plugin/liteflow-script-javax</module>
|
||||
<module>liteflow-benchmark</module>
|
||||
</modules>
|
||||
<module>liteflow-benchmark/liteflow-benchmark-script-javax-pro</module>
|
||||
</modules>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
|
|
Loading…
Reference in New Issue