use of org.drools.persistence.api.SessionMarshallingHelper in project drools by kiegroup.
the class PersistableRunner method initExistingKnowledgeSession.
protected void initExistingKnowledgeSession(Long sessionId, KieBase kbase, KieSessionConfiguration conf, PersistenceContext persistenceContext) {
if (!doRollback && this.ksession != null) {
return;
// nothing to initialise
}
this.doRollback = false;
try {
// if locking is active, this will also lock the (found) SessionInfo instance
this.sessionInfo = (SessionInfo) persistenceContext.findSession(sessionId);
} catch (Exception e) {
throw new SessionNotFoundException("Could not find session data for id " + sessionId, e);
}
if (sessionInfo == null) {
throw new SessionNotFoundException("Could not find session data for id " + sessionId);
}
if (this.marshallingHelper == null) {
// this should only happen when this class is first constructed
this.marshallingHelper = new SessionMarshallingHelper(kbase, conf, env);
MarshallingConfigurationImpl config = (MarshallingConfigurationImpl) this.marshallingHelper.getMarshaller().getMarshallingConfiguration();
config.setMarshallProcessInstances(false);
config.setMarshallWorkItems(false);
}
this.sessionInfo.setJPASessionMashallingHelper(this.marshallingHelper);
// if this.ksession is null, it'll create a new one, else it'll use the existing one
this.ksession = this.marshallingHelper.loadSnapshot(this.sessionInfo.getData(), this.ksession, new JpaSessionInitializer(this));
// update the session id to be the same as the session info id
InternalKnowledgeRuntime kruntime = ((InternalKnowledgeRuntime) ksession);
kruntime.setIdentifier(this.sessionInfo.getId());
kruntime.setEndOperationListener(new EndOperationListenerImpl(this.txm, this.sessionInfo));
this.runner = new TransactionInterceptor();
// apply interceptors
Iterator<ChainableRunner> iterator = this.interceptors.descendingIterator();
while (iterator.hasNext()) {
addInterceptor(iterator.next(), false);
}
initKieSessionMBeans(this.ksession);
}
use of org.drools.persistence.api.SessionMarshallingHelper in project drools by kiegroup.
the class PersistableRunner method initNewKnowledgeSession.
protected void initNewKnowledgeSession(KieBase kbase, KieSessionConfiguration conf) {
this.sessionInfo = new SessionInfo();
// create session but bypass command service
this.ksession = kbase.newKieSession(conf, this.env);
initKieSessionMBeans(this.ksession);
this.marshallingHelper = new SessionMarshallingHelper(this.ksession, conf);
MarshallingConfigurationImpl config = (MarshallingConfigurationImpl) this.marshallingHelper.getMarshaller().getMarshallingConfiguration();
config.setMarshallProcessInstances(false);
config.setMarshallWorkItems(false);
this.sessionInfo.setJPASessionMashallingHelper(this.marshallingHelper);
((InternalKnowledgeRuntime) this.ksession).setEndOperationListener(new EndOperationListenerImpl(this.txm, this.sessionInfo));
this.runner = new TransactionInterceptor();
TimerJobFactoryManager timerJobFactoryManager = ((InternalKnowledgeRuntime) ksession).getTimerService().getTimerJobFactoryManager();
if (timerJobFactoryManager instanceof CommandServiceTimerJobFactoryManager) {
((CommandServiceTimerJobFactoryManager) timerJobFactoryManager).setRunner(this);
}
}
Aggregations