论坛首页 Java版 企业应用

使用Drools后的疑问

浏览 851 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2008-02-02 关键字: drools规则引擎
由于工作所需,最近调研并使用了drools规则引擎.有个疑问想请大家一起说说:

假设事实库中事实a与规则库中规则A,B,C匹配.
现在ActionA调用了业务类ServiceA,业务类ServiceA核心代码是:
public class ServiceA
{
........
try
{
   WorkingMemory workingMemory = ruleBase.newWorkingMemory();
   workingMemory.assertObject(a);
   workingMemory.fireAllRules();
}
catch(Exception e)
{
    //欲捕捉异常进行处理
     
}
..........
}
由ServiceA启动了规则引擎进行模式匹配后最终规则A,B,C被执行.

现在疑问是:
当规则B,C执行过程中发生异常,欲在ServiceA中捕捉到异常进行相应的处理.可事实是在ServiceA中捕捉不到异常.

不知道,大家都是用什么方式来处理drools的异常?Drools在这方面有没有很好的支持?谢谢!
   
最后更新时间:2008-02-02
znj 写道


当规则B,C执行过程中发生异常,欲在ServiceA中捕捉到异常进行相应的处理.可事实是在ServiceA中捕捉不到异常.

不知道,大家都是用什么方式来处理drools的异常?Drools在这方面有没有很好的支持?谢谢!

因为drools设计时将FactException,设计为运行时异常
public class FactException extends RuntimeDroolsException {
......

以下是WorkingMemory 里的fireAllRules 方法定义
 /**
     * Fire all items on the agenda until empty.
     * 
     * @throws FactException
     *             If a RuntimeException error occurs.
     */
    void fireAllRules() throws FactException;

    /**
     * Fire all items on the agenda until empty, using the given AgendaFiler
     * 
     * @throws FactException
     *             If a RuntimeException error occurs.
     */
    void fireAllRules(AgendaFilter agendaFilter) throws FactException;
      
    /**
     * Fire all items on the agenda until empty or at most 'fireLimit' rules have fired
     * 
     * @throws FactException
     *             If a RuntimeException error occurs.
     */
    void fireAllRules( int fireLimit ) throws FactException;

    /**
     * Fire all items on the agenda using the given AgendaFiler
     * until empty or at most 'fireLimit' rules have fired
     * 
     * @throws FactException
     *             If a RuntimeException error occurs.
     */
    void fireAllRules(final AgendaFilter agendaFilter, int fireLimit ) throws FactException;


使用规则引擎时候的异常更多还是来自外部,而非引擎本身
比如 规则 语法不对
action里调用的其他方法有问题
   
0 请登录后投票
最后更新时间:2008-02-02
规则 B,C是怎么执行的?
一般捕获的到,除非另起线程执行抛了异常。
   
0 请登录后投票
最后更新时间:2008-03-19
我也遇到此类问题。可以确定的是规则引擎内部是没问题的。及有可能是外部因素(对象模型)在DROOLS 内做相关处理时遇到空指针问题而导致。

  但整个工程在执行时只是报了一个“空指針异常”没有明确指出是“org.drools.RuntimeDroolsException: java.lang.NullPointerException”
  
   
0 请登录后投票
论坛首页 Java版 企业应用

跳转论坛:
JavaEye推荐