7 Replies Latest reply on Oct 18, 2006 4:55 PM by juangiovanolli

    Help with Timers

    ulfreich

      Hi, in my process I'm declaring a timer just like in the examples provided in the source code at org.jbpm.scheduler.exe, it creates succesfully (instance.getSchedulerInstance().getScheduledTimers(); ). However, in my junit tests I wait some time after the Timer is declared, but nothing happens..

      The definition is as follows:

      <task-node name="task2">
       <task name="task2" swimlane="God" blocking="false">
       <controller>
       <variable name="var1" access="read" />
       <variable name="var2" access="read" />
       <variable name="user" />
       </controller>
       </task>
       <timer duedate="20 seconds" repeat="10 seconds">
       <action class="com.(...).RemindActor">
       <swimlane>God</swimlane>
       </action>
       </timer>
       <transition name="toTask3" to="task3"></transition>
       </task-node>


      Does anybody see what am I doing wrong? tnx!

        • 1. Re: Help with Timers

          A scheduled timer is not automatically an active timer.

          Try to add a saveProcessInstance at the end of your junit test.
          Check the jbpm_timer to see if your timer is really active or not.


          Regards,
          David

          • 2. Re: Help with Timers
            tom.baeyens

            also note that a separate entity (like the SchedulerThread) should be running separatly from your unit test in order for the timer to be executed.

            regards, tom.

            • 3. Re: Help with Timers
              ulfreich

              Thanks for your help, I found the SchedulerMain in jbpm's code and Im trying to run it.

              First I had to put the line:

              scheduler.getSchedulerThread().addListener(new LogListener());

              after the line:

              scheduler.start();

              for the scheduler to run (there is no SchedulerThread until the scheduler is started).

              The scheduler works, but in each execution throws the following strange Exception:

              12:54:44,791 DEBUG QueryTranslatorImpl:177 - HQL: select ti from org.jbpm.scheduler.exe.Timer as ti where ti.exception is null order by ti.dueDate asc
              12:54:44,791 DEBUG QueryTranslatorImpl:178 - SQL: select timer0_.ID_ as col_0_0_ from JBPM_TIMER timer0_ where timer0_.EXCEPTION_ is null order by timer0_.DUEDATE_ asc
              12:54:44,791 DEBUG ErrorCounter:72 - throwQueryException() : no errors
              12:54:44,791 DEBUG AbstractBatcher:290 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
              12:54:44,916 DEBUG SQL:324 - select timer0_.ID_ as col_0_0_ from JBPM_TIMER timer0_ where timer0_.EXCEPTION_ is null order by timer0_.DUEDATE_ asc
              12:54:44,916 DEBUG AbstractBatcher:378 - preparing statement
              12:54:44,931 DEBUG JDBCExceptionReporter:63 - SQL Exception
              java.sql.SQLException: Table not found: JBPM_TIMER in statement [select timer0_.ID_ as col_0_0_ from JBPM_TIMER timer0_ where timer0_.EXCEPTION_ is null order by timer0_.DUEDATE_ asc]
               at org.hsqldb.jdbc.Util.throwError(Unknown Source)
               at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
               at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
               at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:396)
               at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:334)
               at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
               at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
               at org.hibernate.loader.hql.QueryLoader.iterate(QueryLoader.java:410)
               at org.hibernate.hql.ast.QueryTranslatorImpl.iterate(QueryTranslatorImpl.java:281)
               at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:935)
               at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
               at org.jbpm.db.SchedulerSession.findTimersByDueDate(SchedulerSession.java:51)
               at org.jbpm.scheduler.impl.SchedulerThread.executeTimers(SchedulerThread.java:69)
               at org.jbpm.scheduler.impl.SchedulerThread.run(SchedulerThread.java:34)
              12:54:44,931 WARN JDBCExceptionReporter:71 - SQL Error: -22, SQLState: S0002
              12:54:44,931 ERROR JDBCExceptionReporter:72 - Table not found: JBPM_TIMER in statement [select timer0_.ID_ as col_0_0_ from JBPM_TIMER timer0_ where timer0_.EXCEPTION_ is null order by timer0_.DUEDATE_ asc]
              12:54:44,931 DEBUG JDBCExceptionReporter:63 - could not execute query using iterate [select timer0_.ID_ as col_0_0_ from JBPM_TIMER timer0_ where timer0_.EXCEPTION_ is null order by timer0_.DUEDATE_ asc]
              java.sql.SQLException: Table not found: JBPM_TIMER in statement [select timer0_.ID_ as col_0_0_ from JBPM_TIMER timer0_ where timer0_.EXCEPTION_ is null order by timer0_.DUEDATE_ asc]
               at org.hsqldb.jdbc.Util.throwError(Unknown Source)
               at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
               at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
               at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:396)
               at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:334)
               at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
               at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
               at org.hibernate.loader.hql.QueryLoader.iterate(QueryLoader.java:410)
               at org.hibernate.hql.ast.QueryTranslatorImpl.iterate(QueryTranslatorImpl.java:281)
               at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:935)
               at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
               at org.jbpm.db.SchedulerSession.findTimersByDueDate(SchedulerSession.java:51)
               at org.jbpm.scheduler.impl.SchedulerThread.executeTimers(SchedulerThread.java:69)
               at org.jbpm.scheduler.impl.SchedulerThread.run(SchedulerThread.java:34)
              12:54:44,931 WARN JDBCExceptionReporter:71 - SQL Error: -22, SQLState: S0002
              12:54:44,931 ERROR JDBCExceptionReporter:72 - Table not found: JBPM_TIMER in statement [select timer0_.ID_ as col_0_0_ from JBPM_TIMER timer0_ where timer0_.EXCEPTION_ is null order by timer0_.DUEDATE_ asc]
              12:54:44,947 ERROR SchedulerSession:53 - org.hibernate.exception.SQLGrammarException: could not execute query using iterate
              12:54:44,947 DEBUG JDBCTransaction:132 - rollback
              12:54:44,947 DEBUG JDBCContext:278 - before transaction completion
              12:54:44,947 DEBUG SessionImpl:372 - before transaction completion
              12:54:44,947 DEBUG JDBCTransaction:143 - rolled back JDBC Connection
              12:54:44,947 DEBUG JDBCContext:283 - after transaction completion
              12:54:44,947 DEBUG SessionImpl:403 - after transaction completion
              12:54:44,947 DEBUG SessionImpl:269 - closing session
              12:54:44,947 DEBUG ConnectionManager:317 - closing JDBC connection [ (open PreparedStatements: 1, globally: 1) (open ResultSets: 0, globally: 0)]
              12:54:44,947 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
              12:54:44,947 DEBUG JDBCContext:283 - after transaction completion
              12:54:44,947 DEBUG SessionImpl:403 - after transaction completion
              12:54:44,947 ERROR JbpmSession:105 - java.lang.NullPointerException
              12:54:44,947 DEBUG JDBCTransaction:132 - rollback
              12:54:44,947 DEBUG JDBCContext:278 - before transaction completion
              12:54:44,947 DEBUG SessionImpl:372 - before transaction completion
              12:54:44,947 DEBUG JDBCContext:283 - after transaction completion
              12:54:44,947 DEBUG SessionImpl:403 - after transaction completion
              12:54:44,947 ERROR JbpmSession:179 - couldn't rollback hibernate transaction
              org.hibernate.SessionException: Session is closed
               at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:131)
               at org.hibernate.transaction.JDBCTransaction.rollbackAndResetAutoCommit(JDBCTransaction.java:163)
               at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:142)
               at org.jbpm.db.JbpmSession.handleException(JbpmSession.java:177)
               at org.jbpm.db.JbpmSession.commitTransaction(JbpmSession.java:106)
               at org.jbpm.db.JbpmSession.commitTransactionAndClose(JbpmSession.java:129)
               at org.jbpm.scheduler.impl.SchedulerThread.executeTimers(SchedulerThread.java:121)
               at org.jbpm.scheduler.impl.SchedulerThread.run(SchedulerThread.java:34)
              12:54:44,947 WARN JbpmSession:212 - can't pop current session: are you calling JbpmSession.close() multiple times ?
              12:54:44,947 INFO SchedulerThread:43 - runtime exception while executing timers
              java.lang.RuntimeException: couldn't commit transaction
               at org.jbpm.db.JbpmSession.commitTransaction(JbpmSession.java:107)
               at org.jbpm.db.JbpmSession.commitTransactionAndClose(JbpmSession.java:129)
               at org.jbpm.scheduler.impl.SchedulerThread.executeTimers(SchedulerThread.java:121)
               at org.jbpm.scheduler.impl.SchedulerThread.run(SchedulerThread.java:34)
              Caused by: java.lang.NullPointerException
               at org.jbpm.db.JbpmSession.commitTransaction(JbpmSession.java:102)
               ... 3 more
              

              It's strange because the SessionFactory starts including class Timer (mapped to JBPM_TIMER), and the table exists in the database.. Any Ideas? Thx for your help!

              • 4. Re: Help with Timers
                ulfreich

                Ok, the scheduler creates a SessionFactory of its own but with default properties (hypersonic, user=sa, password=), and my hibernate.properties is in the path.. where does the Scheduler look for properties? thanks..

                • 5. Re: Help with Timers
                  gygerl

                  Hi.
                  Got the same problem.
                  I changed config in file "default.jbpm.cfg.xml"

                  <string name="resource.hibernate.cfg.xml" value="oracle/hibernate.cfg.xml" />
                  

                  and it worked.
                  Got another error so :
                  17:12:37,667 [JbpmScheduler] INFO ConnectionProviderFactory : Initializing connection provider: org.hibernate.connection.DatasourceConnectionProvider
                  17:12:37,682 [JbpmScheduler] INFO NamingHelper : JNDI InitialContext properties:{}
                  17:12:37,713 [JbpmScheduler] FATAL DatasourceConnectionProvider : Could not find datasource: java:/OracleDS
                  javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
                   at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
                   at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
                   at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
                   at javax.naming.InitialContext.lookup(InitialContext.java:351)
                   at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
                   at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
                   at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
                   at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:366)
                   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
                   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1859)
                   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1152)
                   at org.jbpm.persistence.db.DbPersistenceServiceFactory.getSessionFactory(DbPersistenceServiceFactory.java:90)
                   at org.jbpm.persistence.db.DbPersistenceService.getSessionFactory(DbPersistenceService.java:74)
                   at org.jbpm.persistence.db.DbPersistenceService.getSession(DbPersistenceService.java:78)
                   at org.jbpm.persistence.db.DbPersistenceService.getSchedulerSession(DbPersistenceService.java:243)
                   at org.jbpm.JbpmContext.getSchedulerSession(JbpmContext.java:425)
                   at org.jbpm.scheduler.impl.SchedulerThread.executeTimers(SchedulerThread.java:103)
                   at org.jbpm.scheduler.impl.SchedulerThread.run(SchedulerThread.java:70)
                  

                  any idea ?
                  Thanks in advance.

                  • 6. Re: Help with Timers
                    gygerl

                    Deployed jbpm webapp in order to start the scheduler.

                    • 7. Re: Help with Timers
                      juangiovanolli

                      if you find the answer for your question, please let me know.


                      Thanks from Argentina