[rules-users] persisted StatefulKnowledgeSession failed to maintain the length of Sliding window?
henrychen
hengdour at 163.com
Wed Sep 12 04:39:00 EDT 2012
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
And I have done what should be done according to the manual reference. When
I running my test case below:
@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();
}
Then I found that the result is:
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=?
As I have declared that the length of window is 2, how can the size of list
increase to 3, 4 and more?
I am using the 5.2.0 final. May be I have missed something, please help me.
Any help will be appreciated.
--
View this message in context: http://drools.46999.n3.nabble.com/persisted-StatefulKnowledgeSession-failed-to-maintain-the-length-of-Sliding-window-tp4019696p4019697.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120912/ac511fea/attachment.html
More information about the rules-users
mailing list