Bug 994533

Summary: ksession.getProcessInstances() does not return active process instances.
Product: [Retired] JBoss BPMS Platform 6 Reporter: Marek Baluch <mbaluch>
Component: jBPM CoreAssignee: Kris Verlaenen <kverlaen>
Status: CLOSED NOTABUG QA Contact: Marek Baluch <mbaluch>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.0.0Flags: kverlaen: needinfo+
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-08-07 15:19:08 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Marek Baluch 2013-08-07 13:00:56 UTC
Description of problem:

Call to 'getProcessInstancees()' in the following code snippet will not return the expected process instance.

KieSession ksession = createKnowledgeSession("BPMN2-UserTask.bpmn2");
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ProcessInstance pi = ksession.startProcess("UserTask");
		
System.out.println(ksession.getProcessInstance(pi.getId())); // prints out the instance correctly		System.out.println(ksession.getProcessInstances()); // prints an empty list


Environment:
jBPM with JPA on PostgreSQL 9.1.

Comment 1 Kris Verlaenen 2013-08-07 13:38:53 UTC
This is actually expected behaviour.  The getProcessInstances() operation returns the process instances that are currently active in this ksession.  When not using persistence, this will be equivalent to all process instances for that ksession (as they all are in memory).  However, when using persistence, process instances are only in the ksession during execution of that process instance.  As soon as an operation is completed, the process instances are persisted in the database.

Changing the implementation of this operation (for example to load all active process instances from database and return those) wouldn't be very useful, as in any real-life system, the number of process instances could be very large.

If the user want to know information about which process instances are active etc., the history log aka audit log is the place to search for these.

See also JavaDocs:
http://docs.jboss.org/jbpm/v5.4/javadocs/org/drools/runtime/process/ProcessRuntime.html#getProcessInstances%28%29

I would therefore recommend closing this as not a bug.  Please let me know if you disagree, so we can discuss alternatives.

Comment 2 Marek Baluch 2013-08-07 14:55:17 UTC
If the active statement in the documentation does not refer to ProcessInstance.STATE_ACTIVE then please close the issue.