Bug 1011370 - Global variables are not available after session restore.
Global variables are not available after session restore.
Status: CLOSED WONTFIX
Product: JBoss BPMS Platform 6
Classification: JBoss
Component: jBPM Core (Show other bugs)
6.0.0
Unspecified Unspecified
low Severity low
: ---
: ---
Assigned To: Kris Verlaenen
Tibor Zimanyi
: FutureFeature
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-09-24 03:32 EDT by Marek Baluch
Modified: 2015-12-08 07:25 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-12-08 07:25:14 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
process definition (16.72 KB, application/xml)
2013-09-24 03:32 EDT, Marek Baluch
no flags Details
Rule definition (893 bytes, text/plain)
2013-09-24 03:32 EDT, Marek Baluch
no flags Details

  None (edit)
Description Marek Baluch 2013-09-24 03:32:18 EDT
Created attachment 802067 [details]
process definition

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(
				ResourceFactory.newClassPathResource("BPMN2-BusinessRuleTask-debug.bpmn2"),
				ResourceFactory.newClassPathResource("BPMN2-BusinessRuleTask.drl"));
		
		List<String> executeRuleList = new ArrayList<String>();
		KieSession ksession = createKnowledgeSession(kbase);
		ksession.setGlobal("executed", executeRuleList);
		ProcessInstance pi = ksession.startProcess("BPMN2-BusinessRuleTask");
		
		Assert.assertNotNull(pi);
		Assert.assertTrue(pi.getState() == ProcessInstance.STATE_ACTIVE);
		
		int sessionId = ksession.getId();
		System.out.println("Signal Continue");
		ksession.signalEvent("Continue", null);
		ksession.dispose();
		
		ksession = restoreKnowledgeSession(sessionId, kbase, null);
		System.out.println("Fire Rules");
		ksession.fireAllRules();
		ksession.dispose();
Comment 1 Marek Baluch 2013-09-24 03:32:46 EDT
Created attachment 802068 [details]
Rule definition
Comment 2 Kris Verlaenen 2013-09-24 07:29:18 EDT
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.
Comment 3 Marek Baluch 2013-09-24 07:39:42 EDT
Thanks for clarification. Marking this issue as FutureFeature.
Comment 4 Tibor Zimanyi 2015-12-08 07:25:14 EST
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.

Note You need to log in before you can comment on or make changes to this bug.