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
    • 🥥Method level declaration
  • 🎲Dynamic rules

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

    • 🍒Pre & Finally components
    • 🥠Substitute component
    • 🍉Component Parameters
    • 🍑Component alias
    • 🍍Component tag
    • 🥝Component event
      • Success event
      • Failure event
        • Note 1
        • Note 2
        • Note 2
    • 🥑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文档
  • 🎨Advanced features
铂赛东
2022-07-03
Contents

🥝Component event

LiteFlow supports component event. There are 2 events supported: success event and failure event.

# Success event

If you override the onSuccess method in the component, this method will be called back when the component succeeds.

@LiteflowComponent("a")
public class ACmp extends NodeComponent {

	@Override
	public void process() {
		DefaultContext context = this.getContextBean(DefaultContext.class);
		//do your biz
	}

	@Override
	public void onSuccess() throws Exception {
		DefaultContext context = this.getContextBean(DefaultContext.class);
		//do your biz
	}
}

In the success event, you can get the context in the same way.

# Failure event

If you override the onError method in the component, the component will call back this method when an exception occurs.

@Component("d")
public class DCmp extends NodeComponent {

	@Override
	public void process() throws Exception{
		//mock throw exception
		throw new NullPointerException();
	}

	@Override
	public void onError() throws Exception {
		DefaultContext context = this.getContextBean(DefaultContext.class);
		//do your biz
	}
}

# Note 1

After the onError method is executed, because the main chain throws an exception, the entire chain is still in a failed state. Errors thrown by the main process are still recorded in LiteFlowResponse.

# Note 2

If the onError method itself throws an error, then the final error thrown is the error in the main chain, and the exception generated by the onError method will be printed, but not thrown. for example:

@Component("d")
public class DCmp extends NodeComponent {

	@Override
	public void process() throws Exception{
		//mock throw exception
		throw new NullPointerException();
	}

	@Override
	public void onError() throws Exception {
		throw new IllegalAccessException("The error event itself throws an exception");
	}
}

Then the exception in the final response will be NullPointerException instead of IllegalAccessException, but the IllegalAccessException exception will be printed.

# Note 2

After the onError method is executed, will the afterProcess method still execute (assuming both are implemented)?

Yes, the afterProcess method will be executed whether or not an error is thrown.

Help us improve this document (opens new window)
last update: 2022/10/13, 00:02:27
🍍Component tag
🥑Implicit chain

← 🍍Component tag 🥑Implicit chain→

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