Hi,
Not using JNDI but plain Spring IoC, here is a working setup:
XML bean factory:
Code:
<bean id="ruleAdministrator" class="org.springmodules.jsr94.factory.RuleAdministratorFactoryBean">
<property name="serviceProvider" ref="droolsRuleServiceProvider"/>
</bean>
<bean id="ruleRuntime" class="org.springmodules.jsr94.factory.RuleRuntimeFactoryBean">
<property name="serviceProvider" ref="droolsRuleServiceProvider"/>
</bean>
<bean id="droolsRuleServiceProvider" class="org.drools.jsr94.rules.RuleServiceProviderImpl"/>
Retrieve a RuleExecutionSetProvider:
Code:
LocalRuleExecutionSetProvider ruleExecutionSetProvider;
ruleExecutionSetProvider = ruleAdministrator.getLocalRuleExecutionSetProvider(null); // Drools JSR-94 integration ignores the argument
Create a RuleExecutionSet:
Code:
// optional: Drools PackageBuilder config
Map<String, Object> config = new HashMap<String, Object>();
config.put(Constants.RES_PACKAGEBUILDER_CONFIG, packageBuilderConfiguration);
RuleExecutionSet ruleExecutionSet;
ruleExecutionSet = ruleExecutionSetProvider.createRuleExecutionSet(source, config); // source can be a Reader, InputStream or Object (Drools Package)
Register the RuleExecutionSet:
Code:
ruleAdministrator.registerRuleExecutionSet("someName", ruleExecutionSet, null); // Drools JSR-94 ignores the third argument
Client side
Create a stateful RuleSession:
Code:
StatefulRuleSession ruleSession;
ruleSession = (StatefulRuleSession) ruleRuntime.createRuleSession("someName", null /* or a Map of parameters to WorkingMemory.setGlobal() */, RuleRuntime.STATEFUL_SESSION_TYPE);
Add objects to the RuleSession:
Code:
ruleSession.addObjects(someObjects);
Trigger rules processing:
Code:
ruleSession.executeRules();
Release resources:
Code:
ruleSession.release();
Regards