5 Replies Latest reply on Jun 12, 2011 3:59 AM by kathy89

    event listeners

    kathy89 Newbie

      hi,

       

         can u help me in managing events.i.e, i would like to listen to node entry and exit events ant run a java code to fill process variables or parameters like #{employee}.

       

      i'm just a beginner... so sorry for technical mistakes in my query.

       

       

      thank you.

        • 1. Re: event listeners
          Esteban Aliverti Master

          jBPM version?

          In jBPM5 would be smoething like:

           

           

          kstateful.addEventListener(new ProcessEventListener() {
          
          
                      public void beforeProcessStarted(ProcessStartedEvent event) {
                      }
          
          
                      public void afterProcessStarted(ProcessStartedEvent event) {
                      }
          
          
                      public void beforeProcessCompleted(ProcessCompletedEvent event) {
                      }
          
          
                      public void afterProcessCompleted(ProcessCompletedEvent event) {
                      }
          
          
                      public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
                      }
          
          
                      public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
                      }
          
          
                      public void beforeNodeLeft(ProcessNodeLeftEvent event) {
                      }
          
          
                      public void afterNodeLeft(ProcessNodeLeftEvent event) {
                      }
          
          
                      public void beforeVariableChanged(ProcessVariableChangedEvent event) {
                      }
          
          
                      public void afterVariableChanged(ProcessVariableChangedEvent event) {
                      }
                  });
          
          
          • 2. Re: event listeners
            kathy89 Newbie

            hi Esteban,

             

                 i do not know where to add the code... i'm not using "kstateful".here is the ProcessTest.java code.

             

             

             

             

             

             

             

             

            thank you for replying soon

             

             

             

             

             

             

             

             

             

             

            public class

             

             

             

             

            ProcessTest {

             

             

            public static final void

            main(String[] args) {

             

            try

            {

             

            // load up the knowledge base

             

            KnowledgeBase kbase = readKnowledgeBase();

            StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

            KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession,

            "test"

            , 1000);

            ksession.getWorkItemManager().registerWorkItemHandler(

            "Human Task", new

            WSHumanTaskHandler());

             

            // start a new process instance

             

            Map<String, Object> params =

            new

            HashMap<String, Object>();

             

            //params.put("employee", "krisv");

             

            ksession.startProcess(

            "com.sample.evaluation"

            , params);

            logger.close();

            }

             

            catch

            (Throwable t)

            {

            t.printStackTrace();

            }

            }

             

             

            private static KnowledgeBase readKnowledgeBase() throws

            Exception {

            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

            kbuilder.add(ResourceFactory.newClassPathResource(

            "Evaluation.bpmn"), ResourceType.BPMN2

            );

             

            return

            kbuilder.newKnowledgeBase();

            }

             

            }

             

            • 3. Re: event listeners
              Esteban Aliverti Master

              kstateful is your ksession.

               

              You must add the code I have provided before you do ksession.startProcess(....);

              • 4. Re: event listeners
                kathy89 Newbie

                thank you very much Esteban.

                 

                it was useful.im using the following function,

                 

                public void afterNodeLeft(ProcessNodeLeftEvent event)

                {
                         Mapper map=new Mapper("xxx");

                          ...

                }

                the mapper class is using a xml decoder which in turn is using some classes...n i'm getting an class not found exception for those classes.where do i add the import statements.

                • 5. Re: event listeners
                  kathy89 Newbie

                  hi esteban,

                   

                    i'm sorry.the problem was with my code,which was looked for in a different package.everything is working fine.

                  thank you