diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 7ab5e7e56..49cb0ac93 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -9,6 +9,7 @@ */ package com.thebeastshop.liteflow.core; +import java.text.MessageFormat; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -23,7 +24,11 @@ import com.thebeastshop.liteflow.entity.config.Node; import com.thebeastshop.liteflow.entity.config.ThenCondition; import com.thebeastshop.liteflow.entity.config.WhenCondition; import com.thebeastshop.liteflow.entity.data.DataBus; -import com.thebeastshop.liteflow.exception.FlowException; +import com.thebeastshop.liteflow.exception.ChainNotFoundException; +import com.thebeastshop.liteflow.exception.ComponentNotAccessException; +import com.thebeastshop.liteflow.exception.FlowExecutorNotInitException; +import com.thebeastshop.liteflow.exception.FlowSystemException; +import com.thebeastshop.liteflow.exception.NoAvailableSlotException; import com.thebeastshop.liteflow.flow.FlowBus; import com.thebeastshop.liteflow.parser.FlowParser; @@ -38,7 +43,8 @@ public class FlowExecutor { try { FlowParser.parseLocal(path); } catch (Exception e) { - LOG.error("init flow executor cause error,cannot parse rule file{}", path, e); + String errorMsg = MessageFormat.format("init flow executor cause error,cannot parse rule file{}", path); + throw new FlowExecutorNotInitException(errorMsg); } } } @@ -53,13 +59,14 @@ public class FlowExecutor { Chain chain = FlowBus.getChain(chainId); if(chain == null){ - LOG.error("couldn't find chain with the id[{}]",chainId); + String errorMsg = MessageFormat.format("couldn't find chain with the id[{}]", chainId); + throw new ChainNotFoundException(errorMsg); } slotIndex = DataBus.offerSlot(); LOG.info("slot[{}] offered",slotIndex); if(slotIndex == -1){ - throw new Exception("there is no available slot"); + throw new NoAvailableSlotException("there is no available slot"); } DataBus.getSlot(slotIndex).setRequestData(param); @@ -79,14 +86,13 @@ public class FlowExecutor { if(component.isAccess()){ component.execute(); }else{ - LOG.error("component[{}] do not gain access",component.getClass().getSimpleName()); - throw new FlowException("component ["+component.getClass().getSimpleName()+"] do not gain access"); + String errorMsg = MessageFormat.format("component[{}] do not gain access", component.getClass().getSimpleName()); + throw new ComponentNotAccessException(errorMsg); } }catch(Throwable t){ if(component.isContinueOnError()){ LOG.error("component[{}] cause error,but flow is still go on",t,component.getClass().getSimpleName()); }else{ - LOG.error(t.getMessage(),t); throw t; } } @@ -102,8 +108,7 @@ public class FlowExecutor { DataBus.getSlot(slotIndex).printStep(); return DataBus.getSlot(slotIndex).getResponseData(); }catch(Exception e){ - LOG.error("executor cause error",e); - throw new FlowException("executor cause error"); + throw new FlowSystemException("executor cause error"); }finally{ DataBus.releaseSlot(slotIndex); } diff --git a/src/main/java/com/thebeastshop/liteflow/exception/ChainNotFoundException.java b/src/main/java/com/thebeastshop/liteflow/exception/ChainNotFoundException.java new file mode 100644 index 000000000..05ec01fb3 --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/exception/ChainNotFoundException.java @@ -0,0 +1,21 @@ +package com.thebeastshop.liteflow.exception; + +public class ChainNotFoundException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public ChainNotFoundException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/main/java/com/thebeastshop/liteflow/exception/ComponentNotAccessException.java b/src/main/java/com/thebeastshop/liteflow/exception/ComponentNotAccessException.java new file mode 100644 index 000000000..bcc118ee4 --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/exception/ComponentNotAccessException.java @@ -0,0 +1,21 @@ +package com.thebeastshop.liteflow.exception; + +public class ComponentNotAccessException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public ComponentNotAccessException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/main/java/com/thebeastshop/liteflow/exception/FlowExecutorNotInitException.java b/src/main/java/com/thebeastshop/liteflow/exception/FlowExecutorNotInitException.java new file mode 100644 index 000000000..40fb8d781 --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/exception/FlowExecutorNotInitException.java @@ -0,0 +1,21 @@ +package com.thebeastshop.liteflow.exception; + +public class FlowExecutorNotInitException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public FlowExecutorNotInitException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/main/java/com/thebeastshop/liteflow/exception/FlowException.java b/src/main/java/com/thebeastshop/liteflow/exception/FlowSystemException.java similarity index 73% rename from src/main/java/com/thebeastshop/liteflow/exception/FlowException.java rename to src/main/java/com/thebeastshop/liteflow/exception/FlowSystemException.java index e3b1f5e3b..6789c2c51 100644 --- a/src/main/java/com/thebeastshop/liteflow/exception/FlowException.java +++ b/src/main/java/com/thebeastshop/liteflow/exception/FlowSystemException.java @@ -1,13 +1,13 @@ package com.thebeastshop.liteflow.exception; -public class FlowException extends RuntimeException { +public class FlowSystemException extends RuntimeException { private static final long serialVersionUID = 1L; /** 异常信息 */ private String message; - public FlowException(String message) { + public FlowSystemException(String message) { this.message = message; } diff --git a/src/main/java/com/thebeastshop/liteflow/exception/NoAvailableSlotException.java b/src/main/java/com/thebeastshop/liteflow/exception/NoAvailableSlotException.java new file mode 100644 index 000000000..beda393da --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/exception/NoAvailableSlotException.java @@ -0,0 +1,21 @@ +package com.thebeastshop.liteflow.exception; + +public class NoAvailableSlotException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public NoAvailableSlotException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +}