How to configure to reload the drools knowledge session when server(tomcat) restart using Spring

做~自己de王妃 提交于 2019-12-10 12:13:00

问题


I am using the drools server 5.5 Final with Spring to configure the knowledge session to persist to database(mysql) and expect it will reload the session when server(tomcat) restart. code snippet as below

<drools:resource-change-scanner id="s1" interval="5" enabled="true" />
  <drools:grid-node id="node1"/>

<drools:kagent id="kagent1" kbase="kbase1" new-instance="false">
      <drools:resources>
         <drools:resource  type="DRL" source="file:///tmp/test.drl"/>
    </drools:resources>
</drools:kagent>

  <drools:kbase id="kbase1" node="node1">
  </drools:kbase>

  <drools:ksession id="ksession1" type="stateful" kbase="kbase1" node="node1">
      <drools:configuration>
        <drools:jpa-persistence>
              <drools:transaction-manager ref="txManager" />
              <drools:entity-manager-factory ref="myEmf" />

        </drools:jpa-persistence>
      </drools:configuration>
  </drools:ksession>

I can see it will insert the session info to Mysql when Tomcat restart each time

How to configure to reload the session from Database if the session has been persisted before?


回答1:


Finally, we happen to see the src code of KnowledgeSessionDefinitionParser which will parse the spring configuration file http://grepcode.com/file/repo1.maven.org/maven2/org.drools/drools-spring/5.5.0.Final/org/drools/container/spring/namespace/KnowledgeSessionDefinitionParser.java?av=f

in the code, it will get the value of 'load' attribute and use as the sessionId to reload. so we tested to add load="sessionId" and it is ok to reload. but if config the sessionId to a number which does not exist in the DB, it will throw exception

  <drools:ksession id="ksession1" type="stateful" kbase="kbase1" node="node1">
      <drools:configuration>
        <drools:jpa-persistence load="42011">
              <drools:transaction-manager ref="txManager" />
              <drools:entity-manager-factory ref="myEmf" />

        </drools:jpa-persistence>
      </drools:configuration>
  </drools:ksession>

For a real application, it is impossible to know the sessionId when do the src configuration, also have not found drools have provided any way for us to pre-set the sessionId.

so is it the correct solution? Any one have advanced opinion?



来源:https://stackoverflow.com/questions/21928187/how-to-configure-to-reload-the-drools-knowledge-session-when-servertomcat-rest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!