🍒Pre & Finally components
LiteFlow supports pre-component and finally-component features.
Used to execute certain components before or after the chain.
The front and finally components are both serial nodes and do not support asynchronous.
# Pre Component
To execute certain nodes before a chain starts, use the PRE
keyword (must be capitalized) in EL rules:
<chain name="chain1">
THEN(
PRE(p1, p2),
a, b, c,
WHEN(d, e)
);
</chain>
# Finally component
Execute some nodes after a chain ends. It should be noted that the finally component is not affected by Exception. Even if the node fails, the finally component will still be executed. Use the FINALLY
keyword (must be capitalized) in EL rules:
<chain name="chain1">
THEN(
a, b, c,
FINALLY(f1, f2)
);
</chain>
# About sequence
Does the pre component have to be written in front? Does the finally component have to be written at the end?
No, PRE
and FINALLY
can be written anywhere in the first layer.
for example:
<chain name="chain1">
THEN(
PRE(a), c, d, FINALLY(f1, f2)
);
</chain>
The following expression is equivalent to the above, even if it is not placed in the corresponding position, it still has the same effect.
<chain name="chain1">
THEN(
FINALLY(f1, f2), c, PRE(a), d
);
</chain>
What is the first layer, please see the following example:
<chain name="chain1">
THEN(
a, THEN(PRE(b,c), d)
);
</chain>
In the above example, PRE
will not be executed. Because it's on the second layer. Valid only for PRE
and FINALLY
at the first layer.
# Scope
It is worth mentioning that the scope of PRE
and FINALLY
is the current Chain.
This also means that if you use PRE
and FINALLY
in a sub chain, it will only work for the sub chain.
Take a look at the following example:
<chain name="chain1">
THEN(PRE(p1, p2), chain2, FINALLY(f1));
</chain>
<chain name="chain2">
THEN(PRE(p3), a, b, FINALLY(f2));
</chain>
If executed correctly, the resulting steps should look like this:
p1=>p2=>p3=>a=>b=>f2=>f1