我正在通过 Java(又名 JRules)使用 IBM 的 ILOG 7.1。我需要调试一些预先存在的功能,其中有一组正在执行的规则。只有一些应该执行的规则实际上在我的跟踪输出中。所以我想知道:
- 规则实际上没有得到执行吗?
- 规则只是没有作为跟踪的一部分输出吗?
我不知道。
我必须执行并记录跟踪规则的 Java 代码如下:
public RulesDTO executeRules(RulesDTO rulesDTO) {
try {
String sessionId = rulesDTO.getSessionId();
String clientIp = rulesDTO.getClientIp();
LOG.info("Starting to execute rules.");
String ruleSetName = rulesDTO.getRuleSetName();
IlrSessionRequest request = this.rulesSessionProvider
.createRequest(ruleSetName);
Map<String, Object> parNameToObjectMap = new HashMap<String, Object>();
parNameToObjectMap.put("params", rulesDTO);
parNameToObjectMap.put("timeOut",
getEngineExecutionTimeout());
request.setInputParameters(parNameToObjectMap);
boolean isTraceEnabled = true;
// Enable trace to retrieve info on executed rules
request.setTraceEnabled(isTraceEnabled);
// get all traces
request.getTraceFilter().setInfoAllFilters(isTraceEnabled);
IlrSessionResponse response = null;
try {
// calls ILOG engine, itself, to execute rules
response = executeRulesRequest(request, ruleSetName);
}
catch (TimeoutException te) {
LOG.error(String.format("Rules %s timed out [timeout=%d]",
ruleSetName, getEngineExecutionTimeout()));
throw te;
}
logRuleExecutions(rulesDTO.getID(), sessionId, response);
return rulesDTO;
}
catch (Throwable t) {
LOG.error("Rule set execution failed. ilogVersion=7.1", t);
throw new RulesException(
"Rule set execution failed. ilogVersion=7.1", t);
}
}
private void logRuleExecutions(
long searchId, String sessionId, IlrSessionResponse response) {
IlrExecutionTrace executionTrace = response.getRulesetExecutionTrace();
List<IlrExecutionEvent> executionEvents = executionTrace.getExecutionEvents();
// ExecutedRule is a custom class I have wrapping IlrExecutionEvent
List<ExecutedRule> executedRules = getRuleExecutions(executionEvents);
int numRulesExecuted = executedRules.size();
LOG.info("sessionId={}, SearchId={}, numRules={}",
new Object[] {sessionId, searchId, numRulesExecuted});
// loop over executedRules list and just log each one
logFilteredRules(executedRules, searchId, sessionId);
}
private List<ExecutedRule> getRuleExecutions(List<IlrExecutionEvent> executionEvents) {
List<ExecutedRule> executedRules = new LinkedList<ExecutedRule>();
for (IlrExecutionEvent event : executionEvents) {
if (event instanceof IlrRuleEvent) {
IlrRuleEvent ruleEvent = (IlrRuleEvent) event;
allRuleExecutions.add(convertToRuleExecution(ruleEvent));
}
else {
List<IlrExecutionEvent> subEvents = ((IlrTaskEvent) event).getSubExecutionEvents();
LOG.debug("Size of subEvents={}", subEvents.size());
List<ExecutedRule> executedSubRules = getRuleExecutions(subEvents);
executedRules.addAll(executedSubRules);
}
}
}
除了似乎只有一些规则被调用的事实之外,似乎只有更早的规则被调用,而不是应该在初始规则之后执行的规则。任何帮助将不胜感激。谢谢。:-)