Results 1 to 10 of 10

Thread: JSR94- Drools Integration newbie question

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Location
    U.S.
    Posts
    18

    Default JSR94- Drools Integration newbie question

    Hey all,

    I am a newbie to jsr94 and I'm looking for resources. Specifically related to drools integration using the drools-brms. I have downloaded the latest version of spring-modules (0.9) and I have read the documentation regarding drools-integration. (what little there is...)

    Anyway, I would be very appreciative if ANYONE could give me a few pointers, at least with the JNDI setup.

    I'm really stoked about getting this setup, but I can't seem to get things started.

    Thanks ahead of time.

    -CodySpringMan

  2. #2
    Join Date
    Sep 2007
    Location
    U.S.
    Posts
    18

    Default Seeking advice -jsr94 Drools integration

    Hello again,

    I would appreciate any feedback. I have tried many variations but I am still unsuccessful.

    Any reply is appreciated...

  3. #3
    Join Date
    Apr 2007
    Location
    France
    Posts
    23

    Default

    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
    Last edited by Fiouz; Jul 3rd, 2008 at 07:30 AM. Reason: Typo

  4. #4
    Join Date
    Sep 2007
    Location
    U.S.
    Posts
    18

    Default

    So you are able to execute rules even though the ruleServiceProvider has NULL arguments?

    Where are your .drl files located?

    Thank you for the reply.

  5. #5
    Join Date
    Apr 2007
    Location
    France
    Posts
    23

    Default

    Hi,

    Quote Originally Posted by codySpringMan View Post
    So you are able to execute rules even though the ruleServiceProvider has NULL arguments?
    Yes, have a look at the source code of org.drools.jsr94.rules.admin.RuleAdministratorImpl / org.drools.jsr94.rules.RuleRuntimeImpl, you'll see that Drools JSR-94 integration does ignore some arguments.

    Quote Originally Posted by codySpringMan View Post
    Where are your .drl files located?
    The rule definition is referenced here under the "source" variable:

    Code:
    RuleExecutionSet ruleExecutionSet;
    ruleExecutionSet = ruleExecutionSetProvider.createRuleExecutionSet(source, config); // source can be a Reader, InputStream or Object (Drools Package)
    You can declare source either ways:
    Code:
    Reader source;
    InputStream source;
    Object source; // but the actual value has to be a org.drools.rule.Package
    Actually, I don't use plain .drl files since I generate my rules from a Excel spreadsheet (using Drools decision table API). My rules are generated into a String which is given to the createRuleExecutionSet() method using a StringReader.

    Regards

  6. #6
    Join Date
    Sep 2007
    Location
    U.S.
    Posts
    18

    Default Nice

    Excellent,

    Thank you for the clarification.

    I will attempt to use this config. for my needs.

    I will keep you updated.

    Thanks again!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •