<div dir="ltr">Joseph,<div><br></div><div>Concerning the KieSession, here is the response :</div><div><br></div><div><div>What is the difference if I create a session on KieContainer vs KieBase (Global, Local List ...) ?</div>
<div>there shouldn't be any difference. the possibility of creating a session from a KieContainer is just a shortcut. under the hood it retrieves the KieBase in which that KieSession has been defined (or build it if you're using it for the first time) and then creates the KieSession from there</div>
<div><br></div><div>Regards,</div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jan 24, 2014 at 8:38 AM, Charles Moulliard <span dir="ltr"><<a href="mailto:ch007m@gmail.com" target="_blank">ch007m@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">Hi Joseph,</span><div class="im">
<div><font face="arial, sans-serif"><br></font></div><div><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">1. I need to rebuild the rules on the fly, so I was using examples from</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">the IncrementalCompilationTest.</span><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">java</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px"><</span><a href="https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/compiler/integrationtests/IncrementalCompilationTest.java" style="font-family:arial,sans-serif;font-size:12.727272033691406px" target="_blank">https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/compiler/integrationtests/IncrementalCompilationTest.java</a><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">></span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">to accomplish that task. However, those tests don't use a classpath</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">container... can I still rebuild a KieModule via runtime code when running</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">in a classpathContainer?</span></div><div><br></div></div><div>>> <span style="font-family:arial,sans-serif;font-size:12.727272033691406px">My example uses this META-INF/kmodules.xml file to let the KieContainer to scan and discover the resources (.drl, pacjkages) when we call </span></div>
<div><br></div><div><pre style="margin-top:0px;margin-bottom:0px"><div style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:18px;padding-left:10px">
<span> KieContainer</span> <span>kcont</span> <span style="font-weight:bold">=</span> <span>ks</span><span style="font-weight:bold">.</span><span style="color:teal">newKieClasspathContainer</span><span style="font-weight:bold">(</span><span>getClass</span><span style="font-weight:bold">().</span><span style="color:teal">getClassLoader</span><span style="font-weight:bold">());</span></div>
<div style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:18px;padding-left:10px"> <span>KieBase</span> <span>kbase</span> <span style="font-weight:bold">=</span> <span>kcont</span><span style="font-weight:bold">.</span><span style="color:teal">getKieBase</span><span style="font-weight:bold">(</span><span style="color:rgb(221,17,68)">"sampleKBase"</span><span style="font-weight:bold">);</span></div>
<div style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:18px;padding-left:10px"><span style="font-weight:bold;font-size:12px"><br></span></div>
<div style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:18px;padding-left:10px"><span style="font-weight:bold;font-size:12px">As you have mentioned in your email, this is a static approach as we load the resources before to create a KieSession and fire the rules.</span><br>
</div><div style="padding-left:10px"><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:18px;font-weight:bold">To be able to do increment, the approach that you mention is the way to go. I have also created an example where the KieModule is created using a programming approach --> </span><font color="#333333" face="Consolas, Liberation Mono, Courier, monospace"><span style="line-height:18px"><b><a href="https://github.com/cmoulliard/droolsjbpm-osgi-examples/blob/master/simple-external-resource/src/main/java/org/drools/example/osgi/FetchExternalResourceOsgiActivator.java" target="_blank">https://github.com/cmoulliard/droolsjbpm-osgi-examples/blob/master/simple-external-resource/src/main/java/org/drools/example/osgi/FetchExternalResourceOsgiActivator.java</a>. That should not be difficult to adapt it to support increment</b></span></font><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:18px;font-weight:bold"> </span></div>
<div style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:18px;padding-left:10px"><span style="font-weight:bold"><br></span></div>
</pre><div class="im"><br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">2. Your example code calls .newKieSession() on a kbase object as opposed to</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">a kContainer object. Is there a reason why? If I create a new KieSession</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">from a kbase vs. kContainer, will I still be able to rebuild the kjar</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">dynamically in the code and keep using the same stateful session?</span></div></div><div><br></div><div>I need that Mario Fusco or Marc Proctor confirm what I will say here (or somebody) else but I suspect that if you create a session on the KieContainer level and not on the KieBase could allow you to support increment as this unit test show you (<a href="https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/compiler/integrationtests/IncrementalCompilationTest.java#L660" target="_blank">https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/compiler/integrationtests/IncrementalCompilationTest.java#L660</a>) without having to recreate a new session (stateless) <div class="im">
<br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">3. It looks like I'll have to wait until Drools 6.1.0 to get the parameter</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">to specify a classloader when creating the container? I see you just added</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">that recently. I've tried using</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">Thread.currentThread().</span><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">setContextClassLoader(...) but can't seem to make</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">that work with Drools 6.0.1 in Karaf 2.3.3 because then</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">RuleBaseConfiguration sets the classloader and uses it to try resolving</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">org.drools.core.conflict.</span><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">DepthConflictResolver, which it can't do because</span><br style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<span style="font-family:arial,sans-serif;font-size:12.727272033691406px">it's no longer using the OSGi classloader.</span></div></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">>> I have no ideas if my modifications will be merged with 6.0.x release. Mario Fusco should be able to provide a response<br>
</font><div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">Regards,</div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">
</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div class="im">On Thu, Jan 23, 2014 at 6:01 PM, jhusby <span dir="ltr"><<a href="mailto:husby024@umn.edu" target="_blank">husby024@umn.edu</a>></span> wrote:<br>
</div><div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I actually looked through your example project yesterday; very helpful!!!<br>
However, there are a few things I'm not sure are compatible with what I'm<br>
trying to do.<br>
<br>
1. I need to rebuild the rules on the fly, so I was using examples from<br>
the IncrementalCompilationTest.java<br>
<<a href="https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/compiler/integrationtests/IncrementalCompilationTest.java" target="_blank">https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/compiler/integrationtests/IncrementalCompilationTest.java</a>><br>
to accomplish that task. However, those tests don't use a classpath<br>
container... can I still rebuild a KieModule via runtime code when running<br>
in a classpathContainer?<br>
<br>
2. Your example code calls .newKieSession() on a kbase object as opposed to<br>
a kContainer object. Is there a reason why? If I create a new KieSession<br>
from a kbase vs. kContainer, will I still be able to rebuild the kjar<br>
dynamically in the code and keep using the same stateful session?<br>
<br>
3. It looks like I'll have to wait until Drools 6.1.0 to get the parameter<br>
to specify a classloader when creating the container? I see you just added<br>
that recently. I've tried using<br>
Thread.currentThread().setContextClassLoader(...) but can't seem to make<br>
that work with Drools 6.0.1 in Karaf 2.3.3 because then<br>
RuleBaseConfiguration sets the classloader and uses it to try resolving<br>
org.drools.core.conflict.DepthConflictResolver, which it can't do because<br>
it's no longer using the OSGi classloader.<br>
<br>
Thank you,<br>
<br>
Joseph<br>
<br>
<br>
Charles Moulliard-2 wrote<br>
<div>> Hi Joseph,<br>
><br>
> I propose that you have a look to this example which is currently working<br>
> on Karaf - <a href="https://github.com/cmoulliard/droolsjbpm-osgi-examples" target="_blank">https://github.com/cmoulliard/droolsjbpm-osgi-examples</a> (simple<br>
> =<br>
> OSGI BundleActivator + KieSession + Drools Rules)<br>
><br>
> Regards,<br>
><br>
> Charles<br>
<br>
<br>
<br>
<br>
<br>
</div>--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/kContainer-newKieSession-fails-in-Apache-Karaf-tp4027815p4027838.html" target="_blank">http://drools.46999.n3.nabble.com/kContainer-newKieSession-fails-in-Apache-Karaf-tp4027815p4027838.html</a><br>
<div><div>Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div></div></div><br><br clear="all"><div class="im"><div><br></div>-- <br><div dir="ltr"><div>Charles Moulliard</div><div>Apache Committer / Architect @RedHat</div><div>Twitter : @cmoulliard | Blog : <a href="http://cmoulliard.github.io" target="_blank"> http://cmoulliard.github.io</a></div>
<div><br></div></div>
</div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div>Charles Moulliard</div><div>Apache Committer / Architect @RedHat</div><div>Twitter : @cmoulliard | Blog : <a href="http://cmoulliard.github.io" target="_blank"> http://cmoulliard.github.io</a></div>
<div><br></div></div>
</div>