🎯How to build
It should be noted that the dynamic rule mode and the rule file mode do not actually conflict. They can be used alone or in combination.
# When to build
It is recommended to build at project startup, rules only needs to be build once. Do not build it every time you execute it! ! !
# Build Node
You can build a common Node like the following, of course in the spring/springboot environment, you don't need to build a Node in most cases, because as long as your component is marked with
@LiteflowComponent, the component will be scanned to and register automatically.
I just tell you that you can build it through code in this way. If your component is a dynamic proxy class instead of a statically existing java class, or a script node, such a building makes sense.
For the concept of script nodes, you can view Script Components
//Build a common component LiteFlowNodeBuilder.createCommonNode().setId("a") .setName("cmpA") .setClazz("com.yomahub.liteflow.test.builder.cmp.ACmp") .build(); //Build a switch component LiteFlowNodeBuilder.createSwitchNode().setId("a") .setName("cmpA") .setClazz("com.yomahub.liteflow.test.builder.cmp.ACmp") .build(); //Build a script common component LiteFlowNodeBuilder.createScriptNode().setId("a") .setName("cmpA") .setScript("your script text") .build(); //Build a script switch component LiteFlowNodeBuilder.createScriptSwitchNode().setId("a") .setName("cmpA") .setScript("your script text") .build(); //Build a script component that loads from file LiteFlowNodeBuilder.createScriptNode().setId("a") .setName("cmpA") .setFile("xml-script-file/s1.groovy") .build();
Remind again, if you are in a spring/springboot environment, you don't need to define components. Suggest scan into spring context
The node class here does not require you to declare
@Component. If the project is a spring system, the LiteFlow framework will automatically inject the node class into the spring context.
So you can still use any spring annotations like @Autowired and @Resource etc in this class.
# Build Chain
You can build a chain like the following, since it does not conflict with the rules defined. You can also use it in combination with rules files. When building, add it if it doesn't exist, and modify it if it exists.
LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( "THEN(a, b, WHEN(c, d))" ).build();
It is worth mentioning that since using the building mode is one by one, if you use a sub-process, if chain1 depends on chain2, then chain2 must be constructed first. Otherwise, an error will be reported.
However, after the study of the above chapters, in fact, an EL expression can represent a complex process, and even if it cannot, you can use sub-variables to optimize the process.
# Remove Chain
LiteFlow allows you to manually run the following code to destroy a chain: