Drools mvel方言drl断点调试方法

开发环境:myeclipse2014,  jdk1.8.0.91,drools6.4.0.Final, drools-eclipse-plugin,mvel2-2.2.6.Final
问题描述:drl使用Java方言的设置断点调试没有问题,但是用mvel方言出现异常:

java.lang.RuntimeException: no debugger registered to handle breakpoint
at org.mvel2.debug.DebuggerContext.checkBreak(DebuggerContext.java:)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:)
at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:)
at org.mvel2.MVEL.executeExpression(MVEL.java:)
at org.drools.core.util.MVELSafeHelper$RawMVELEvaluator.executeExpression(MVELSafeHelper.java:)
at org.drools.core.rule.constraint.MvelConditionEvaluator.evaluate(MvelConditionEvaluator.java:)
at org.drools.core.rule.constraint.MvelConditionEvaluator.evaluate(MvelConditionEvaluator.java:)
at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:)
at org.drools.core.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:)
at org.drools.core.reteoo.AlphaNode.assertObject(AlphaNode.java:)
at org.drools.core.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:)
at org.drools.core.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:)
at org.drools.core.reteoo.ObjectTypeNode.propagateAssert(ObjectTypeNode.java:)
at org.drools.core.phreak.PropagationEntry$Insert.execute(PropagationEntry.java:)
at org.drools.core.phreak.SynchronizedPropagationList.flush(SynchronizedPropagationList.java:)
at org.drools.core.phreak.SynchronizedPropagationList.flush(SynchronizedPropagationList.java:)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.flushPropagations(StatefulKnowledgeSessionImpl.java:)
at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:)
at org.drools.impl.adapters.StatefulKnowledgeSessionAdapter.fireAllRules(StatefulKnowledgeSessionAdapter.java:)
at step1.TestFibonacci.main(TestFibonacci.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.junit.runners.model.FrameworkMethod$.runReflectiveCall(FrameworkMethod.java:)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:)
at org.junit.runners.ParentRunner$.run(ParentRunner.java:)
at org.junit.runners.ParentRunner$.schedule(ParentRunner.java:)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:)
at org.junit.runners.ParentRunner.access$(ParentRunner.java:)
at org.junit.runners.ParentRunner$.evaluate(ParentRunner.java:)
at org.junit.runners.ParentRunner.run(ParentRunner.java:)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:)

使用“no debugger registered to handle breakpoint”作为关键字google,有两篇提出同样问题的,但是没有答案,后陆续变换关键字,终于找到一篇神贴:

http://www.programcreek.com/java-api-examples/index.php?api=org.mvel2.debug.Debugger

关键在这段:

final List<String> knownVariables = new ArrayList<String>();
MVELRuntime.resetDebugger();
MVELDebugHandler.setDebugMode(true);
MVELRuntime.setThreadDebugger(new Debugger() {
public int onBreak(Frame frame) {
System.out.println("onBreak");
for (String var: frame.getFactory().getKnownVariables()) {
System.out.println(" " + var);
knownVariables.add(var);
}
return ;
}
});
MVELRuntime.setThreadDebugger将Debugger赋值,单元测试就能实现断点调试了。
上一篇:autotrace显示Statistics很多信息为0(转)


下一篇:troubshooting-sqoop 导出 TiDB表数据报com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure