[rules-users] KnowledgeAgent with persistence?

dunnlow dunnlow at yahoo.com
Wed Sep 11 10:59:23 EDT 2013


Thanks David.  Short answer is yes, I have it set to false.  

I am actually combining Spring and Java Configuration (I am doing this all
in the drools-server).  I create my KnowledgeAgent in Spring and then pass
it (with the EntityManagerFactory, TransactionManager, and node) to an
"Initializer" bean that creates the ksession (so I can load an existing
session).

My KnowledgeAgent config is as follows:

<drools:grid-node id="node1"/>
<drools:kbase id="kbase1" node="node1"/>
<drools:kagent id="kagent1" kbase="kbase1" new-instance="false">
    <drools:resources>
        <drools:resource type="PKG" basic-authentication="enabled"
source="http://localhost:8080/guvnor/org.drools.guvnor.Guvnor/package/Travel/LATEST"
username="user" password="pass"/>
    </drools:resources>
</drools:kagent>

<bean id="txManager".....>
<bean id="jpaEntityManagerFactory....>

<bean id="ksessionInit" class="com.my.trn.KnowedgeSessionInitializer"
depends-on="node1">
    <constructor-arg index="0"<ref
bean="jpaEntityManagerFactory"/></constuctor-arg>
    <constructor-arg index="1"<ref bean="txManager"/></constuctor-arg>
    <constructor-arg index="2"<ref bean="kagent1"/></constuctor-arg>
    <constructor-arg index="3"<ref bean="node1"/></constuctor-arg>
</bean>

<bean id="ksession1" factory-bean="ksessionInit"
factory-method="getKsession"/>

then,

public void initialize(Object anEMF, PlatformTransactionManager aTxManager,
KnowledgeAgent kAgent, GridNode anode) {

   Environment env="KnowledgeBaseFactory.newEnvironment();
   env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, anEMF)
   env.set(EnvironmentName.TRANSACTION_MANAGER, aTxManager);
  .
  kAgent.addEventListener(new KnowledgeAgentEventListener(){.....for
debugging...}
  .
  Integer maxSession =
getTheMaxSession(((EntityManagerFactory)anEmf).createEntityManager());
  if (maxSession==0) {
     
*ksession=kAgent.getKnowledgeBase()newStatefulKnowledgeSession(null,env);*
  } else {
      session=JPAKnowledgeService.loadStatefulKnowledgeSession(maxSession,
kAgent.getKnowledgeBase(),null,env);
  {
  .
  .
  anode.set("ksession1",ksession);
   .
   .
}

Note, when I create the new ksesison as above in bold, the new session is
created in the database, and the kagent sees the changes in Guvnor
(although, interestingly when I build vs when I deploy); however, the
persisted session in the database is not updated.

If I try
ksession=kAgent.getKnowledgeBase().newStatefulKnowledgeSession(null,env) the
new session is NEVER created in the database.

If a session already exists, the loadStatefulKnowledgeSession does read the
existing session, and the kagent triggers on a build in guvnor, but the
session is not updated :(

Thanks again for any insight.
-J




--
View this message in context: http://drools.46999.n3.nabble.com/KnowledgeAgent-with-persistence-tp4025897p4025917.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list