Discussion:
[jboss-user] [jBPM] - Integrating jBPM 5 into web application - architecture
Pedro Gonçalves
2012-05-17 18:02:07 UTC
Permalink
Pedro Gonçalves [https://community.jboss.org/people/pgoncalves] created the discussion

"Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/736299#736299

--------------------------------------------------------------
Hello,

I've been trying to integrate the jBPM5 into my own web app, but I've some doubts about how to make it.

My processes are mostly composed by Human Actions, which make them long running processes.
My problem is similar to the one discribed here: https://community.jboss.org/message/636561#636561 https://community.jboss.org/message/636561#636561

I've already configured jBPM to use persistense and I was able to start processes (building kbase, ksession, taskService, etc.). But everytime I start a process, or try to list the started processes I create a new entry on SessionInfo (in the database), and I got a empty list of started processes (I've 2 process instances holding a human action).
* It is clear to me that I'm not managing the sessions properly, my question is, what is the best way to do it? :p
* Does jBPM5.3 brings any improvement on this?
* What are the best practices regarding the use of the kbase, ksessions, taskServices, etc.

Thanks in advance!
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/736299#736299]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Jakub Ferschmann
2012-06-21 11:07:53 UTC
Permalink
Jakub Ferschmann [https://community.jboss.org/people/fersmi] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/743330#743330

--------------------------------------------------------------
Hi,
any progress about this stuff? Do you invented something? I'm worried about the same thing.
Best Regards
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/743330#743330]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
w***@red61.com
2012-06-21 10:47:58 UTC
Permalink
I am currently on holiday until June 26th

If you require support, please email ***@red61.com

Alternatively I will respond to your email upon my return

Will Tatam
Pedro Gonçalves
2012-06-21 11:25:19 UTC
Permalink
Pedro Gonçalves [https://community.jboss.org/people/pgoncalves] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/743334#743334

--------------------------------------------------------------
I'm back to jbpm5 just a couple of days ago; I had spent some time searching for alternatives (activiti is infinitely more simple, but i find it not to be very mature).

The solution i had found for managing the kSession is to create a structure in my db that correlates each process instance to a kSession. I'm using one kSession per process instance.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/743334#743334]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Jakub Ferschmann
2012-06-21 11:38:56 UTC
Permalink
Jakub Ferschmann [https://community.jboss.org/people/fersmi] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/743338#743338

--------------------------------------------------------------
How does it work? I mean, how to store kSessionId for every process instance? In web application every user has only httpSession, and I don't want to store something to it.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/743338#743338]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Mauricio Salatino
2012-06-21 11:48:51 UTC
Permalink
Mauricio Salatino [https://community.jboss.org/people/salaboy21] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/743342#743342

--------------------------------------------------------------
I'm at the moment writing some examples about this topic.
Depending what the process is doing you can store the process instance ID and or the session in a related entity.
As you mention you have the User Session, but if the process do things for more than one user, the User entity is not the appropriate one to store the reference.
one kSession per process instance is one option, I will be sharing examples about different approaches.
Cheers
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/743342#743342]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Lisa DeSouza
2013-02-06 11:17:19 UTC
Permalink
Lisa DeSouza [https://community.jboss.org/people/lisadesouza89] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/796319#796319

--------------------------------------------------------------
hi, are any of your examples currently available online? I am new to jBPM and would like to create a prototype of a webapplication(struts framework) integrated with jBPM. I have not yet been able to find any useful example applications. I successfully installed the jBPM demo, but the integration is my issue.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/796319#796319]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Sandra Renaud
2013-02-06 12:10:21 UTC
Permalink
Sandra Renaud [https://community.jboss.org/people/joploya] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/796329#796329

--------------------------------------------------------------
Hi,

I am implementing a jEE web-app that integrate jbpm5 human task (local service).

I had used examples of Mauricio Salatino and create a KnowledgeSessionProducer to instanciate the KnowledgeSession, load the database and processes. And a Bean that contains all methods to manage tasks.

My users log in, then they choose a form. When they validate the form a process instance is created and a task save in database. Because my processes contains human task nodes, at each step tasks wait being claim. So, next user log in, go to an interface where his tasks are display, then click on take task. This call a method that use the taskManagerBean to claim and start the task and redirect him to the form page. and so one until last validation.

The interface to manage tasks is very well explain in the book about jbpm5. I you need I can give my code but I don't know if we have the same architecture and needs.

Regards,
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/796329#796329]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Lisa DeSouza
2013-02-07 05:05:07 UTC
Permalink
Lisa DeSouza [https://community.jboss.org/people/lisadesouza89] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/796438#796438

--------------------------------------------------------------
yes, it would be very helpful if you shared your code. I tend to work better if I have working examples in front of me, rather than explanations on how to do the task at hand. :) how large is your application? would it be able to be sent via. email? or maybe shared via. a cloud storage application like dropbox?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/796438#796438]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Anand Kumar Jha
2013-02-07 12:34:50 UTC
Permalink
Anand Kumar Jha [https://community.jboss.org/people/anandaryan] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/796509#796509

--------------------------------------------------------------
hi sandra renaud,
I am facing same difficulty as being faced by lisa..
If possible, kindly share the code. after that i will be able to understand the architecture and relevent facts..thanks in advance..:)
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/796509#796509]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Sandra Renaud
2013-02-07 13:46:04 UTC
Permalink
Sandra Renaud [https://community.jboss.org/people/joploya] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/796530#796530

--------------------------------------------------------------
Hello Lisa and Anand,
<!-- jbpm -->
     <dependency>
               <groupId>org.drools</groupId>
                         <artifactId>drools-compiler</artifactId>
                         <version>5.4.0.Final</version>
                    </dependency>
                     <dependency>
                              <groupId>org.jbpm</groupId>
                              <artifactId>jbpm-bpmn2</artifactId>
                              <version>5.4.0.Final</version>
                              <exclusions>
                    <exclusion>
                          <groupId>dom4j</groupId>
                          <artifactId>dom4j</artifactId>
                    </exclusion>
              </exclusions>
                    </dependency>
                    <dependency>
                              <groupId>org.jbpm</groupId>
                              <artifactId>jbpm-flow</artifactId>
                              <version>5.4.0.Final</version>
                              <exclusions>
                    <exclusion>
                          <groupId>dom4j</groupId>
                          <artifactId>dom4j</artifactId>
                    </exclusion>
              </exclusions>
                    </dependency>
                    <dependency>
                              <groupId>org.jbpm</groupId>
                              <artifactId>jbpm-human-task-core</artifactId>
                              <version>5.4.0.Final</version>
                              <exclusions>
                    <exclusion>
                          <groupId>dom4j</groupId>
                          <artifactId>dom4j</artifactId>
                    </exclusion>
              </exclusions>
                    </dependency>
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.annotation.PostConstruct;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import org.drools.KnowledgeBase;
import org.drools.SystemEventListenerFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.Resource;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.EnvironmentName;
import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.process.workitem.email.EmailWorkItemHandler;
import org.jbpm.task.Group;
import org.jbpm.task.User;
import org.jbpm.task.identity.UserGroupCallbackManager;
import org.jbpm.task.service.TaskService;
import org.jbpm.task.service.TaskServiceSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import static org.junit.Assert.*;
@Stateless
@LocalBean
public class KnowledgeSessionProducer implements Serializable{
          private static final long serialVersionUID = -4494168896880405667L;
          private Logger log = LoggerFactory.getLogger(KnowledgeSessionProducer.class);
          private KnowledgeRuntimeLogger logger;
    private EntityManagerFactory emf;
              log.debug("init of KnowledgeSessionProducer ...");
              TaskService taskService = new TaskService(emf, SystemEventListenerFactory.getSystemEventListener());
        TaskServiceSession taskSession = taskService.createSession();
        // Add users
                    Map vars = new HashMap();
        InputStream usersin = KnowledgeSessionProducer.class.getResourceAsStream( "/LoadUsers.mvel" );
        if(usersin != null) {
                  Reader reader = new InputStreamReader( usersin );  
                  Map<String, User> users = ( Map<String, User> ) TaskService.eval( reader, vars );  
                  log.debug("Users to load in db : ...");
                  for ( User user : users.values() ) {
                            taskSession.addUser( user );
                            log.debug(" - "+user);
                  }          
        }
        InputStream groupsin = KnowledgeSessionProducer.class.getResourceAsStream( "/LoadGroups.mvel" );
        if(groupsin != null) {
                  Reader reader = new InputStreamReader( groupsin );  
                  Map<String, Group> groups = ( Map<String, Group> ) TaskService.eval( reader, vars );    
                  log.debug("Groups to load in db : ...");
                  for ( Group group : groups.values() ) {
                            taskSession.addGroup( group );
                            log.debug(" - "+group);
                  }
        }
        // try to get the usergroup callback properties
        InputStream usergroupsin = KnowledgeSessionProducer.class.getResourceAsStream(  "/jbpm.usergroup.callback.properties" );
        if(usergroupsin != null) {
                  Properties callbackproperties = new Properties();
                  try {
                      // Properties.load(Reader) is a JDK 6 method
                            callbackproperties.load(usergroupsin);
                            UserGroupCallbackManager.getInstance().setCallbackFromProperties(callbackproperties);
                            System.out.println("Task service registered usergroup callback ...");
                  } catch (Exception e) {
                            System.out.println("Task service unable to register usergroup callback ...");
                  }
        }
        taskSession.dispose();
        System.out.println("Task service started correctly!");
        System.out.println("Task service running ...");
    }
          public StatefulKnowledgeSession produceKnowledgeSession(){
                    log.debug("produce the KnowledgeSession ...");
                    //Create the knowledgeBase
                    /*This factory is used to build the knowledge base resources that are held collectively in KnowledgePackages.*/
                    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
                    //Add all processes to the knowledgeBuilder
                    List<Resource> resources = getProcessDefinitionList();
                    for (Resource resource : resources) {
                              kbuilder.add(resource, ResourceType.BPMN2);
                    }
                    /*Create a new KnowledgeBase from the knowledge packages that have been added to this builder.
                     * An exception is thrown if there are any errors.*/
//                    assertFalse( kbuilder.hasErrors() );
                    if ( kbuilder.hasErrors() ) {
                         log.error( kbuilder.getErrors().toString() );
                     }
                    KnowledgeBase kbase = kbuilder.newKnowledgeBase();
                    /*Create a new StatefulKnowledgeSession using the default session configuration.
                     * Don't forget to dispose() session when you are done.
                     *
                     * StatefulKnowledgeSession is the most common way to interact with the engine.
                     * A StatefulKnowledgeSession allows the application to establish an iterative conversation with the engine,
                     * where the state of the session is kept across invocations.*/
                    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
        logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "loggerFile", 1000);
        /*A work item manager is responsible for finding the right work item handler when a work item should be executed
         * and should be notified when this work item has been completed (or aborted).
         *
         * Register the given handler for all work items of the given type of work
         * This part is done in the LocalHumanTaskService*/
//        ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler );
        ksession.getEnvironment().set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
        /*
         * Register WorkItem Handler for Email
         */
        //EmailWorkItemHandler emailHandler =  new EmailWorkItemHandler();
        //ksession.getWorkItemManager().registerWorkItemHandler("Email", emailHandler);
        return ksession;
          }
          public KnowledgeRuntimeLogger getLogger(){
                    return this.logger;
          }
          private List<Resource> getProcessDefinitionList(){
                    List<Resource> resourceList = new ArrayList<>();
                    resourceList.add(ResourceFactory.newClassPathResource("workflows/MyFlow.bpmn2"));
                    /**
                     * TODO
                     * add all other process here
                     */
                    return resourceList;
          }
}
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Event;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import org.drools.runtime.StatefulKnowledgeSession;
import org.jboss.seam.security.Identity;
import org.drools.runtime.process.ProcessInstance;
import org.jbpm.task.Status;
import org.jbpm.task.query.TaskSummary;
import org.jbpm.task.service.local.LocalHumanTaskService;
import org.jbpm.workflow.instance.WorkflowProcessInstance;
import com.st.ams.tools.ClaimEventListener;
import com.ste.ws.authentication.seam.api.UserLDAP;
/**
* Linked to the task management view
*
*/
          private static final long serialVersionUID = 7768657778155604411L;
          private List<Status> listStatus = new ArrayList<Status>();
          public org.jbpm.task.TaskService getTaskService(){
                    return LocalHumanTaskService.getTaskService(kSession);
          }
          private List<TaskSummary> userTaskList = new ArrayList<TaskSummary>();
          private Map<String, List<TaskSummary>> groupTaskMap = new HashMap<String, List<TaskSummary>>();
          private TaskSummary manageTask;
          private List<String> groups;
                    System.out.println("init task manager ...");
                    //Load user tasks
                    listStatus.clear();
                    listStatus.add(Status.Reserved);listStatus.add(Status.InProgress);
                    System.out.println("load task list for user : "+((UserLDAP)identity.getUser()).getUser().getLogin());
                    userTaskList = new ArrayList<TaskSummary>(getTaskService().getTasksAssignedAsPotentialOwnerByStatus(
                                                                                ((UserLDAP)identity.getUser()).getUser().getLogin(),
                                                                                listStatus,
                                                                                "en-UK"));
                    //Load groups and tasks for each group
                    groups = new ArrayList<String>();
                    for(String grp : ((UserLDAP)identity.getUser()).getUser().getGroups()){
                 groups.add(grp);
                 groupTaskMap.put(grp, getGroupTasks(grp));
                    }
          }
          public List<TaskSummary> getUserTaskList() {
                    if((userTaskList == null) || userTaskList.isEmpty()){
                              listStatus.clear();
                              listStatus.add(Status.Reserved);listStatus.add(Status.InProgress);
               //Trick because UserGroupCallBackImpl is not properly implemented
               //TODO correction
                              Set<TaskSummary> set = new HashSet<TaskSummary>(getTaskService().getTasksAssignedAsPotentialOwnerByStatus(
                                                                                                                                                      ((UserLDAP)identity.getUser()).getUser().getLogin(),
                                                                                                                                                      listStatus,
                                                                                                                                                      "en-UK"));
                              userTaskList = new ArrayList<TaskSummary>(set);
                    }
                    return userTaskList;
          }
          /**
           * In order to refresh the user task list
           * This function allow to clear the content of the list
           */
          public void clearUserTaskList(){
                    userTaskList.clear();
          }
          /**
           * In order to refresh the groups task list
           * This function allow to clear the content of all lists
           */
          public void clearAllGroupTaskList(){
                    List<String> keys = new ArrayList<>(groupTaskMap.keySet());
                    for(String grp : keys){
                              clearGroupTaskList(grp);
                    }
          }
          /**
           * In order to refresh the group task list
           * This function allow to clear the content of the list
           */
          public void clearGroupTaskList(String group){
                    groupTaskMap.put(group, null);
          }
          /**
           * return all group tasks available for the user
           */
          public List<TaskSummary> getAllGroupTaskList() {
                    List<TaskSummary> allGroupTask = new ArrayList<TaskSummary>();
                    Iterable<List<TaskSummary>> mapValues = groupTaskMap.values();
                    for(List<TaskSummary> entry : mapValues){
                              allGroupTask.addAll(entry);
                    }
                    return allGroupTask;
          }
          public List<String> getUserGroups(){
                    if((groups == null) || groups.isEmpty()){
                              groups = new ArrayList<String>();
                              for(String grp : ((UserLDAP)identity.getUser()).getUser().getGroups()){
groups.add(grp);
                              }
                    }
                    return groups;
          }
          /**
           * return tasks available for the group
           */
          public List<TaskSummary> getGroupTaskList(String group){
                    if((groupTaskMap.get(group) == null) || groupTaskMap.get(group).isEmpty()){
                              groupTaskMap.put(group, getGroupTasks(group));
                    }
                    return groupTaskMap.get(group);
          }
          /**
           * return tasks available for the group
           */
          public List<TaskSummary> getGroupTasks(String group){
                    listStatus.clear();
                    listStatus.add(Status.Ready);
          //Trick because UserGroupCallBackImpl is not properly implemented
          //TODO correction
          Set<TaskSummary> set = new HashSet<TaskSummary>(getTaskService().getTasksAssignedAsPotentialOwnerByStatus(group, listStatus, "en-UK"));
                    return new ArrayList<TaskSummary>(set);
          }
          public void removeGroup(String group){
                    groups.remove(group);
          }
          public void addGroup(String group){
                    if((group != null) && !group.isEmpty())
                              groups.add(group);
          }
          public void addGroupTask(String group){
                    groupTaskMap.put(group, getGroupTasks(group));
          }
          /**
           * Start a new processInstance of an existing Process
           * and set the variables of this instance
           */
          public ProcessInstance startProcess(String processId, Map<String, Object> parameters){
                    ProcessInstance p = kSession.startProcess(processId,parameters);
                    return p;
          }
          /**
           * Return the WorkflowProcessInstance associated to a Task
           * This instance allow to access the map of variables
           */
          public WorkflowProcessInstance getWorkflowProcessInstance(long processInstanceId){
                    return (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
          }
          /**
           * Start a new processInstance of an existing Process
           */
          public ProcessInstance startProcess(String processId){
                    return kSession.startProcess(processId);
          }
          /**
           * When a user claim a task, the task go to RESERVED state
           * Then we call start and the task goes to IN_PROGRESS state
           * and is not visible for others
           */
          public void claimTask(TaskSummary task){
                    addMessage("task "+task.getId()+" claimed");
                    setManageTask(task);
                    getTaskService().claim(task.getId(),
                                        ((UserLDAP)identity.getUser()).getUser().getLogin());
                    getTaskService().start(task.getId(), ((UserLDAP)identity.getUser()).getUser().getLogin());
                    event.fire(new ClaimEventListener());
          }
          /**
           * return a task to group task
           */
          public void revokeTask(TaskSummary task){
                    addMessage("task "+task.getId()+" revoked");
                    setManageTask(task);
                    getTaskService().release(task.getId(),
                                        ((UserLDAP)identity.getUser()).getUser().getLogin());
          }
          public void completeTask(TaskSummary task, Object results){
                    getTaskService().completeWithResults(task.getId(),
                                        ((UserLDAP)identity.getUser()).getUser().getLogin(), results);
          }
          /**
           * The current manage task
           */
          public TaskSummary getManageTask() {
                    return manageTask;
          }
          /**
           * Set the currently manage task
           * (save it during the session)
           */
          private void setManageTask(TaskSummary manageTask) {
                    this.manageTask = manageTask;
          }
          /**
           * faces message rendered
           */
          public void addMessage(String summary) { 
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary,  null); 
        FacesContext.getCurrentInstance().addMessage(null, message); 
    }
}
You have to implement the UserGroupCallBackImpl. (See the doc for that : http://docs.jboss.org/jbpm/v5.4/userguide/ch.human-tasks.html#d0e5419 http://docs.jboss.org/jbpm/v5.4/userguide/ch.human-tasks.html#d0e5419)

You have to register your implementation of usergroupcallback by creating a file jbpm.usergroup.callback.properties in the folder resources.
jbpm.usergroup.callback=com.your.package.path.with.dot.MyUserGroupCallbackImpl
Loading Image... Loading Image...


The persistence.xml must be configured like this :
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/796530#796530]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Anand Kumar Jha
2013-02-09 03:56:04 UTC
Permalink
Anand Kumar Jha [https://community.jboss.org/people/anandaryan] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/796861#796861

--------------------------------------------------------------
thanks a lot sandra!...:)
Hope this will help me a lot...:)
here i kickstart///...:)
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/796861#796861]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Pedro Gonçalves
2012-06-21 12:17:37 UTC
Permalink
Pedro Gonçalves [https://community.jboss.org/people/pgoncalves] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/743352#743352

--------------------------------------------------------------
What I do is this:

public void startProcess(CoreData coreData, String definitionId) {
 
     //build variables.......
 
     ProcessInstance processInstance = kSession.startProcess(definitionId, variables);
 
     ProcessInfoData processInfoData = new ProcessInfoData();
 
     processInfoData.setkSessionId(kSession.getId());
     processInfoData.setProcessInstanceId(processInstance.getId());
 
     serviceProcessInfo.create(processInfoData);
}


So, in my db, I have a table that maps KnowledgeSession <---> ProcessInstance
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/743352#743352]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Mauricio Salatino
2012-06-21 12:24:53 UTC
Permalink
Mauricio Salatino [https://community.jboss.org/people/salaboy21] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/743354#743354

--------------------------------------------------------------
Yes, that's a very valid option.
It depends on what your business processes are doing.
You can also store more information, like for example the workItemId that is pending to be completed, as well as business information that identifies in an unique way
the ksession, processInstance, workItem + any business data relevant for finding out the runtime where that process was running.

For some situations running multiple process instances in the same ksession could be required or useful.

Cheers
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/743354#743354]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Jakub Ferschmann
2012-06-21 12:48:03 UTC
Permalink
Jakub Ferschmann [https://community.jboss.org/people/fersmi] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/743367#743367

--------------------------------------------------------------
Ok,
can I use one kSession for all process instance in web application? If kSession will load every request (different thread) from the database, is it thread safe?
In jBPM3 I can use one context with default name for every interaction with workflow engine. Context is not stored in the database and it is unlike jBPM5

JbpmConfiguration config;
....
try {
    context = config.createJbpmContext(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);

   .... // do something with context
} finally {
    if (context != null) {
        context.close();
    }
}
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/743367#743367]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Pedro Gonçalves
2012-06-21 12:56:08 UTC
Permalink
Pedro Gonçalves [https://community.jboss.org/people/pgoncalves] created the discussion

"Re: Integrating jBPM 5 into web application - architecture"

To view the discussion, visit: https://community.jboss.org/message/743369#743369

--------------------------------------------------------------
Sessions can be created based on a knowledge base and are used to execute processes and interact with the engine. You can create as many independent session as you need and creating a session is considered relatively lightweight. How many sessions you create is up to you. In general, most simple cases start out with creating one session that is then called from various places in your application. You could decide to create multiple sessions if for example you want to have multiple independent processing units (for example, if you want all processes from one customer to be completely independent from processes for another customer, you could create an independent session for each customer) or if you need multiple sessions for scalability reasons. If you don't know what to do, simply start by having one knowledge base that contains all your process definitions and create one session that you then use to execute all your processes.
I'm still a bit lost in jbpm architecture, and trying to understand all the concepts. But I thought (or guess :-/ ) that in the future I will need one ksession per process instance...
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/743369#743369]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...