[
https://issues.jboss.org/browse/DROOLS-422?page=com.atlassian.jira.plugin...
]
Nedo Nedic commented on DROOLS-422:
-----------------------------------
Hello Davide
I've made a small change in org.drools.time.impl.JDKTimerService, and for now it seems
that thing is working good. At internalSchedule method I moved the line where timer job
instance is being added. If this line is placed after job schedule, due to concurrency
issue, next fire timestamp of timerJobInstance sometimes was setting to null.
public void internalSchedule(TimerJobInstance timerJobInstance) {
Date date = timerJobInstance.getTrigger().hasNextFireTime();
Callable<Void> item = (Callable<Void>) timerJobInstance;
jobFactoryManager.addTimerJobInstance( timerJobInstance ); <------
JDKJobHandle jobHandle = (JDKJobHandle) timerJobInstance.getJobHandle();
long then = date.getTime();
long now = System.currentTimeMillis();
ScheduledFuture<Void> future = null;
if ( then >= now ) {
future = scheduler.schedule( item,
then - now,
TimeUnit.MILLISECONDS );
} else {
future = scheduler.schedule( item,
0,
TimeUnit.MILLISECONDS );
}
jobHandle.setFuture( future );
}
Davide, can you please confirm is this could be a bug?
Thanks
Timer based rules don't fire and facts can't expire after
session restore
-------------------------------------------------------------------------
Key: DROOLS-422
URL:
https://issues.jboss.org/browse/DROOLS-422
Project: Drools
Issue Type: Bug
Security Level: Public(Everyone can see)
Affects Versions: 5.5.0.Final
Environment: Linux Mint 15
JBoss AS 5.1
Reporter: Nedo Nedic
Assignee: Mark Proctor
Attachments: drools-mongodb-persistence.zip
I have implemented a custom persistence engine for Drools sessions in MongoDB. When
session is built for first time, everything works like a charm. I am having some problems
when Drools sessions are restored from MongoDB collection. Firstly, interval based rules
(for example timer(int: 10s 10s)) don't fire. Some facts that should expire, they just
don't expire and remain forever in WM. I attached the source code. When session is
built for first time, I use code like this:
KnowledgeBase kbase = createKBase(getKnowledgeBuilder(rulePackagePath),
config);
if (hasKnowledgeAgent) {
createKnowledgeAgent(kbase, correlatorId);
wm = (ReteooStatefulSession) ((KnowledgeBaseImpl) kagent
.getKnowledgeBase()).ruleBase.newStatefulSession(
(SessionConfiguration) ksconf, env);
ksession = new StatefulKnowledgeSessionImpl(wm, kagent
.getKnowledgeBase());
stateOutputMarshaller = StateMarshallerFactory.newOutputMarshaller(this, ksession,
ksconf);
stateOutputMarshaller.init();
((InternalKnowledgeRuntime) ksession).setEndOperationListener(this);
}
Then, after every action I update the session in MongoDB collection.
public void endOperation(InternalKnowledgeRuntime ikr) {
stateOutputMarshaller.marshall();
}
For session restoring, after AS restart I use this code:
KnowledgeBase kbase = createKBase( getKnowledgeBuilder(rulePackagePath), getKBaseConfig()
);
stateInputMarshaller = StateMarshallerFactory.newInputMarshaller( this, kbase,
getSessionConf() );
ksession = stateInputMarshaller.unmarshall(correlatorId);
stateOutputMarshaller = StateMarshallerFactory.newOutputMarshaller( this, ksession,
getSessionConf() );
((InternalKnowledgeRuntime)ksession).setEndOperationListener(this);
protected static KnowledgeBaseConfiguration getKBaseConfig() {
KnowledgeBaseConfiguration config = KnowledgeBaseFactory
.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM);
return config;
}
protected static KnowledgeSessionConfiguration getSessionConf() {
KnowledgeSessionConfiguration ksconf =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.get("realtime"));
return ksconf;
}
Any help is appreciated.
Thanks
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:
http://www.atlassian.com/software/jira