[rules-users] Will StatefulKnowledgeSession.fireallrules() block in this case ?
Wolfgang Laun
wolfgang.laun at gmail.com
Mon May 14 01:14:21 EDT 2012
On 13/05/2012, soumya_sd <soumya_sd at yahoo.com> wrote:
> My question is if I call re.callRuleEngine(facts) in the same thread (which
> in turn calls knowledgeSession.fireallrules()) will it "block" till
> a) ALL rules are fired (i.e., THEN part of rule is executed for all
> matching facts in working memory)
> AND
> b) MyChannel.send() is executed for all matching facts i.e., the list of
> FilteredFacts inside my MyChannel object is populated completely at the end
> of the blocking call.
>
Yes.
Adding b) to the question is redundant unless you use a very unusual
implementation of List in MyChannel.)
You aren't showing your actual code - it's neither correct nor complete.
-W
>
> Thanks.
>
> -------------------------------------------------------------------------------------
>
> RuleEngine re = RuleEngine();
> re.callRuleEngine(facts);
>
>
>
> -----------------------------------------------------------------------------------
>
> rule.drl
>
> rule "some_rule"
> dialect "mvel"
> when
> $my_var : MyValueObject( x > 4.0 )
> then
> channels["my_drools_channel"].send($my_var);
> end
>
>
> -----------------------------------------------------------------------------------
>
> RuleEngine
> {
>
> RuleEngine{
> KnowledgeBase knowledgeBase = null;
> try {
> knowledgeBase = createKnowledgeBase();
> } catch (Exception e) {
> e.printStackTrace();
> }
> knowledgeSession = knowledgeBase.newStatefulKnowledgeSession();
> knowledgeSession.registerChannel("my_drools_channel", new MyChannel());
>
> }
>
> void callRuleEngine(List<MyValueObject> facts)
> {
> // insert Facts into
> // the working memory.
> for (Object fact : facts) {
> knowledgeSession.insert(fact);
> }
>
> knowledgeSession.fireallrules();
> }
> }
>
>
> -----------------------------------------------------------------------------------
>
>
> public class MyChannel implements Channel {
>
> private List<MyValueObject> filteredFacts;
>
> @Override
> public void send(Object object) {
>
> if( object instanceof MyValueObject )
> {
> MyValueObject obj = (MyValueObject)object;
> filteredFacts.add(obj)
>
> }
>
> }
>
> }
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Will-StatefulKnowledgeSession-fireallrules-block-in-this-case-tp3984730.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