KnowledgeAgent custom class loader not working for PKG resources
by Hrumph
I believe there may be a bug when trying to use a custom class loader with
the KnowledgeAgent and the KnowledgeBuilderConfiguration, and when the
ChangeSet is a PKG resource.
I have been trying to get the knowledge-agent-classloader sample from the
new Drools Cookbook to work with a PKG resource. The sample works fine for
a DRL resource, but when I convert it to use my fact jar, and a PKG resource
containing my rules, which I downloaded from Guvnor, it throws a
ClassNotFoundException for my fact model. If I put my fact model in the
classpath, the error goes away and my rules can be added to the
KnowledgeAgent and run correctly. Following is the code from the sample
that I have converted, and I have attached a zip file with a complete
project demonstrating the problem. Also, I can get my rules and fact
model to work if I use a DRL ChangeSet.knowledge-agent-classloader.zip
URL modelJarURL = getClass().getResource("Patient-1.0.jar");
URLClassLoader customURLClassloader = new URLClassLoader(new URL[]
{modelJarURL });
KnowledgeBuilderConfiguration kbuilderConfig =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null,
customURLClassloader);
KnowledgeBaseConfiguration kbaseConfig =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null,
customURLClassloader);
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase(kbaseConfig);
KnowledgeAgentConfiguration aconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("test", kbase, aconf,
kbuilderConfig);
// kagent.applyChangeSet(new ClassPathResource("change-set.xml",
getClass())); // this goes with model.jar
// kagent.applyChangeSet(new ClassPathResource("drl-change-set.xml",
getClass())); // this goes with Patient.jar
kagent.applyChangeSet(new ClassPathResource("pkg-change-set.xml",
getClass())); // this goes with Patient.jar
return kagent.getKnowledgeBase();
Following is the stack trace from the error:
java.lang.NullPointerException
at
org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:148)
at
org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:1016)
at
org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:785)
at
org.drools.agent.impl.KnowledgeAgentImpl.buildKnowledgeBase(KnowledgeAgentImpl.java:657)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:190)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:169)
at
drools.cookbook.chapter02.KnowledgeAgentClassloaderTest.createKnowledgeBase(KnowledgeAgentClassloaderTest.java:59)
at
drools.cookbook.chapter02.KnowledgeAgentClassloaderTest.customClassloaderTest(KnowledgeAgentClassloaderTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at
org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at
org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at
org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at
org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
I have been having the exact same problem when trying to use a custom class
loader with just a KnowldegeBuilder and no KnowledgeAgent.
http://drools.46999.n3.nabble.com/file/n3746456/knowledge-agent-classload...
knowledge-agent-classloader.zip
--
View this message in context: http://drools.46999.n3.nabble.com/KnowledgeAgent-custom-class-loader-not-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Globals - delegate
by Wolfgang Laun
This is from Expert (5.4.0):
Using a delegate is another way of global resolution. Assigning a
value to a global (with setGlobal(String, Object)) results in the
value being stored in an internal collection mapping identifiers to
values. Identifiers in this internal collection will have priority
over any supplied delegate. Only if an identifier cannot be found in
this internal collection, the delegate global (if any) will be used.
For setting a delegate, I've found org.drools.runtime.Globals and
void Globals.setDelegate(Globals delegate)
and the KnowledgeRuntime /StatelessKnowledgeSession method
Globals getGlobals()
Does this mean that one might take a Globals object from one session
and use it as a delegate to the Globals of another session?
(Evil thought:
Globals a = sessionA.getGlobals();
Globals b = sessionB.getGlobals();
a.setDelegate( b );
b.setDelegate( a );
What happens then?)
-W
13 years, 9 months
GUVNOR 5.4 JBOSS v4.2.3 deployment error
by abhinay_agarwal
hey,
i was trying to upgrade from guvnor 5.3.0 to 5.4 when i pasted the guvnor
war into the deployment folder and restarted the server it throwed an error
2012-06-29 10:06:52,163 DEBUG [org.jboss.web.WebModule] Starting failed
jboss.web.deployment:war=drools-guvnor.war,id=-1487681113
org.jboss.deployment.DeploymentException: Error during deploy; - nested
throwable: (javax.naming.NamingException: resource-env-ref: BeanManager has
no valid JNDI binding. Check the jboss-web/resource-env-ref.)
i know its some binding error in jboss but any help would be appreciated !!
Thanks in advance,
Abhinay
--
View this message in context: http://drools.46999.n3.nabble.com/GUVNOR-5-4-JBOSS-v4-2-3-deployment-erro...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Hibernate Configuration with Drools 5.4
by zeeshan
Hi All !
I want to use Hibernate for database persistence in my drools project.
Please suggest me the steps. I am using 5.4.0 final version. Which version
of hibernate I shall use whether 3.1 or Annotation one.....?? I have idea
about 3.1. Actually I am having 50,000 records in one of my Decision table,
so it is taking too much time to give the result. Now I have decided to use
move this to database. So please tell me configuration steps.
Thanks !!
--
View this message in context: http://drools.46999.n3.nabble.com/Hibernate-Configuration-with-Drools-5-4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
NullPointerException using 'enabled' function.
by groovenarula
I'm trying to use the enabled function to ensure that some rules only fire
under certain conditions.
I have the following in my DRL :
rule "Load pricelist"
salience 10000
when
$unitPrice : Pricelist() from PricelistUtilities.getPriceLists()
then
insert ($unitPrice);
end
rule "Retract a priced unit"
salience 5000
when
$priceUnit : PriceUnit( basePrice != null )
then
System.out.println("Retracting ..." + $priceUnit);
retract ( $priceUnit );
end
rule "Price Unit by Prodid, Grade, Pattern, Color"
enabled ( $detailPrice == true )
salience 2500
when
$priceUnit : PriceUnit ( $detailPrice : detailPrice )
$priceList : Pricelist( prodid == $priceUnit.prodid, coverGrade ==
$priceUnit.coverGrade, coverSeries == $priceUnit.coverSeries, coverColor ==
$priceUnit.coverColor )
then
modify ( $priceUnit ) {
setBasePrice ( $priceList.getBasePrice() );
}
end
rule "Price Unit by Prodid, Grade, Pattern"
enabled ( $detailPrice == true )
salience 2000
when
$priceUnit : PriceUnit ( $detailPrice : detailPrice )
$priceList : Pricelist( prodid == $priceUnit.prodid, coverGrade ==
$priceUnit.coverGrade , coverSeries == $priceUnit.coverSeries )
then
modify ( $priceUnit ) {
setBasePrice ( $priceList.getBasePrice() );
}
end
rule "Price Unit by Prodid, Grade, Pattern 0000"
salience 1500
when
$priceUnit : PriceUnit ( )
$priceList : Pricelist( prodid == $priceUnit.prodid, coverGrade ==
$priceUnit.coverGrade , coverSeries == "0000" )
then
System.out.println("Pricing unit : " + $priceUnit + " from " +
$priceList);
$priceUnit.setBasePrice($priceList.getBasePrice());
update ( $priceUnit );
end
Before adding the 'enabled' conditions to the rules, it all worked fine. But
after adding the 'enabled' function, I'm getting the following NullPointer
exception :
Exception executing consequence for rule "Price Unit by Prodid, Grade,
Pattern 0000" in com.sample: java.lang.NullPointerException
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1283)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1209)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1442)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
at com.generic.rules.utils.DroolsTest.main(DroolsTest.java:37)
Caused by: java.lang.NullPointerException
at org.drools.common.DefaultAgenda.createActivation(DefaultAgenda.java:569)
at
org.drools.reteoo.RuleTerminalNode.modifyLeftTuple(RuleTerminalNode.java:297)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateModifyChildLeftTuple(SingleLeftTupleSinkAdapter.java:246)
at org.drools.reteoo.JoinNode.modifyLeftTuple(JoinNode.java:363)
at
org.drools.reteoo.LeftTupleSource.doModifyLeftTuple(LeftTupleSource.java:297)
at
org.drools.reteoo.LeftTupleSource.modifyLeftTuple(LeftTupleSource.java:271)
at org.drools.reteoo.JoinNode.modifyLeftTuple(JoinNode.java:429)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.doPropagateModifyObject(CompositeLeftTupleSinkAdapter.java:260)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.propagateModifyObject(CompositeLeftTupleSinkAdapter.java:275)
at
org.drools.reteoo.LeftInputAdapterNode.modifyObject(LeftInputAdapterNode.java:170)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
at org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
at org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:470)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:370)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:317)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:312)
at
com.sample.Rule_Price_Unit_by_Prodid__Grade__Pattern_0000_8fe2d406670448989b7e4f1e051a27e9.defaultConsequence(Rule_Price_Unit_by_Prodid__Grade__Pattern_0000_8fe2d406670448989b7e4f1e051a27e9.java:9)
at
com.sample.Rule_Price_Unit_by_Prodid__Grade__Pattern_0000_8fe2d406670448989b7e4f1e051a27e9DefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
at
com.sample.Rule_Price_Unit_by_Prodid__Grade__Pattern_0000_8fe2d406670448989b7e4f1e051a27e9DefaultConsequenceInvoker.evaluate(Unknown
Source)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1273)
... 6 more
In the console I also see the results of my System.out.println :
Pricing unit : PriceUnit [prodid=001001, coverGrade= A, coverSeries=1234,
coverColor=05, basePrice=null] from Pricelist [prodid=001001, cover=
A0000null, basePrice=599]
The only 'null' is $priceUnit.basePrice, which is what I'm trying to set.
I only get the exception when the 'detailedPrice' of PriceUnit is set to
false (i.e. when "Price Unit by Prodid, Grade, Pattern 0000" is attempting
to fire. If I set detailedPrice to true, the other rules fire just fine.
If I comment out the 'update ( $priceUnit );', the consequence fires just
fine, but then other rules fire as well. When PriceUnit's pattern is set to
anything other than '1234', then too consequence of ""Price Unit by Prodid,
Grade, Pattern 0000"" rule fires just fine and I get the following output
(correctly so) :
Pricing unit : PriceUnit [prodid=001001, coverGrade= A, coverSeries=3456,
coverColor=05, basePrice=null] from Pricelist [prodid=001001, cover=
A0000null, basePrice=599]
Retracting ...PriceUnit [prodid=001001, coverGrade= A, coverSeries=3456,
coverColor=05, basePrice=599]
What is causing the 'NullPointerException' ?
I'm using Drools 5.4.0.
Please help.
G
--
View this message in context: http://drools.46999.n3.nabble.com/NullPointerException-using-enabled-func...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Drools Performance
by elena_nardini@libero.it
Hi,
I am wondering about using Drools rule engine.
I have to threat with a large data set, so I would like to know about rule
engine performance.
Could someone help me?
Thanks a lot,
Elena
13 years, 9 months