[rules-users] setting global variables in session : the Command interface VS the RuleContext. What is the difference ?

Welsh, Armand AWelsh at StateStreet.com
Mon Apr 23 13:18:47 EDT 2012


The knowledgeSession is used to setup your new session for processing.  When you issue the command, fireAllRule() on the knowledgeSession (or session.execute), then the knowledgeRuntime is created, and the rules are in a running state.  

The knowledgeRuntime is an instance of a live (running or idle) session.   This is why the first parameter in the function if RuleContext, because a rule is calling the static function, and passing the information about the fired rule to the function, so that the function to derive information about the fired rule, and from that, the current runtime session that is running the rule.

Or, to put it another way, the knowledgeSession is pre-execution, or post-executeion information about the session that will or has been executed.  The knowledgeRuntime is the actual execution session, or runtime.

-----Original Message-----
From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of bardelman
Sent: Monday, April 23, 2012 2:02 AM
To: rules-users at lists.jboss.org
Subject: [rules-users] setting global variables in session : the Command interface VS the RuleContext. What is the difference ?

hi ,
i m new in drools, i m reading the Drools-JBoss-Rules-5.0-Developers-Guide
book in which i found a validation rule example on its chapter 3. In this
exemple, global variables were set into the session with two methods shown
in this code :

...
session = knowledgeBase.newStatelessKnowledgeSession();
    session.setGlobal("reportFactory", reportFactory);
    session.setGlobal("inquiryService", inquiryService);
...

and these variables qualified as immutables, were called from the
RuleContext

public static void error(RuleContext drools,
      Object... context) {
 KnowledgeRuntime knowledgeRuntime = drools
        .getKnowledgeRuntime();
    ValidationReport validationReport = (ValidationReport)
        knowledgeRuntime.getGlobal("validationReport");
    ReportFactory reportFactory = (ReportFactory)
        knowledgeRuntime.getGlobal("reportFactory");
...

and for other variables(or facts ) the Command interface was used instead :

 List<Command> commands = new ArrayList<Command>();
    commands.add(CommandFactory.newSetGlobal(
        "validationReport", report));
    commands.add(CommandFactory
        .newInsertElements(getFacts(customer)));
    session.execute(CommandFactory
        .newBatchExecution(commands));

i m looking for accuracy in understanding when and which to use each method.

thanks for help 

--
View this message in context: http://drools.46999.n3.nabble.com/setting-global-variables-in-session-the-Command-interface-VS-the-RuleContext-What-is-the-difference-tp3931886p3931886.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