Results 1 to 10 of 10

Thread: JSR94- Drools Integration newbie question

  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!!

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

    Default

    Do you know where I can find a sample packageBuilderConfiguration to reference?

    How is it optional? I thought it was mandatory for Drools.

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

    Default

    Quote Originally Posted by codySpringMan View Post
    Do you know where I can find a sample packageBuilderConfiguration to reference?

    How is it optional? I thought it was mandatory for Drools.
    The simplest configuration is the default one:

    Code:
            PackageBuilderConfiguration packageBuilderConfiguration;
            packageBuilderConfiguration = new PackageBuilderConfiguration();
    It is optional as mentioned at http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/apidocs/org/drools/compiler/PackageBuilder.html#PackageBuilder(org.drools.rule .Package, org.drools.compiler.PackageBuilderConfiguration)

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

    Default J2EE config???

    Fiouz,

    Thank you for you help in this matter. However I am still confused as to how this configuration can be used in a J2EE environment. It seems that this configuration can only be used by having the decision tables / .drl files stored locally, which is NOT what I need.

    I wish to deploy the drools-brms application on an application server, and be able to execute the rules stored there from another server. (does this make sense?)

    Do you know where I might find an example configuration of this?

    ( JNDI - ???)

    Thank you again for your help.

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

    Default

    There is no mandatory usage of local files with Spring since you can make usage of the resources infrastructure in order to retrieve data from filesystem/classpath/war archive/...
    Using classpath resources with Spring is a common usage in JEE environments.

    As for JNDI retrieving, Spring has support classes too http://static.springframework.org/sp...ee-jndi-lookup and I mainly use it to retrieve JDBC datasources.
    I'm not too used to app server custom JNDI binding/remoting, but I guess you just have to figure out what to bind (the rule definition itself? the service that generates it?), bind it and refer to it from Spring.

Posting Permissions

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