LiteFlow LiteFlow
💒Home
📚Documents
💖Donation
🚀Plugin
  • About LiteFlow
  • Update Record
Community
Users
Gitee (opens new window)
Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
💒Home
📚Documents
💖Donation
🚀Plugin
  • About LiteFlow
  • Update Record
Community
Users
Gitee (opens new window)
Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
  • 🍤Introduction
  • 🍓Features
  • 🍟Quick Start(Hello world)

    • 🍄Notice
    • 🌿Springboot environment

      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
    • 🌱Spring environment

      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
    • 🌵Other environment

      • 🍄Notice
      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
  • 🍢Configuration item

    • 🍄Notice
    • 🌿Springboot environment
    • 🌱Spring environment
    • 🌵Other environment
  • 🗂Rules file

    • 📔Rules file format
    • 📕Local rule file
    • 📗Zookeeper source
    • 📘SQL database source
    • 📋Nacos source
    • 🗄Etcd source
    • 📙Custom source
  • 🔗General components

    • 📎Common component
    • ✂️Switch component
    • 📌If component
    • 🧬For component
    • ⛓While component
    • 🧿Break component
  • 🧩How to write EL rules

    • 🍄Notice
    • 🌴Serial mode
    • 🎋Parallel mode
    • 🌾Switch mode
    • 🌵If mode
    • 🌳Loop mode
    • 🍁Use sub chain
    • 🍂Use sub variables
    • 💐Complex example
    • 🌻About semicolons
    • 🌰About comments
    • 🐚Component Name Package
  • 🌮Data context

    • 🍄Notice
    • 🌯Definition and use
    • 🪶Pass initialized context
  • 🛩Flow executor

    • 🍄Notice
    • 🎡Executor method
    • 🎢Chain input parameter
    • 🎈LiteflowResponse object
  • 🍋Script component

    • 🍫Choose a script language
    • 🍕Define script component
    • 🌯Define file script
    • 🍣Interact with java
    • 🍘Dynamic refresh script
  • 🍇Declarative component

    • 🥭What is a declarative component
    • 🧅Class level declaration
      • Declaration of common components
      • Switch component declaration
      • If component declaration
      • For component declaration
      • While component declaration
      • Break component declaration
      • Notice
    • 🥥Method level declaration
  • 🎲Dynamic rules

    • 🍄Notice
    • 🎯How to build
  • 🎨Advanced features

    • 🍒Pre & Finally components
    • 🥠Substitute component
    • 🍉Component Parameters
    • 🍑Component alias
    • 🍍Component tag
    • 🥝Component event
    • 🥑Implicit chain
    • 🍕Private delivery
    • 🍣Component retry
    • 🍖Smooth hot refresh
    • 🍪Component aspect
    • 🍡Step information
    • 🧊Exceptions
    • 🧇Printing details
    • 🧁Custom request id
    • 🌭Multiple type rules
    • 🥗Asynchronous thread pool
    • 🍿Custom component executor
    • 🍥Simple monitor
    • 🧉DTD in Xml
  • ⛱Test cases and demo

    • 🪁Test cases
    • 🪀Demo
  • 🪂Performance
  • v2.9.X文档
  • 🍇Declarative component
铂赛东
2022-10-12
Contents

🧅Class level declaration

The main purpose of class-level declaration is to make ordinary java beans into components of LiteFlow through annotations. There is no need to inherit classes or implement interfaces.

Since the components of LiteFlow need to be defined by inheriting classes in the conventional way, you cannot inherit the classes of your own business. This feature can solve this problem.

# Declaration of common components

You can declare a common component as follows:

@LiteflowComponent("a")
@LiteflowCmpDefine
public class ACmp{
  
	@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
	public void processAcmp(NodeComponent bindCmp) {
		System.out.println("ACmp executed!");
	}

