🍿Custom component executor
LiteFlow allows users to define custom component executors, which can be used to add custom code and rewrite retry policies when executing components. Of course other ways to accomplish the same purpose are possible, such as the component aspect feature.
If you are not very clear about what this feature does, it is recommended to use the default way. (Which really means no need to read this section)
# Global component executor
For custom component executors, you can override them globally. The default component executor is:com.yomahub.liteflow.flow.executor.DefaultNodeExecutor
You can replace the global default component executor by:
liteflow.node-executor-class=com.yomahub.liteflow.test.nodeExecutor.CustomerDefaultNodeExecutor
Custom component executors need to inheritcom.yomahub.liteflow.entity.executor.NodeExecutor
。
public class CustomerDefaultNodeExecutor extends NodeExecutor {
@Override
public void execute(NodeComponent instance) throws Exception {
LOG.info("use customerDefaultNodeExecutor to execute");
super.execute(instance);
//You can add your own code here, the above code can be removed.
//But make sure to at least call instance.execute(), otherwise the component will not be executed correctly.
}
}
# Configure executor for one components
single components also support configuring custom executor.
You need to implement the getNodeExecutorClass
method when defining the component:
@LiteflowComponent("d")
public class DCmp extends NodeComponent {
@Override
public void process() {
System.out.println("DCmp executed!");
}
@Override
public Class<? extends NodeExecutor> getNodeExecutorClass() {
return CustomerNodeExecutorAndCustomRetry.class;
}
}
# Priority
If both global and single component are configured with custom executors, the executor configured on the single component will take precedence.
# The impact of custom executors on retry functions
Because the retry logic is implemented in the default executor. So if you configure a custom executor, the retry function needs to be implemented by yourself. And the global retry parameter configuration and the @LiteflowRetry
function tag will be invalid.
Of course, if you implement your own custom executor, you can still get the retry parameters and write your own special retry logic. All this needs to be done by yourself. Pay attention to this.