Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
JSR94- Drools Integration newbie question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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...

    Comment


    • #3
      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, 07:30 AM. Reason: Typo

      Comment


      • #4
        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.

        Comment


        • #5
          Hi,

          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.

          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

          Comment


          • #6
            Nice

            Excellent,

            Thank you for the clarification.

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

            I will keep you updated.

            Thanks again!!

            Comment


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

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

              Comment


              • #8
                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/do...Configuration)

                Comment


                • #9
                  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.

                  Comment


                  • #10
                    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.

                    Comment

                    Working...
                    X