使用ContextAwareHolder.loadContextAware改造获取线程构建者

This commit is contained in:
daiqi
2022-03-11 21:42:12 +08:00
parent 61cbd1f4c3
commit e34416574d
3 changed files with 12 additions and 12 deletions

View File

@@ -398,6 +398,15 @@ public class FlowExecutor {
}
slot.setException(e);
} finally {
try{
if (ObjectUtil.isNotNull(chain)){
chain.executeFinally(slotIndex);
}
}catch (Exception e){
String errMsg = StrUtil.format("[{}]:an exception occurred during the finally Component execution in chain[{}]", slot.getRequestId(), chain.getChainName());
LOG.error(errMsg, e);
}
if (!isInnerChain) {
slot.printStep();
DataBus.releaseSlot(slotIndex);

View File

@@ -79,17 +79,6 @@ public class Chain implements Executable {
if (CollUtil.isEmpty(conditionList)) {
throw new FlowSystemException("no conditionList in this chain[" + chainName + "]");
}
try {
executeBody(slotIndex);
} finally {
executeFinally(slotIndex);
}
}
// 执行主体的逻辑
private void executeBody(Integer slotIndex) throws Exception {
//循环chain里包含的condition每一个condition分四种类型pre,then,when,finally
//这里conditionList其实已经是有序的pre一定在最前面finally一定在最后面
for (Condition condition : conditionList) {
if (condition instanceof PreCondition){
for (Executable executableItem : condition.getNodeList()) {

View File

@@ -14,6 +14,7 @@ import com.google.common.collect.Maps;
import com.yomahub.liteflow.exception.ThreadExecutorServiceCreateException;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -123,7 +124,8 @@ public class ExecutorHelper {
*/
private ExecutorBuilder getExecutorBuilder(String threadExecutorClass) {
try {
return (ExecutorBuilder) Class.forName(threadExecutorClass).newInstance();
Class<ExecutorBuilder> executorClass = (Class<ExecutorBuilder>) Class.forName(threadExecutorClass);
return ContextAwareHolder.loadContextAware().registerBean(executorClass);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new ThreadExecutorServiceCreateException(e.getMessage());