6 Replies Latest reply on Feb 25, 2010 6:27 AM by swiderski.maciej

    how to find all processInstance

      Hi guys,

      i start new processInstance everytime i catch an event in my java thread. I'm not in jbpm-console.

      I'd like to see the state and catch the end of them.

      Any suggestions?

      Thanks in advance

        • 1. Re: how to find all processInstance

          I'm trying by myself to make query to db with

          JbpmConfiguration instance = JbpmConfiguration.getInstance();
                    JbpmContext context = instance.getCurrentJbpmContext();
                    try {
                         Session hibernateSession = context.getSession();
                         Query query = hibernateSession
                                   .createSQLQuery("select id_ from...
          

           

          with jbpm-3.1.4.jar. But i have an exception:

          13:07:10,879 INFO  [JbpmConfiguration] using jbpm configuration resource 'jbpm.cfg.xml'
          13:07:10,895 DEBUG [JbpmConfiguration] loading defaults in jbpm configuration
          13:07:10,942 DEBUG [ObjectFactoryImpl] adding object info 'default.jbpm.context'
          13:07:10,942 DEBUG [ObjectFactoryImpl] adding object info 'resource.hibernate.cfg.xml'
          13:07:10,942 DEBUG [ObjectFactoryImpl] adding object info 'resource.business.calendar'
          13:07:10,942 DEBUG [ObjectFactoryImpl] adding object info 'resource.default.modules'
          13:07:10,942 DEBUG [ObjectFactoryImpl] adding object info 'resource.converter'
          13:07:10,942 DEBUG [ObjectFactoryImpl] adding object info 'resource.action.types'
          13:07:10,942 DEBUG [ObjectFactoryImpl] adding object info 'resource.node.types'
          13:07:10,942 DEBUG [ObjectFactoryImpl] adding object info 'resource.parsers'
          13:07:10,957 DEBUG [ObjectFactoryImpl] adding object info 'resource.varmapping'
          13:07:10,957 DEBUG [ObjectFactoryImpl] adding object info 'jbpm.msg.wait.timout'
          13:07:10,957 DEBUG [ObjectFactoryImpl] adding object info 'jbpm.byte.block.size'
          13:07:10,957 DEBUG [ObjectFactoryImpl] adding object info 'mail.smtp.host'
          13:07:10,957 DEBUG [ObjectFactoryImpl] adding object info 'jbpm.task.instance.factory'
          13:07:10,957 DEBUG [ObjectFactoryImpl] adding object info 'jbpm.variable.resolver'
          13:07:10,957 DEBUG [ObjectFactoryImpl] adding object info 'jbpm.mail.address.resolver'
          13:07:10,957 DEBUG [JbpmConfiguration] loading specific configuration...
          13:07:10,973 ERROR [STDERR] Exception in thread "Thread-26"
          13:07:10,973 ERROR [STDERR] org.jbpm.JbpmException: couldn't parse jbpm configuration from resource 'jbpm.cfg.xml'
          13:07:10,973 ERROR [STDERR]     at org.jbpm.JbpmConfiguration.getInstance(JbpmConfiguration.java:284)
          13:07:10,973 ERROR [STDERR]     at org.jbpm.JbpmConfiguration.getInstance(JbpmConfiguration.java:256)
          13:07:10,973 ERROR [STDERR]     at it.vega.jbpm.demo.MyListenerStop.proviamo(Unknown Source)
          13:07:10,973 ERROR [STDERR]     at it.vega.jbpm.demo.MyListener$1.directoryChange(Unknown Source)
          13:07:10,973 ERROR [STDERR]     at it.vega.jbpm.demo.dirListener.DirectoryMonitor.fireNotify(Unknown Source)
          13:07:10,973 ERROR [STDERR]     at it.vega.jbpm.demo.dirListener.DirectoryMonitor.checkRemovals(Unknown Source)
          13:07:10,989 ERROR [STDERR]     at it.vega.jbpm.demo.dirListener.DirectoryMonitor.run(Unknown Source)
          13:07:10,989 ERROR [STDERR]     at java.lang.Thread.run(Thread.java:619)
          13:07:10,989 ERROR [STDERR] Caused by: org.jbpm.JbpmException: no ObjectInfo class specified for element 'import'
          13:07:10,989 ERROR [STDERR]     at org.jbpm.configuration.ObjectFactoryParser.parse(ObjectFactoryParser.java:139)
          13:07:10,989 ERROR [STDERR]     at org.jbpm.configuration.ObjectFactoryParser.parseElements(ObjectFactoryParser.java:117
          )
          13:07:10,989 ERROR [STDERR]     at org.jbpm.configuration.ObjectFactoryParser.parseElementsStream(ObjectFactoryParser.ja
          va:110)
          13:07:10,989 ERROR [STDERR]     at org.jbpm.JbpmConfiguration.parseObjectFactory(JbpmConfiguration.java:303)
          13:07:10,989 ERROR [STDERR]     at org.jbpm.JbpmConfiguration.getInstance(JbpmConfiguration.java:280)
          13:07:11,004 ERROR [STDERR]     ... 7 more
          

           

          So... Any idea? Is there a simple way to find all processInstance given processInstanceId or Key?

          Can anyone help me?

          TIA

          • 2. Re: how to find all processInstance

            Use the Query API to get the list of Process Instances for a given ProcessInstanceID.

             

            I used below code to get the process instances.

            getExecutionService

            • 3. Re: how to find all processInstance

              ProcessEnginer.get(ExecutionService.class)..createProcessInstanceQuery().processInstanceId(ProcessInstanceID).list()

              • 4. Re: how to find all processInstance
                kukeltje
                He is using jBPM 3 I think....
                • 5. Re: how to find all processInstance

                  No, im using jbpm 4.3.

                  I'm explain my case:

                  I have a DirectoryListener and on addFile

                   dm.addDirectoryChangeListener(new DirectoryChangeListener() {
                              public void directoryChange(DirectoryChangeEvent dce) {
                                  File file = (File)dce.getSource();
                                  if (dce.getType() == DirectoryChangeEvent.FILE_ADDED) {
                                       HashMap<String,String> hashMap = new HashMap<String,String>();
                                       hashMap.put("image_path", file.toString());
                                 executionService.startProcessInstanceByKey("DEMO",hashMap);
                                 System.out.println("added: " + file.toString());
                                  } else if (dce.getType() == DirectoryChangeEvent.FILE_REMOVED) {
                                      System.out.println("removed: " + file.toString());
                                  }
                              }
                          });
                  

                   

                  When a file is added on dir, a new processInstace is started.

                   

                  Using

                  List<ProcessInstance> listP = processEngine.get(ExecutionService.class).createProcessInstanceQuery().processInstanceKey("DEMO").list();
                  

                  and while there are a lot of processInstances, the listP is empty.

                  I think that i can't use .processInstanceId("") because every process has a own Id (eg DEMO.xxxxxxx)

                  Any Idea?

                  TIA

                   

                  ciccio

                  • 6. Re: how to find all processInstance
                    swiderski.maciej

                    HI,

                     

                    it seems like key is not set in JBPM4_EXECUTION table that's why the list is empty.

                     

                    You could do one of two things:

                    1. use process definition id to return all process instances of given definition

                    2. assign process definition key and process instance key while starting, this could be a solution if you can use this pair when querying for process instance and then you could use processInstanceId, check out user guide http://docs.jboss.com/jbpm/v4/userguide/html_single/#withakey

                    For instance, you could use something like this: DEMO.{file_name}

                     

                    Cheers,

                    Maciej