📎Common component
Common component nodes need to inherit the NodeComponent
class, which can be used in the THEN
and WHEN
keywords.
Need to implement the process
method:
@LiteflowComponent("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}
tip
@LiteflowComponent
inherits from @Component
, if you are in the spring system environment, you can inject any spring beans into the component for use.
The parameter a of @LiteflowComponent
is the component ID you need to use when writing EL rules.
# Methods that can be overridden
For components, the following methods in the superclass can be overridden.
# isAccess
It is recommended to implement the isAccess
method, indicating whether to enter the node, which can be used for pre-judgment of business parameters.
# isContinueOnError
Indicates whether the error continues to execute the next component, the default value is false.
# isEnd
If it returns true after overwriting, it means that the entire process will be terminated immediately after the component is executed. For this method, since it is a process that the user voluntarily ends, it is a normal end, so the final isSuccess is true.
tip
It should be noted that if this.setIsEnd(true)
is called when isContinueOnError
is true, it will still terminate. The isSuccess
in the response is still true.
# beforeProcess and afterProcess
The pre- and post-processors of the process, where the pre-processor is executed after isAccess
.
Used to perform some pre- and post-processing, but generally this is not needed. If it is to do the component front and rear in a unified way, it is recommended to use the aspect to complete it. For the aspect, please refer to Component aspect.
# onSuccess and onError
The success or failure event callback of the process, please refer to Component Event Callback for details.
# Methods that the This keyword can call
# Get context
In the component node, you can get the context defined by yourself through the method this.getContextBean(clazz)
at any time, so that you can get any data.
# getNodeId
Get the component ID.
# getName
Get component alias.
# getChainName
Get the currently executing Chain name.
# getRequestData
Get the initial parameters of the Chain.
# setIsEnd
Indicates whether to end the entire process immediately, the usage is this.setIsEnd(true)
. For this method, since it is a process that the user voluntarily ends, it is a normal end, so the final isSuccess is true.
notice
It should be noted that if this.setIsEnd(true)
is called when isContinueOnError
is true, it will still terminate. The isSuccess
in the response is still true.
# getTag
Get the label information of this component. For the definition and use of labels, please refer to Component Labels.
# invoke and invoke2Response
Call the implicit process. For the description and usage of the implicit process, please refer to Implicit Chain.
# @LiteflowComponent
Since v2.6.0, the @LiteflowComponent
tag has been added, which is inherited from Spring's @Component
tag, so in terms of function, it is no different from the @Component
tag, but @LiteflowComponent
A new name
attribute has been added to alias the component, which will be reflected when printing the call chain. For details, please refer to the Printing Details chapter. Starting with the new version, it is recommended that you use @LiteflowComponent
, of course, @Component
can also continue to be used.