我的ILOG规则被调用了,还是我的ILOG跟踪问题?

时间:2015-10-21 07:03:37

标签: java rule-engine business-rules ilog jrules

我通过Java(又名JRules)使用IBM的ILOG 7.1。我需要调试一些预先存在的功能,其中有一组规则正在执行。只有一些应该执行的规则实际上在我的跟踪输出中。所以我想知道:

  1. 规则是否实际上没有执行?
  2. 规则是否只是作为跟踪的一部分输出?
  3. 我不确定。

    我必须执行并记录跟踪规则的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);
            }
        }
    }
    

    除了事实上只有一些规则似乎被调用之外,似乎只调用了早期的规则,而不是在初始规则之后应该执行的规则。任何帮助将不胜感激。谢谢。 : - )

0 个答案:

没有答案