	@LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS)
	public boolean isAcmpAccess(NodeComponent bindCmp){
		return true;
	}

	@LiteflowMethod(LiteFlowMethodEnum.BEFORE_PROCESS)
	public void beforeAcmp(String nodeId, Slot slot){
		System.out.println("before A");
	}

	@LiteflowMethod(LiteFlowMethodEnum.AFTER_PROCESS)
	public void afterAcmp(String nodeId, Slot slot){
		System.out.println("after A");
	}

	@LiteflowMethod(LiteFlowMethodEnum.ON_SUCCESS)
	public void onAcmpSuccess(NodeComponent bindCmp){
		System.out.println("Acmp success");
	}

	@LiteflowMethod(LiteFlowMethodEnum.ON_ERROR)
	public void onAcmpError(NodeComponent bindCmp){
		System.out.println("Acmp error");
	}
	
	@LiteflowMethod(LiteFlowMethodEnum.IS_END)
	public boolean isAcmpEnd(NodeComponent bindCmp) {
		return false;
	}
}

Users do not need to inherit NodeComponent. On the class you define, as long as the class is annotated with LiteflowCmpDefine, and the corresponding method is annotated with LiteflowMethod, any custom class can be turned into a component.

The role of LiteFlowMethod is to map your own defined methods to component methods. The other methods are also defined as such.

Notice1

It should be noted here that most methods must pass the parameter NodeComponent bindCmp, and there must be only one parameter, otherwise an error will be reported, and beforeProcess and afterProcess are still defined according to the previous parameters. Note this, see the example above.

In the past, the this keyword was used to get the context bean, but now you only need to get it from bindCmp.

The name of the method can be defined any way you want. There is no limit to this.

Notice2

When you define a method yourself, the return value should be the same as the return value of the corresponding method in the conventional component. For example, the process method of ordinary components does not return, such as the processIf method of IF components, which returns a boolean value.

If you write it wrong, a little exception will occur, which may increase your troubleshooting time.

# Switch component declaration

Declaring the switch component requires adding the NodeTypeEnum.SWITCH parameter to both the class and the method.

@Component("e")
@LiteflowCmpDefine(NodeTypeEnum.SWITCH)
public class ECmp{

    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH)
    public String processSwitch(NodeComponent bindCmp) throws Exception {
        System.out.println("Ecomp executed!");
        return "g";
    }
}

# If component declaration

Declaring the if component requires adding the NodeTypeEnum.IF parameter to both the class and the method.

@Component("x")
@LiteflowCmpDefine(NodeTypeEnum.IF)
public class XCmp{

	@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.IF)
	public boolean processIf(NodeComponent bindCmp) throws Exception {
		//do your biz
		return true;
	}
}

# For component declaration

Declaring the For component requires adding the NodeTypeEnum.FOR parameter to both the class and the method.

@Component("x")
@LiteflowCmpDefine(NodeTypeEnum.FOR)
public class XCmp{

	@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR, nodeType = NodeTypeEnum.FOR)
	public int processFor(NodeComponent bindCmp) throws Exception {
		//do your biz
		return 10;
	}
}

# While component declaration

Declaring the While component requires adding the NodeTypeEnum.WHILE parameter to both the class and the method.

@Component("x")
@LiteflowCmpDefine(NodeTypeEnum.WHILE)
public class XCmp{

	@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeType = NodeTypeEnum.WHILE)
	public boolean processWhile(NodeComponent bindCmp) throws Exception {
		//get your while flag
		boolean flag = xxxxxx;
		return flag;
	}
}

# Break component declaration

Declaring the Break component requires adding the NodeTypeEnum.BREAK parameter to both the class and the method.

@Component("x")
@LiteflowCmpDefine(NodeTypeEnum.BREAK)
public class XCmp{

	@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeType = NodeTypeEnum.BREAK)
	public boolean processBreak(NodeComponent bindCmp) throws Exception {
		//get your break flag
		boolean flag = xxxxxx;
		return flag;
	}
}

# Notice

notice

For other methods in the class, they are declared in the same way as processXxx.

Help us improve this document (opens new window)
last update: 2022/10/13, 00:02:27
🥭What is a declarative component
🥥Method level declaration

← 🥭What is a declarative component 🥥Method level declaration→

Theme by Vdoing | Copyright © 2020-2022 铂赛东 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式