[rules-users] Dynamically loading rules in KieBase

Davide Sottara dsotty at gmail.com
Tue Jul 22 12:14:32 EDT 2014


You can add rules programmatically to an existing KieBase, but you have to:

1) add/replace the resource in the KieFileSystem
2) Cast the KieBuilder to InternalKieBuilder and use the
incrementalBuild() method
3) Enjoy and report problems as this is a newer feature

See the test suite here
https://github.com/droolsjbpm/drools/blob/184765346e998430064a4935fbb358930946d82c/drools-compiler/src/test/java/org/drools/compiler/integrationtests/IncrementalCompilationTest.java

the latest tests show the use of the incremental builder
Davide

On 07/22/2014 04:20 PM, marianbuenosayres wrote:
> I'm bumping this question for general interest on other possible solutions,
> and to give my two cents. 
>
> The closest I was to getting this feature in Drools 6 from the public APIs,
> is to use a persistent session. Then, when I loaded an existing session, I
> would pass a newly created KieBase, like this
>
> KieStoreServices kstore = KieServices.Factory.get().getStoreServices();
>
> KieBase kbase = ...; //create a Kie Base
> Environment env = ...; //create an environment
> KieSession ksession = kstore.newKieSession(kbase, null, env);
> Integer sessionId = ksession.getId();
>
> KieBase kbase2 = ...; //updated Kie base
> KieSession ksessionReloaded = ks.loadKieSession(kbase2, null, env);
>
> ksession and ksessionReloaded would be the same working memory and agenda,
> but the kie base they work with would change. 
>
> Hope this helps, but I hope more for an alternative
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Dynamically-loading-rules-in-KieBase-tp4030351p4030425.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



More information about the rules-users mailing list