Hi, all: I'm a newbie to Drools. I'm trying to restore stateful knowledge session using JPAKnowledgeService after restarting server. In my rules I use Drools Fusion's Sliding Length Window to processing events. Below is a sample:
package com.sample
import com.sample.Event;
import java.util.List;
declare Event @role(event) end
rule "test"
when
$list : List() from collect(Event() over window: length(2))
then
System.out.println("list size:" + $list.size());
end
@Test
public void test_persistedsession() {
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
loadDRL(kbase);
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, Persistence.createEntityManagerFactory( "org.drools.persistence.jpa"));
env.set( EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
//create a persisted statefulknowledgesession
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
ksession.insert(new Event());
ksession.fireAllRules();
ksession.insert(new Event());
ksession.fireAllRules();
//reload the persisted session
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(ksession.getId(), kbase, null, env);
ksession.insert(new Event());
ksession.fireAllRules();
ksession.insert(new Event());
ksession.fireAllRules();
}
Hibernate: insert into SessionInfo (id, lastModificationDate, rulesByteArray, startDate, OPTLOCK) values (null, ?, ?, ?, ?)
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
list size:1
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
list size:2
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
list size:3
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=? Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
list size:4
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?