mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-15 04:22:09 +08:00
getDispalyName
This commit is contained in:
@@ -18,6 +18,7 @@ import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||
import com.yomahub.liteflow.spi.holder.CmpAroundAspectHolder;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -303,4 +304,12 @@ public abstract class NodeComponent{
|
||||
public String getChainName(){
|
||||
return getSlot().getChainName();
|
||||
}
|
||||
|
||||
public String getDisplayName(){
|
||||
if(StringUtils.isEmpty(this.name)){
|
||||
return this.nodeId;
|
||||
}else {
|
||||
return this.nodeId + "(" + this.name + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ScriptComponent extends NodeComponent{
|
||||
}
|
||||
|
||||
public void loadScript(String script) {
|
||||
log.info("load script for component[{}]", getNodeId());
|
||||
log.info("load script for component[{}][{}]", getNodeId(),getDisplayName());
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor().load(getNodeId(), script);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
import com.yomahub.liteflow.spi.local.LocalContextAware;
|
||||
import com.yomahub.liteflow.util.CopyOnWriteHashMap;
|
||||
import com.yomahub.liteflow.util.LiteFlowProxyUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -156,7 +157,7 @@ public class FlowBus {
|
||||
|
||||
nodeMap.put(nodeId, node);
|
||||
} catch (Exception e) {
|
||||
String error = StrUtil.format("component[{}] register error", cmpClazz.getName());
|
||||
String error = StrUtil.format("component[{}][{}] register error", cmpClazz.getName(), StringUtils.isEmpty(name)?nodeId:nodeId+"("+name+")");
|
||||
LOG.error(error, e);
|
||||
throw new ComponentCannotRegisterException(error);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.yomahub.liteflow.enums.ExecuteTypeEnum;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ChainEndException;
|
||||
import com.yomahub.liteflow.exception.FlowSystemException;
|
||||
import com.yomahub.liteflow.util.LogUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -127,7 +126,7 @@ public class Node implements Executable,Cloneable{
|
||||
if (instance.isAccess()) {
|
||||
//根据配置判断是否打印执行中的日志
|
||||
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())){
|
||||
LogUtil.info(LOG,"[{}]:[O]start component[{}][{}] execution",slot.getRequestId(),instance.getClass().getSimpleName(),instance.getName());
|
||||
LOG.info("[{}]:[O]start component[{}][{}] execution",slot.getRequestId(),instance.getClass().getSimpleName(),instance.getDisplayName());
|
||||
}
|
||||
|
||||
//这里开始进行重试的逻辑和主逻辑的运行
|
||||
@@ -136,12 +135,12 @@ public class Node implements Executable,Cloneable{
|
||||
nodeExecutor.execute(instance);
|
||||
//如果组件覆盖了isEnd方法,或者在在逻辑中主要调用了setEnd(true)的话,流程就会立马结束
|
||||
if (instance.isEnd()) {
|
||||
String errorInfo = StrUtil.format("[{}]:component[{}] lead the chain to end", slot.getRequestId(), instance.getClass().getSimpleName());
|
||||
String errorInfo = StrUtil.format("[{}]:[{}] lead the chain to end", slot.getRequestId(), instance.getClass().getSimpleName(),instance.getDisplayName());
|
||||
throw new ChainEndException(errorInfo);
|
||||
}
|
||||
} else {
|
||||
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())){
|
||||
LogUtil.info(LOG,"[{}]:[X]skip component[{}][{}] execution", slot.getRequestId(), instance.getClass().getSimpleName(),instance.getName());
|
||||
LOG.info("[{}]:[X]skip component[{}][{}] execution", slot.getRequestId(), instance.getClass().getSimpleName(),instance.getDisplayName());
|
||||
}
|
||||
}
|
||||
} catch (ChainEndException e){
|
||||
|
||||
@@ -50,7 +50,7 @@ public abstract class NodeExecutor {
|
||||
//执行重试逻辑 - 子类通过实现该方法进行重试逻辑的控制
|
||||
protected void retry(NodeComponent instance, int currentRetryCount) throws Exception {
|
||||
Slot slot = DataBus.getSlot(instance.getSlotIndex());
|
||||
LOG.info("[{}]:component[{}] performs {} retry", slot.getRequestId(), instance.getNodeId(), currentRetryCount + 1);
|
||||
LOG.info("[{}]:component[{}][{}] performs {} retry", slot.getRequestId(), instance.getNodeId(),instance.getDisplayName(), currentRetryCount + 1);
|
||||
//执行业务逻辑的主要入口
|
||||
instance.execute();
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
package com.yomahub.liteflow.util;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author 惊云
|
||||
* @date 2022/6/12 11:05
|
||||
*/
|
||||
public class LogUtil {
|
||||
|
||||
private static final String EMPTY = "";
|
||||
|
||||
/**
|
||||
* 日志输出,过滤掉null值的占位符
|
||||
* @param logger
|
||||
* @param message
|
||||
* @param arguments
|
||||
*/
|
||||
public static void info(Logger logger,String message,Object... arguments){
|
||||
info(PlaceholderEnum.PACK_PLACEHOLDER,logger,message,arguments);
|
||||
}
|
||||
|
||||
public static void info(PlaceholderEnum placeholderEnum,Logger logger,String message,Object... arguments){
|
||||
StringBuilder result = new StringBuilder(message);
|
||||
int replaceCount = 0;
|
||||
for (int i = 0; i < arguments.length; i++){
|
||||
if(Objects.isNull(arguments[i])){
|
||||
int index = StringUtils.ordinalIndexOf(result.toString(), placeholderEnum.getValue(), i+1-replaceCount);
|
||||
if(index > 0){
|
||||
replaceCount++;
|
||||
result.replace(index,index + placeholderEnum.getValue().length(),EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
Object[] objects = Arrays.stream(arguments).filter(Objects::nonNull).toArray();
|
||||
logger.info(result.toString(),objects);
|
||||
}
|
||||
|
||||
public enum PlaceholderEnum{
|
||||
PLACEHOLDER("PLACEHOLDER","{}"),
|
||||
PACK_PLACEHOLDER("PACK_PLACEHOLDER", "[{}]");
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
PlaceholderEnum(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
private String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
private String getValue(){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user