[rules-users] Drools-server KnowledgeSessions

Richard Calmbach rcalmbac at gmail.com
Thu Jan 12 13:38:49 EST 2012


Here is how I create StatefulKnowledgeSession instances dynamically, while
still leveraging Spring config:

[...]

  <drools:ksession kbase="kBase" type="stateful" id="kSessionParent">
    <drools:batch>
      <drools:set-global identifier="helper" ref="sessionHelper"/>
    </drools:batch>
  </drools:ksession>

  <bean id="kSession" scope="prototype" parent="kSessionParent"/>

  <bean id="knowledgeSessionGateway"
class="com.acme.rules.CompositeKnowledgeSessionGateway">
    <lookup-method name="createSession" bean="kSession"/>
  </bean>

Read [1,2] for background on Spring method injection and how to use it to
get a factory method for Spring-configured prototype beans without your
code (here: CompositeKnowledgeSessionGateway) needing to be Spring-aware.
Note that conceptually, kSessionParent is an abstract bean, but the
"abstract" attribute does not seem to be supported on <drools:ksession>.
Class CompositeKnowledgeSessionGateway has a

    protected StatefulKnowledgeSession createSession() {
        return null;
    }

method (that could be abstract) that gets overridden in a Spring-generated
subclass.

Ref.:
[1]
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-factory-method-injection
[2] http://blog.springsource.com/2004/08/06/method-injection/

-Richard

On Wed, Jan 11, 2012 at 4:37 PM, Hrumph <Herman.Post at imail.org> wrote:

> Is it possible to dynamically create a KnowledgeSession using the
> Drools-server API, or must the be statically declared in the Spring config?
>
> Thanks
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Drools-server-KnowledgeSessions-tp3652344p3652344.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120112/7f8dd308/attachment.html 


More information about the rules-users mailing list