7 Replies Latest reply on Nov 3, 2005 5:16 AM by pedro costa

    Iterator in tasks-nodes

    pedro costa Apprentice

      In this code,

      while(processInstance.getTaskMgmtInstance().getUnfinishedTasks(processInstance.getRootToken())
       .iterator().hasNext())
       {
       ...
      
       System.out.println("ITERATION --> " + k);
      
       try
       {
       taskInstance = (TaskInstance) processInstance.getTaskMgmtInstance().getUnfinishedTasks(processInstance.getRootToken())
       .iterator().next();
       }
       catch(NoSuchElementException ex)
       {
       System.out.println("NOOOOOOOOOOOOOOOOOOOOOOOOO");
       }
       k++;
      
       }
      
      
      


      i have associated 3 task-nodes sequentially. When i pass through them and i reach de last one, the program doesn't jump out of the while passing the hasNext, and i catch the exception. I don't understand why the hasNext doesn't work here.

      Anybody can explain this?

      Thanks

        • 1. Re: Iterator in tasks-nodes
          pedro costa Apprentice

          If i do
          processInstance.getTaskMgmtInstance().getUnfinishedTasks(processInstance.getRootToken()).size();
          i get 1 task instead of 3.

          • 3. Re: Iterator in tasks-nodes
            Ronald van Kuijk Master

            look at a 'token' as something that traverses the process (like petri-nets') So this token is always in just one node. If you exit that node it goes to the next (or splitting itself in case of forks)

            Try reading the jBPM docs a little and look at the testcases you can see there what happens

            • 4. Re: Iterator in tasks-nodes
              Ronald van Kuijk Master

              Try this: does it make a difference?

              Iterator myIt = processInstance.getTaskMgmtInstance().getUnfinishedTasks(processInstance.getRootToken()).iterator();
              while(myIt.hasNext()) {
              
               ...
              
               System.out.println("ITERATION --> " + k);
              
               try {
               taskInstance = (TaskInstance) myIt.next();
               } catch(NoSuchElementException ex) {
               System.out.println("NOOOOOOOOOOOOOOOOOOOOOOOOO");
               }
               k++;
              }
              


              And btw? what is in the ..... A 'signal' or 'endtask' or something? I mean, do you do something somewhere with the tasks?


              • 5. Re: Iterator in tasks-nodes
                pedro costa Apprentice

                Yes, i do things with the task, but i didn't put the code here.

                • 6. Re: Iterator in tasks-nodes
                  pedro costa Apprentice

                  When i do the code like kukeltje says, i only get the first task, and right after that, the code jump off the while.

                  Where is my processdefinition.xml

                  <?xml version="1.0" encoding="UTF-8"?>
                  
                  <process-definition name='simple'>
                   <start-state name='start'>
                   <transition name='to_registo_ocorrencia' to='registo_ocorrencia'/>
                   </start-state>
                  
                   <!-- Tarefa 1 -->
                   <task-node name='registo_ocorrencia'>
                   <task name='RegistoOcorrenciaTask'>
                   <controller>
                   <variable name='data' access='read,required' mapped-name='data' />
                   <variable name='hora' access='read,required' mapped-name='hora' />
                   <variable name='local' access='read,required' mapped-name='local'/>
                   <variable name='data_registo' access='read,required' mapped-name='data_registo'/>
                   </controller>
                   </task>
                   <transition name='to_lista_tarefas' to='lista_tarefas'/>
                   </task-node>
                  
                   <!-- Tarefa 2 -->
                   <task-node name='lista_tarefas'>
                   <task name='ListaTarefasTask'/>
                   <transition name='to_notificacoes' to='notificacoes'></transition>
                   </task-node>
                  
                   <!-- Tarefa 3 -->
                   <task-node name='notificacoes'>
                   <task name='NotificacoesTask'>
                   </task>
                   <transition name='to_end' to='end'>
                   <!-- <action name='action' class='com.samples.action.GravarOcorrenciaHandler'></action> -->
                   </transition>
                   </task-node>
                  
                   <end-state name='end'></end-state>
                  </process-definition>
                  
                  


                  This xml code has some words in portuguese

                  • 7. Re: Iterator in tasks-nodes
                    pedro costa Apprentice

                    Now i do another question, beside the first one. How can i get the total of task-node?

                    Thanks.