13 Replies Latest reply on Mar 16, 2007 3:00 AM by aakil786

    A timer associated to a process instance ?

    biggef

      I would like to set up timers associated to process instances. It seems as if it is only possible to associate them to task instances or nodes, but I may have skipped something in the documentation (or maybe some body has written suc a timer).
      So can a timer be associated with a process instance ?

        • 1. Re: A timer associated to a process instance ?
          cpob

          According to the XML Schema, you can put a create-timer element on a process definition, but it never did anything through my testing.

          What you could do, is put a create-timer on the start-node and then an cancel-timer on all end nodes.

          • 2. Re: A timer associated to a process instance ?
            biggef

             

            "cpob" wrote:
            According to the XML Schema, you can put a create-timer element on a process definition, but it never did anything through my testing

            ie nothing happens when the timer fires ?
            Was the timer cancelled when leaving a node ?

            "cpob" wrote:
            What you could do, is put a create-timer on the start-node and then an cancel-timer on all end nodes.
            The idea was indeed something like this, in order to set alerts dynamicaly on some sections of the workflow.

            • 3. Re: A timer associated to a process instance ?
              cpob

               

              "biggef" wrote:
              "cpob" wrote:
              According to the XML Schema, you can put a create-timer element on a process definition, but it never did anything through my testing

              ie nothing happens when the timer fires ?
              Was the timer cancelled when leaving a node ?


              It never created the timer. The action to create the timer is in the DB, it just never gets created, and therefore never starts.

              Look at the create-timer and cancel-timer elements. They allow you to create a timer, only to cancel it anywhere else in the flow (Timer names must be unique). Check out section 16.4.22 of the User Guide.

              • 4. Re: A timer associated to a process instance ?
                biggef

                Do you know about a documentation on how to handle with timer programatically ? (basically, create it, get it, cancel it and modify it)

                • 5. Re: A timer associated to a process instance ?
                  cpob

                  Look at the source code in CreateTimerAction and CancelTimerAction, they create and cancel timers programmatically.

                  • 6. Re: A timer associated to a process instance ?
                    biggef

                    Well thanks.
                    I followed the example of code in CreateTimerAction and CancelTimerAction (and switched from jbpm 3.0.2 to 3.1.2) and now I can see my timers in the DB. But when I try to set an Action to be called when the timer fires, I got an error.

                    Here is my related code:

                    Action timerAction = new Action();
                    Delegation delegation = new Delegation();
                    delegation.setClassName("logique.alerte.TimerHandler");
                    timerAction.setActionDelegation(delegation);
                    String sDueDate = "5 minutes";
                    String sTimerName = "bob";
                    Date dDueDate = businessCalendar.add( new Date(), duration );

                    Timer timer = new Timer(executionContext.getToken());
                    timer.setName(sTimerName);
                    timer.setDueDate(dDueDate);
                    timer.setAction(timerAction);
                    timer.setGraphElement(executionContext.getEventSource());

                    SchedulerService schedulerService = (SchedulerService) Services.getCurrentService(Services.SERVICENAME_SCHEDULER);
                    schedulerService.createTimer(timer);


                    And here is the error:
                    org.jbpm.persistence.JbpmPersistenceException: couldn't commit hibernate session
                    at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:172)
                    at org.jbpm.svc.Services.close(Services.java:211)
                    at org.jbpm.JbpmContext.close(JbpmContext.java:139)
                    at logique.JbpmManager.closeSession(JbpmManager.java:36)
                    at servlet.NouveauDossier.postRequest(NouveauDossier.java:94)
                    at logique.servlet.ServletContenu.traiterRequete(ServletContenu.java:132)
                    at logique.servlet.ServletContenu.doPost(ServletContenu.java:163)
                    at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
                    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                    at logique.ihm.XsltFilter.doFilter(XsltFilter.java:81)
                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
                    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
                    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
                    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
                    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
                    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
                    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
                    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
                    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
                    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
                    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
                    at java.lang.Thread.run(Thread.java:595)
                    Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.jbpm.graph.def.Action
                    at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
                    at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
                    at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:221)
                    at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:476)
                    at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:2785)
                    at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:457)
                    at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:180)
                    at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:104)
                    at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
                    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
                    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
                    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:877)
                    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:344)
                    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
                    at org.jbpm.persistence.db.DbPersistenceService.close(DbPersistenceService.java:162)
                    ... 28 more

                    So how can I save the Action before closing the session ?

                    • 7. Re: A timer associated to a process instance ?
                      kukeltje

                      uhhmm... by saving the action? Learn a little how hibernate works. Lots of info on this (very generic) hibernate error.

                      • 8. Re: A timer associated to a process instance ?
                        biggef

                        OK, I solved the last hibernate problem. Now I have my timers (actions and delegations) correctly shown in the database ... but they never fire. I must have missed something but I can find it.
                        I heard from a TimerExecutor in the user guide. It is shown as responsible for making the timers fire. Is there someting special to do to make it work ? (Is it so hard to have one's timers work !?)

                        PS: I have the horrible feeling to progress small step by small step, every time spending much time on trying to find docs and experimenting. Is there not a doc I missed with the whole thing explained (a tuto about timers, a timer userguide, or something like this). I often feel as if I ask for rubbishes :-S.

                        • 9. Re: A timer associated to a process instance ?
                          olivier_debels

                          Timers are fired in the schedulerthread which is started up in the JbpmThreadsServlet of the jbpm-webapp.

                          In order to make it run you have to add the code to start the schedulerthread or also deploy the webapp.

                          • 10. Re: A timer associated to a process instance ?
                            biggef

                            Thanks. I'll try.

                            • 11. Re: A timer associated to a process instance ?
                              biggef

                              I now start the schedulerthread and all work perfectly.

                              Thank you very much to all for your answers.

                              • 12. Re: A timer associated to a process instance ?
                                aakil786

                                biggef

                                How did you save the Action? I am trying to do something simila,r create Actions to unsuspend a process after a period of time after suspending it. I am a newbie to hibernate and jbpm and i have tried saving whatever I can for instance process, task, token via the jbpmContext but no luck. So yes I can see it is failing due to the Action not being saved but how do one get it to save with the type of coding that you have done.

                                Thanks
                                Aakil


                                • 13. Re: A timer associated to a process instance ?
                                  aakil786

                                  just a note to anyone else with 3.1.2 that might experience this problem, it is fixed in 3.1.3. I am using it in 3.1.4 so far without any problems.