Commit b370961e by s_guodong

流程控制和日志打印

parent 14788401
...@@ -61,20 +61,24 @@ public abstract class AbstractAutoCompileEmitter extends AbstractRuleEmitter { ...@@ -61,20 +61,24 @@ public abstract class AbstractAutoCompileEmitter extends AbstractRuleEmitter {
continue; continue;
} }
try { try {
boolean b = true;
switch (ruleItem.getRuleType()) { switch (ruleItem.getRuleType()) {
case RuleItem.INIT: case RuleItem.INIT:
execInitItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot())); b = execInitItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot()));
break; break;
case RuleItem.CHECK: case RuleItem.CHECK:
execCheckItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot())); b = execCheckItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot()));
break; break;
case RuleItem.DEFAULT: case RuleItem.DEFAULT:
execDefaultItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot())); b = execDefaultItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot()));
break; break;
case RuleItem.RULE: case RuleItem.RULE:
execRuleItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot())); b = execRuleItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot()));
break; break;
} }
if (!b) {
return false;
}
} catch (Exception e) { } catch (Exception e) {
log.error("execute Rule Exception", e); log.error("execute Rule Exception", e);
throw e; throw e;
...@@ -164,6 +168,7 @@ public abstract class AbstractAutoCompileEmitter extends AbstractRuleEmitter { ...@@ -164,6 +168,7 @@ public abstract class AbstractAutoCompileEmitter extends AbstractRuleEmitter {
boolean result = invokeRuleList(RuleItem.CHECK, entry.getKey(), order); boolean result = invokeRuleList(RuleItem.CHECK, entry.getKey(), order);
if (!result) { if (!result) {
log.warn(String.format("execute @Check[%s,%d] return false", entry.getKey(), order)); log.warn(String.format("execute @Check[%s,%d] return false", entry.getKey(), order));
return false;
} }
} }
return true; return true;
......
...@@ -109,7 +109,7 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter { ...@@ -109,7 +109,7 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
protected boolean checkPathMatch(String path, String target) { protected boolean checkPathMatch(String path, String target) {
if(target.startsWith("\\")){ if (target.startsWith("\\")) {
target = target.substring(1).toLowerCase(); target = target.substring(1).toLowerCase();
} }
int targetLen = target.length(); int targetLen = target.length();
...@@ -322,7 +322,7 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter { ...@@ -322,7 +322,7 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
Boolean result = executeInit(-1); Boolean result = executeInit(-1);
return result; return result;
} catch (RuleExitException e) { } catch (RuleExitException e) {
throw new RuleExecuteException("Init执行返回false", e); throw new RuleExecuteException("Init执行异常", e);
// return false; // return false;
} catch (Exception ex) { } catch (Exception ex) {
DCR.emptyDefaultQueue(); DCR.emptyDefaultQueue();
...@@ -346,7 +346,7 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter { ...@@ -346,7 +346,7 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
} }
} }
public void execInitItem(int order, String path, Ruleable<Boolean> ruleHolder) { public boolean execInitItem(int order, String path, Ruleable<Boolean> ruleHolder) {
boolean ignore = false; boolean ignore = false;
if (ruleHolder instanceof RuleItemExecutor) { if (ruleHolder instanceof RuleItemExecutor) {
RuleItemExecutor executor = (RuleItemExecutor) ruleHolder; RuleItemExecutor executor = (RuleItemExecutor) ruleHolder;
...@@ -365,14 +365,16 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter { ...@@ -365,14 +365,16 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
if (!ruleHolder.exec()) { if (!ruleHolder.exec()) {
stopWatch.stop(); stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execInitItem", path, order); addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execInitItem", path, order);
throw new RuleExitException(String.format("%s init %d %s exit", MdaEnv.getContext().getTransName(), order, path)); // throw new RuleExitException(String.format("%s init %d %s exit", MdaEnv.getContext().getTransName(), order, path));
return false;
} }
stopWatch.stop(); stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execInitItem", path, order); addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execInitItem", path, order);
} }
return true;
} }
public void execRuleItem(int order, String path, Ruleable<Boolean> ruleHolder) { public boolean execRuleItem(int order, String path, Ruleable<Boolean> ruleHolder) {
boolean ignore = false; boolean ignore = false;
String eventPath = MdaEnv.getContext().getEventPath(); String eventPath = MdaEnv.getContext().getEventPath();
if (ruleHolder instanceof RuleItemExecutor) { if (ruleHolder instanceof RuleItemExecutor) {
...@@ -394,7 +396,8 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter { ...@@ -394,7 +396,8 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
if (!b) { if (!b) {
stopWatch.stop(); stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execRuleItem", path, order); addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execRuleItem", path, order);
throw new RuleExitException(String.format("%s rule %d %s exit", MdaEnv.getContext().getTransName(), order, eventPath)); return false;
// throw new RuleExitException(String.format("%s rule %d %s exit", MdaEnv.getContext().getTransName(), order, eventPath));
} }
if (MdaEnv.getContext().getFieldErrors().size() > oldLength) { if (MdaEnv.getContext().getFieldErrors().size() > oldLength) {
log.warn("{} rule [{}] [{}] set fieldError", MdaEnv.getContext().getTransName(), order, eventPath); log.warn("{} rule [{}] [{}] set fieldError", MdaEnv.getContext().getTransName(), order, eventPath);
...@@ -402,10 +405,11 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter { ...@@ -402,10 +405,11 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
stopWatch.stop(); stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execRuleItem", path, order); addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execRuleItem", path, order);
} }
return true;
//log.debug("rule [{}] [{}] finished",order,eventPath); //log.debug("rule [{}] [{}] finished",order,eventPath);
} }
public void execCheckItem(int order, String path, Ruleable<Boolean> ruleHolder) { public boolean execCheckItem(int order, String path, Ruleable<Boolean> ruleHolder) {
boolean ignore = false; boolean ignore = false;
String eventPath = MdaEnv.getContext().getEventPath(); String eventPath = MdaEnv.getContext().getEventPath();
if (ruleHolder instanceof RuleItemExecutor) { if (ruleHolder instanceof RuleItemExecutor) {
...@@ -426,7 +430,8 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter { ...@@ -426,7 +430,8 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
if (!ruleHolder.exec()) { if (!ruleHolder.exec()) {
stopWatch.stop(); stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execCheckItem", path, order); addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execCheckItem", path, order);
throw new RuleExitException(String.format("check [%d] [%s] exit", order, eventPath)); // throw new RuleExitException(String.format("check [%d] [%s] exit", order, eventPath));
return false;
} }
if (MdaEnv.getContext().getFieldErrors().size() > oldLength) { if (MdaEnv.getContext().getFieldErrors().size() > oldLength) {
log.warn(String.format("%s check [%d] [%s] set fieldError", MdaEnv.getContext().getTransName(), order, eventPath)); log.warn(String.format("%s check [%d] [%s] set fieldError", MdaEnv.getContext().getTransName(), order, eventPath));
...@@ -435,9 +440,10 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter { ...@@ -435,9 +440,10 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execCheckItem", path, order); addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execCheckItem", path, order);
//log.debug("check [{}] [{}] finished",order,eventPath); //log.debug("check [{}] [{}] finished",order,eventPath);
} }
return true;
} }
public void execDefaultItem(int order, String path, Ruleable<Boolean> ruleHolder) { public boolean execDefaultItem(int order, String path, Ruleable<Boolean> ruleHolder) {
boolean ignore = false; boolean ignore = false;
String eventPath = MdaEnv.getContext().getEventPath(); String eventPath = MdaEnv.getContext().getEventPath();
if (ruleHolder instanceof RuleItemExecutor) { if (ruleHolder instanceof RuleItemExecutor) {
...@@ -457,12 +463,14 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter { ...@@ -457,12 +463,14 @@ public abstract class AbstractRuleEmitter implements IRuleEmitter {
if (!ruleHolder.exec()) { if (!ruleHolder.exec()) {
stopWatch.stop(); stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execDefaultItem", path, order); addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execDefaultItem", path, order);
throw new RuleExitException(String.format("%s default [%d] [%s] exit", MdaEnv.getContext().getTransName(), order, eventPath)); // throw new RuleExitException(String.format("%s default [%d] [%s] exit", MdaEnv.getContext().getTransName(), order, eventPath));
return false;
} }
stopWatch.stop(); stopWatch.stop();
addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execDefaultItem", path, order); addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execDefaultItem", path, order);
//log.debug("default [{}] [{}] finished",order,eventPath); //log.debug("default [{}] [{}] finished",order,eventPath);
} }
return true;
} }
public List<IModuleList> getAllModuleList() { public List<IModuleList> getAllModuleList() {
......
...@@ -157,19 +157,26 @@ public abstract class AbstractRouteService<V extends BaseVO> { ...@@ -157,19 +157,26 @@ public abstract class AbstractRouteService<V extends BaseVO> {
try { try {
StopWatch stopWatch = new StopWatch("executeCheck:" + StringUtils.join(rulePathArr, ',')); StopWatch stopWatch = new StopWatch("executeCheck:" + StringUtils.join(rulePathArr, ','));
stopWatch.start("enterTransaction"); stopWatch.start("enterTransaction");
enterTransaction(req); boolean b = enterTransaction(req);
stopWatch.stop(); stopWatch.stop();
IContext ctx = MdaEnv.getContext(); IContext ctx = MdaEnv.getContext();
if (!b) {
return new ResponseSet<V>(ctx, req);
}
synchronized (ctx) { synchronized (ctx) {
stopWatch.start("setValueFromVO"); stopWatch.start("setValueFromVO");
setValueFromVO(req); setValueFromVO(req);
stopWatch.stop(); stopWatch.stop();
stopWatch.start("executeStepWithCheckList"); stopWatch.start("executeStepWithCheckList");
executeStepWithCheckList(rulePathArr); boolean[] step = executeStepWithCheckList(rulePathArr);
stopWatch.stop(); stopWatch.stop();
boolean continueFlag = summarizeResult(step);
if (!continueFlag) {
return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage(), req);
}
stopWatch.start("afterExecute"); stopWatch.start("afterExecute");
boolean result = ctx.getFieldErrors().size() <= 0; boolean result = ctx.getFieldErrors().size() <= 0;
afterExecute(rulePathArr); afterExecute(rulePathArr);
...@@ -199,10 +206,13 @@ public abstract class AbstractRouteService<V extends BaseVO> { ...@@ -199,10 +206,13 @@ public abstract class AbstractRouteService<V extends BaseVO> {
try { try {
StopWatch stopWatch = new StopWatch("executeRule:" + StringUtils.join(rulePathArr, ',')); StopWatch stopWatch = new StopWatch("executeRule:" + StringUtils.join(rulePathArr, ','));
stopWatch.start("enterTransaction"); stopWatch.start("enterTransaction");
enterTransaction(req); boolean b = enterTransaction(req);
stopWatch.stop(); stopWatch.stop();
IContext ctx = MdaEnv.getContext(); IContext ctx = MdaEnv.getContext();
if (!b) {
return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage(), req);
}
synchronized (ctx) { synchronized (ctx) {
stopWatch.start("setValueFromVO"); stopWatch.start("setValueFromVO");
setValueFromVO(req); setValueFromVO(req);
...@@ -212,6 +222,11 @@ public abstract class AbstractRouteService<V extends BaseVO> { ...@@ -212,6 +222,11 @@ public abstract class AbstractRouteService<V extends BaseVO> {
boolean[] step = executeStepWithRuleList(rulePathArr); boolean[] step = executeStepWithRuleList(rulePathArr);
stopWatch.stop(); stopWatch.stop();
boolean continueFlag = summarizeResult(step);
if (!continueFlag) {
return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage(), req);
}
// checkAll时对ModuleList进行check // checkAll时对ModuleList进行check
if (rulePathArr.length == 1 && CHEK_PATH.equals(rulePathArr[0])) { if (rulePathArr.length == 1 && CHEK_PATH.equals(rulePathArr[0])) {
stopWatch.start("executeCheckAll"); stopWatch.start("executeCheckAll");
...@@ -240,14 +255,13 @@ public abstract class AbstractRouteService<V extends BaseVO> { ...@@ -240,14 +255,13 @@ public abstract class AbstractRouteService<V extends BaseVO> {
//return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage(), ctx.getFieldErrors()); //return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage(), ctx.getFieldErrors());
} }
} catch (Exception e) { } catch (Exception e) {
// throw new RuleExecuteException(e.getMessage(), e); return ResponseSet.fail(e.getMessage());
IContext ctx = MdaEnv.getContext();
return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage());
} finally { } finally {
DCR.emptyDefaultQueue(); DCR.emptyDefaultQueue();
} }
} }
/** /**
* 执行defaultRule * 执行defaultRule
*/ */
...@@ -328,16 +342,11 @@ public abstract class AbstractRouteService<V extends BaseVO> { ...@@ -328,16 +342,11 @@ public abstract class AbstractRouteService<V extends BaseVO> {
/** /**
* 初始化步骤 * 初始化步骤
*/ */
public void initTrans(V req) { public boolean initTrans(V req) {
IContext ctx = MdaEnv.getContext(); IContext ctx = MdaEnv.getContext();
if (req != null) { if (req != null) {
ctx.setVo(req); ctx.setVo(req);
} }
// if (!req.isNeedInit()) {
// logger.info("不需要初始化");
// return;
// }
// logger.info("开始初始化...");
StopWatch watch = new StopWatch("initTrans"); StopWatch watch = new StopWatch("initTrans");
IRuleEmitter emitter = getEmitter(); IRuleEmitter emitter = getEmitter();
//将认证信息(usr、usg、ety)放入sysStream //将认证信息(usr、usg、ety)放入sysStream
...@@ -349,8 +358,12 @@ public abstract class AbstractRouteService<V extends BaseVO> { ...@@ -349,8 +358,12 @@ public abstract class AbstractRouteService<V extends BaseVO> {
//一阶段,构造与初始化 //一阶段,构造与初始化
// DCR.emptyDefaultQueue(); // DCR.emptyDefaultQueue();
watch.start("executeInit"); watch.start("executeInit");
emitter.executeInit(); // 执行初始 boolean b = emitter.executeInit();// 执行初始
watch.stop(); watch.stop();
// 初始化返回false就不往下执行了
if (!b) {
return false;
}
DCR.enNotify(true); DCR.enNotify(true);
watch.start("executeDefaultAfterInit"); watch.start("executeDefaultAfterInit");
emitter.executeDefaultAfterInit(); emitter.executeDefaultAfterInit();
...@@ -362,6 +375,7 @@ public abstract class AbstractRouteService<V extends BaseVO> { ...@@ -362,6 +375,7 @@ public abstract class AbstractRouteService<V extends BaseVO> {
logger.info(watch.prettyPrint()); logger.info(watch.prettyPrint());
//执行Default //执行Default
DCR.executeQueue(); DCR.executeQueue();
return true;
} }
/** /**
...@@ -393,6 +407,9 @@ public abstract class AbstractRouteService<V extends BaseVO> { ...@@ -393,6 +407,9 @@ public abstract class AbstractRouteService<V extends BaseVO> {
String path = ruleList[i]; String path = ruleList[i];
Argument<String> pathBox = Argument.box(path); Argument<String> pathBox = Argument.box(path);
result[i] = getEmitterByPath(pathBox).executeRule(pathBox.value); result[i] = getEmitterByPath(pathBox).executeRule(pathBox.value);
if (!result[i]) {
return result;
}
//todo 判断是否列表数据,例如机构选择,如果是则不执行后续的default, //todo 判断是否列表数据,例如机构选择,如果是则不执行后续的default,
Map<String, Object> gridData = MdaEnv.getGridData(); Map<String, Object> gridData = MdaEnv.getGridData();
if (gridData != null && ruleList.length == 1) { if (gridData != null && ruleList.length == 1) {
...@@ -417,6 +434,9 @@ public abstract class AbstractRouteService<V extends BaseVO> { ...@@ -417,6 +434,9 @@ public abstract class AbstractRouteService<V extends BaseVO> {
String path = ruleList[i]; String path = ruleList[i];
Argument<String> pathBox = Argument.box(path); Argument<String> pathBox = Argument.box(path);
result[i] = getEmitterByPath(pathBox).executeCheck(pathBox.value); result[i] = getEmitterByPath(pathBox).executeCheck(pathBox.value);
if (!result[i]) {
return result;
}
//执行Default //执行Default
DCR.executeQueue(); DCR.executeQueue();
executeAndClearPostQueue(); executeAndClearPostQueue();
...@@ -476,7 +496,7 @@ public abstract class AbstractRouteService<V extends BaseVO> { ...@@ -476,7 +496,7 @@ public abstract class AbstractRouteService<V extends BaseVO> {
} }
ctx.storeData(IContext.DISPLAY_KEY, req); ctx.storeData(IContext.DISPLAY_KEY, req);
initTrans(req); return initTrans(req);
} }
return true; return true;
} }
...@@ -490,4 +510,13 @@ public abstract class AbstractRouteService<V extends BaseVO> { ...@@ -490,4 +510,13 @@ public abstract class AbstractRouteService<V extends BaseVO> {
// DCR.executeQueue(false); // DCR.executeQueue(false);
beforeExecute(); beforeExecute();
} }
private boolean summarizeResult(boolean[] step) {
for (boolean b : step) {
if (!b) {
return b;
}
}
return true;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment