Red Hat Bugzilla – Bug 1011370
Global variables are not available after session restore.
Last modified: 2015-12-08 07:25:14 EST
Created attachment 802067 [details]
Description of problem:
The following code will fail on NPE when rules are fired because they use the 'executed' global which is set before process start and is lost:
KieBase kbase = createKnowledgeBaseFromResources(
List<String> executeRuleList = new ArrayList<String>();
KieSession ksession = createKnowledgeSession(kbase);
ProcessInstance pi = ksession.startProcess("BPMN2-BusinessRuleTask");
Assert.assertTrue(pi.getState() == ProcessInstance.STATE_ACTIVE);
int sessionId = ksession.getId();
ksession = restoreKnowledgeSession(sessionId, kbase, null);
Created attachment 802068 [details]
This is as expected (and same behaviour as before). Globals are environment variables, and they are not stored as part of the session state (same as for example work item handlers, elements in Environment, etc.).
The reasoning behind this is that globals are typically used to get a reference to external services or externally defined variables. They are typically set on ksession creation, and similarly should also be set after service restore. In a lot of cases, storing globals as part of the session state is not feasible (as when the session is restored, these references to external services need to be updated).
We've considered making it configurable, to support persistence of globals when appropriate (using for example some kind of annotation), but this would be a future feature request.
Thanks for clarification. Marking this issue as FutureFeature.
Closing this, because this cannot be implemented easily. setGlobal() method takes Object as a global, so it can be practically everything. This implies what Kris wrote: "In a lot of cases, storing globals as part of the session state is not feasible (as when the session is restored, these references to external services need to be updated)". And there are other problems - serialization (not each Object is serializable), etc.