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
      • Default context
      • Customized context
      • Multi-Context
    • 🪶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
    • 🥥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文档
  • 🌮Data context
铂赛东
2022-07-01
Contents

🌯Definition and use

# Default context

LiteFlow provides a default implementation of the data context: DefaultContext. This default implementation is actually a Map, which is the main container for storing data.

You can put data in through the setData method in the DefaultContext and get data through the getData method.

suggestion

DefaultContext can be used, but in the actual business, there will be a lot of weak types with this, and it is quite inconvenient to convert all the time when accessing data. So it is officially recommended that you implement your own data context.

# Customized context

You can use any of your own beans as a context to pass in; LiteFlow has no requirements for the context bean.

The context you define is essentially a simple value object, and the context you define is more relevant to the business because it is strongly typed.

You can do incoming like this:

LiteflowResponse response = flowExecutor.execute2Resp("chain1", 流程初始参数, CustomContext.class);

Once passed in, LiteFlow will initialize it when called, assigning a unique instance to the context. You can get this context instance in the component like this:

@LiteflowComponent("yourCmpId")
public class YourCmp extends NodeComponent {

	@Override
	public void process() {
		CustomContext context = this.getContextBean(CustomContext.class);
		//Or you can use this method to get a context instance, which is equivalent to the above
		//CustomContext context = this.getFirstContextBean();
		...
	}
}

Please refer to Common Components for more information about what other default parameters are available in the component.

# Multi-Context

LiteFlow supports multiple contexts in the new version, the framework will initialize the multiple contexts you pass in before execution. It's also easy to get in the component based on the class type.

You can pass it in like this (scroll back if you can't see it all).

LiteflowResponse response = flowExecutor.execute2Resp("chain1", parameters, OrderContext.class, UserContext.class, SignContext.class);

The context instance can be obtained in the component as follows:

@LiteflowComponent("yourCmpId")
public class YourCmp extends NodeComponent {

	@Override
	public void process() {
		OrderContext orderContext = this.getContextBean(OrderContext.class);
		UserContext userContext = this.getContextBean(UserContext.class);
		SignContext signContext = this.getContextBean(SignContext.class);
		
		//If you only want to get the first context, and the first context is OrderContext, then you can also use this method
		//OrderContext orderContext = this.getFirstContextBean();
		...
	}
}
Help us improve this document (opens new window)
last update: 2022/10/13, 00:02:27
🍄Notice
🪶Pass initialized context

← 🍄Notice 🪶Pass initialized context→

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