[rules-users] Boolean global issue

Dan Seaver dan.seaver at ge.com
Mon Jun 15 15:05:01 EDT 2009


So, I'd like to have a ruleset that returns true or false. The way I set that
up in one of the version 5 candidate releases is to use a Boolean global and
use drools.getWorkingMemory().setGlobal("result", new Boolean(false)) to
change the value of the global. I could then access the updated value in the
code by using the old style getGlobal.

However in version 5 Final release, the global value changes fine within the
ruleset, but is not updated when I access it via ExecResults. I imagine the
reason for this is that immutable variables are handled differently in the
final release than in the candidate release, but need to know whether this
is by design.

Here is the RuleSet I'm using:
package BooleanTest

global Boolean result

rule "Initialize"
salience -1
	when
	then 
	drools.getWorkingMemory().setGlobal("result", new Boolean(false));
	System.out.println("Initialized result to false");		
end

rule "Display result"
salience -2
when
then
	System.out.println("result is " + result);
end


Here is the pertinent code:
			cmds.add(CommandFactory.newSetGlobal("result", null, true));

			ExecutionResults execResults = ksession.execute(CommandFactory
					.newBatchExecution(cmds));

			for (String identifier : execResults.getIdentifiers()) {
				System.out.format(String.format("Identifier: %s, Value: %s \n",
						identifier, execResults.getValue(identifier)));
			}

Here is the output:
Initialized result to false
result is false
Identifier: result, Value: null

-- 
View this message in context: http://www.nabble.com/Boolean-global-issue-tp24040774p24040774.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list