Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
402 changed files
with
30,453 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.creditease.ns.framework</groupId> | ||
<artifactId>NS4_FRAME</artifactId> | ||
<version>0.8.3-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>ns_chains</artifactId> | ||
<name>NS_CHAINS</name> | ||
<description>一个工作流基础框架</description> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.creditease.ns.framework</groupId> | ||
<artifactId>ns_commons</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mvel</groupId> | ||
<artifactId>mvel2</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>2.1</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-release-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<configuration> | ||
<useReleaseProfile>false</useReleaseProfile> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
24 changes: 24 additions & 0 deletions
24
NS_CHAINS/src/main/java/com/creditease/ns/chains/chain/AbstractChain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.creditease.ns.chains.chain; | ||
|
||
import com.creditease.ns.chains.exchange.Exchanger; | ||
|
||
public abstract class AbstractChain implements Chain{ | ||
|
||
public void doCommand(Exchanger exchanger) throws Exception { | ||
checkExchanger(exchanger); | ||
doChain(exchanger); | ||
} | ||
|
||
private void checkExchanger(Exchanger exchanger) throws Exception | ||
{ | ||
if (exchanger == null) | ||
{ | ||
throw new Exception("exchanger不能为null"); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isNotBreak() { | ||
return false; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
NS_CHAINS/src/main/java/com/creditease/ns/chains/chain/AbstractConditionaleCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.creditease.ns.chains.chain; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import com.creditease.ns.chains.exchange.Exchanger; | ||
|
||
public abstract class AbstractConditionaleCommand implements ConditionableCommand{ | ||
protected List<Command> commands; | ||
protected String cond; | ||
protected String desc; | ||
|
||
|
||
public void doCommand(Exchanger exchanger) throws Exception { | ||
if (canExecute(cond, exchanger)) | ||
{ | ||
for (Iterator iterator = commands.iterator(); iterator.hasNext(); ) | ||
{ | ||
Command command = (Command) iterator.next(); | ||
command.doCommand(exchanger); | ||
} | ||
} | ||
else | ||
{ | ||
doEmpty(); | ||
} | ||
} | ||
|
||
protected void doEmpty() | ||
{ | ||
//TODO 打印日志 | ||
} | ||
|
||
public List<Command> getCommands() { | ||
return commands; | ||
} | ||
|
||
|
||
public void setCommands(List<Command> commands) { | ||
this.commands = commands; | ||
} | ||
|
||
|
||
public String getCond() { | ||
return cond; | ||
} | ||
|
||
|
||
public void setCond(String cond) { | ||
this.cond = cond; | ||
} | ||
|
||
public String getDesc() { | ||
return desc; | ||
} | ||
|
||
public void setDesc(String desc) { | ||
this.desc = desc; | ||
} | ||
|
||
@Override | ||
public String getLogStr() { | ||
return "[执行条件判断命令] ["+cond+"] ["+(commands == null ? 0 : commands.size())+"] ["+desc+"]"; | ||
} | ||
|
||
@Override | ||
public boolean isNotBreak() { | ||
return false; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
NS_CHAINS/src/main/java/com/creditease/ns/chains/chain/AbstractElIfCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.creditease.ns.chains.chain; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
import com.creditease.ns.chains.exchange.Exchanger; | ||
import com.creditease.ns.chains.util.ExpUtil; | ||
|
||
public abstract class AbstractElIfCommand extends AbstractConditionaleCommand{ | ||
|
||
@Override | ||
public void doCommand(Exchanger exchanger) throws Exception { | ||
if (canExecute(cond, exchanger)) | ||
{ | ||
boolean result = ExpUtil.executeStatement(this, exchanger, ConditionableCommand.ELIFEXECUTECAN); | ||
if (result) | ||
{ | ||
for (Iterator iterator = commands.iterator(); iterator.hasNext(); ) | ||
{ | ||
Command command = (Command) iterator.next(); | ||
command.doCommand(exchanger); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
doEmpty(); | ||
} | ||
} | ||
|
||
|
||
|
||
} |
37 changes: 37 additions & 0 deletions
37
NS_CHAINS/src/main/java/com/creditease/ns/chains/chain/AbstractIfCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.creditease.ns.chains.chain; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
import com.creditease.ns.chains.exchange.Exchanger; | ||
import com.creditease.ns.chains.util.ExpUtil; | ||
|
||
public abstract class AbstractIfCommand extends AbstractConditionaleCommand{ | ||
|
||
@Override | ||
public void doCommand(Exchanger exchanger) throws Exception { | ||
|
||
ExpUtil.startIfElseFlag(exchanger); | ||
|
||
if (canExecute(cond, exchanger)) | ||
{ | ||
boolean result = ExpUtil.executeStatement(this, exchanger, ConditionableCommand.IFEXECUTECAN); | ||
|
||
if (result) | ||
{ | ||
for (Iterator iterator = commands.iterator(); iterator.hasNext(); ) | ||
{ | ||
Command command = (Command) iterator.next(); | ||
command.doCommand(exchanger); | ||
} | ||
} | ||
|
||
} | ||
else | ||
{ | ||
doEmpty(); | ||
} | ||
} | ||
|
||
|
||
} |
92 changes: 92 additions & 0 deletions
92
NS_CHAINS/src/main/java/com/creditease/ns/chains/chain/AbstractServiceMessageCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.creditease.ns.chains.chain; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.creditease.framework.exception.NSException; | ||
import com.creditease.framework.exception.StopException; | ||
import com.creditease.framework.pojo.ServiceMessage; | ||
import com.creditease.framework.scope.RetInfo; | ||
import com.creditease.framework.work.ActionWorker; | ||
import com.creditease.ns.chains.constants.ChainConstants; | ||
import com.creditease.ns.chains.exchange.Exchanger; | ||
import com.creditease.ns.log.NsLog; | ||
|
||
public abstract class AbstractServiceMessageCommand implements Command{ | ||
static NsLog flowLog = NsLog.getFlowLog("NsChainFlow", "NsChainFlow"); | ||
private ThreadLocal<Object> notBreakChain = new ThreadLocal<Object>(); | ||
/** | ||
* 这个方法需要注意 | ||
* 当在使用spring注解的时候,使用人员往往喜欢在doService方法上加事务注解 | ||
* transactional 此时就会出现问题,发现事务没有起作用 | ||
* 原因就是doService是被doCommand调用的 doCommand上面是没有加transactional注解的 | ||
* 原理是 在spring中当外部对象调用时 直接调用的是代理对象 而在本地对象自我调用内部方法 | ||
* 利用的是this对象 这是原生对象 绕过了代理 所以事务没有执行 | ||
* 目前的解决办法是继承类自己覆盖doCommand方法然后在doCommand方法上加事务 | ||
* @param exchanger | ||
* @throws Exception | ||
* 2015年11月5日下午2:02:22 | ||
*/ | ||
@Override | ||
public void doCommand(Exchanger exchanger) throws Exception { | ||
ServiceMessage serviceMessage = (ServiceMessage)exchanger.getExchange(ChainConstants.DEFAULT_SERIVCEMESSAGE_KEY); | ||
doService(serviceMessage); | ||
} | ||
|
||
public abstract void doService(ServiceMessage serviceMessage) throws NSException; | ||
|
||
@Override | ||
public abstract String getLogStr(); | ||
|
||
public void stop(ServiceMessage serviceMessage,RetInfo retInfo) throws StopException | ||
{ | ||
ActionWorker.stop(serviceMessage, retInfo); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public void continueCurrentChain() | ||
{ | ||
Object isNotBreakChain = notBreakChain.get(); | ||
Boolean isNotBreak = true; | ||
Map<String,Boolean> isNotBreakChainMap = null; | ||
if (isNotBreakChain == null) | ||
{ | ||
isNotBreakChainMap = new HashMap<String, Boolean>(); | ||
|
||
notBreakChain.set(isNotBreakChainMap); | ||
} | ||
else | ||
{ | ||
isNotBreakChainMap = (Map<String,Boolean>)isNotBreakChain; | ||
} | ||
|
||
isNotBreakChainMap.put(this.getClass().getName(), isNotBreak); | ||
flowLog.debug("# 设置不中断标记 OK classname:{} isnotbreak:{} #", this.getClass().getName(),isNotBreak); | ||
} | ||
|
||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public boolean isNotBreak() { | ||
Object isNotBreakChain = notBreakChain.get(); | ||
Boolean isNotBreak = false; | ||
if (isNotBreakChain == null) | ||
{ | ||
isNotBreak = false; | ||
} | ||
else | ||
{ | ||
Map<String,Boolean> isNotBreakChainMap = (Map<String,Boolean>) isNotBreakChain; | ||
|
||
isNotBreak = isNotBreakChainMap.get(this.getClass().getName()); | ||
|
||
if(isNotBreak == null) | ||
{ | ||
isNotBreak = false; | ||
} | ||
} | ||
flowLog.debug("# 获取不中断标记 OK classname:{} isnotbreak:{} #", this.getClass().getName(),isNotBreak); | ||
return isNotBreak; | ||
|
||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
NS_CHAINS/src/main/java/com/creditease/ns/chains/chain/Chain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.creditease.ns.chains.chain; | ||
|
||
import com.creditease.ns.chains.constants.LoggerConstants; | ||
import com.creditease.ns.chains.exchange.Exchanger; | ||
import com.creditease.ns.log.NsLog; | ||
import com.creditease.ns.log.spi.LoggerWrapper; | ||
|
||
public interface Chain extends Command{ | ||
static NsLog flowLog = NsLog.getFlowLog("NsChainFlow", "NsChainFlow"); | ||
public void doChain(Exchanger exchanger) throws Exception; | ||
public void add(Command command); | ||
} |
23 changes: 23 additions & 0 deletions
23
NS_CHAINS/src/main/java/com/creditease/ns/chains/chain/ChainBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.creditease.ns.chains.chain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.creditease.ns.chains.constants.LoggerConstants; | ||
import com.creditease.ns.chains.def.CatalogDef; | ||
import com.creditease.ns.log.NsLog; | ||
import com.creditease.ns.log.spi.LoggerWrapper; | ||
|
||
public class ChainBuilder { | ||
|
||
public static Chain build(CatalogDef catalogDef) throws Exception | ||
{ | ||
List<Command> commands = new ArrayList<Command>(); | ||
catalogDef.tranverse(commands); | ||
DefaultChain chain = new DefaultChain(); | ||
chain.init(); | ||
chain.addAll(commands); | ||
Chain.flowLog.debug("ChainBuilder构建工作链 成功 catalogDef:{} chain中的命令数:{}", catalogDef.getId(),commands.size()); | ||
return chain; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
NS_CHAINS/src/main/java/com/creditease/ns/chains/chain/ChainFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.creditease.ns.chains.chain; | ||
|
||
|
||
public class ChainFactory { | ||
public static Chain getDefaultChain() | ||
{ | ||
return DefaultChainDispatcher.getInstance(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
NS_CHAINS/src/main/java/com/creditease/ns/chains/chain/Command.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.creditease.ns.chains.chain; | ||
|
||
import com.creditease.ns.chains.constants.LoggerConstants; | ||
import com.creditease.ns.chains.exchange.Exchanger; | ||
import com.creditease.ns.log.spi.LoggerWrapper; | ||
|
||
public interface Command { | ||
static String logPrefix = "[Command] "; | ||
public void doCommand(Exchanger exchanger) throws Exception; | ||
public boolean isNotBreak(); | ||
|
||
public String getLogStr(); | ||
} |
19 changes: 19 additions & 0 deletions
19
NS_CHAINS/src/main/java/com/creditease/ns/chains/chain/ConditionableCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.creditease.ns.chains.chain; | ||
|
||
import com.creditease.ns.chains.exchange.Exchanger; | ||
|
||
public interface ConditionableCommand extends Command{ | ||
|
||
//以下 所有位置 0 表示没有执行, 1表示执行 | ||
public static int INITEXECUTED = 0x01; //初始化状态 | ||
public static int IFEXECUTECAN = 0x03; //二进制 0011 倒数第二位,表示if执行状态 | ||
public static int ELIFEXECUTECAN = 0x05; //二进制 0101 | ||
public static int ELSEEXECUTECAN = 0x09; //二进制 1001 | ||
|
||
public static String IFELSE_FLAG_KEY = "_if_else_flag_key_"; | ||
|
||
public boolean canExecute(String cond,Exchanger exchanger); | ||
public String getCond(); | ||
public void setCond(String cond); | ||
|
||
} |
Oops, something went wrong.