1 Reply Latest reply on Apr 22, 2008 8:20 PM by agenttokyo

    Problem with TimerService

    hasc

      Hi,

      i posted this question already in the seam forum, but i was told I should post the question here again...

      I wrote a simple stateless bean to test the TimerService. i am using jboss 4.2.0GA

      bean using the TimerService:

      @Stateless
      @Name("listener")
      public class DBChangeListenerService implements DBChangeListener {
      
       @Resource TimerService timerservice;
      
       @Logger Log log;
      
       public DBChangeListenerService() {}
      
       public void initTimer() {
       log.info("initTimer");
       timerservice.createTimer(2*60*1000, 2*60*1000,"DBChangeListener");
       }
      
       @Timeout
       public void queryState(Timer timer) {
       log.info("query db state");
       }
      }
      


      and the bean calling the initTimer() method:
      @Stateless
      @AutoCreate
      @Name("objectcache")
      public class ObjectCacheService implements ObjectCache{
      
      
       @In(create=true)
       DBChangeListenerService listener;
      
       public void init() {
       listener.initTimer();
       }
      }


      When the init() method is called the following exception is trhrown:
      2007-10-02 14:56:55,437 ERROR [org.jboss.ejb.txtimer.TimerServiceImpl] Cannot create txtimer
      java.lang.IllegalStateException: Unable to persist timer
       at org.jboss.ejb.txtimer.DatabasePersistencePolicy.insertTimer(DatabasePersistencePolicy.java:124)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      ...
      ...
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
       at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:437)
       at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:381)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: org.jboss.util.NestedSQLException: Could not enlist in transaction on entering meta-aware
       object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to en
      list resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: -3f57fdff:555:47023fba:53 status: ActionStatus.ABORT_ONLY >); - nested throwable: (org.jboss.resource.JBossResourceException: Could not enlist in transaction o
      n entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Thr
      owable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: -3f57fdff:555:47023fba:53 status: ActionStatus.ABORT_ONLY >))
       at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:94)
       at org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin.insertTimer(GeneralPurposeDatabase
      PersistencePlugin.java:199)
       at org.jboss.ejb.txtimer.DatabasePersistencePolicy.insertTimer(DatabasePersistencePolicy.java:120)
       ... 317 more
      Caused by: org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering me
      ta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabl
      ed to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: -3f57fdff:555:47023fba:53 status: ActionStatus.ABORT_ONLY >)
       at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnecti
      onManager.java:343)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2.reconnectManagedConnection(BaseConne
      ctionManager2.java:518)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionMan
      ager2.java:399)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConne
      ction(BaseConnectionManager2.java:842)
       at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
       ... 319 more
      Caused by: javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see t
      he previous warnings. tx=TransactionImple < ac, BasicAction: -3f57fdff:555:47023fba:53 status: ActionStatus.ABORT_ONLY >
       at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener$TransactionSy
      nchronization.checkEnlisted(TxConnectionManager.java:744)
       at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.enlist(TxConn
      ectionManager.java:577)
       at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnecti
      onManager.java:337)
       ... 323 mor



      any tips would be great.

      Thanks and regards,
      hasc

        • 1. Re: Problem with TimerService
          agenttokyo

           

          "hasc" wrote:
          Hi,

          i posted this question already in the seam forum, but i was told I should post the question here again...

          I wrote a simple stateless bean to test the TimerService. i am using jboss 4.2.0GA



          I hope you long ago solved your issue =) Bit since I saw this problem a number of places w/out a solution I'm commenting here.

          I ran into this moving from Jboss 4.0.5 to 4.2.2 using Postgresql 8.1

          Your DS doesn't support the XA interface. I assume there is a way to do this in HSQL as well but found no answer (I saw no XA DataSource in the hsqldb.jar)? But... here is my solution.

          In my postgres-dx.xml I had the usual local-tx-datasource, which was used for my entities. I then added the xa-datasource

          <datasources>
           <local-tx-datasource>
           <jndi-name>PostGresDS</jndi-name>
           <connection-url>jdbc:postgresql://localhost:5432/blah</connection-url>
           <driver-class>org.postgresql.Driver</driver-class>
           <user-name>user</user-name>
           <password>password</password>
           </local-tx-datasource>
          
           <xa-datasource>
           <jndi-name>XAPostGresDS</jndi-name>
           <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
           <xa-datasource-property name="ServerName">localhost</xa-datasource-property>
           <xa-datasource-property name="DatabaseName">blah</xa-datasource-property>
           <xa-datasource-property name="PortNumber">5432</xa-datasource-property>
          
           <xa-datasource-property name="User">user</xa-datasource-property>
           <xa-datasource-property name="Password">password</xa-datasource-property>
          
           <metadata>
           <type-mapping>PostgreSQL</type-mapping>
           </metadata>
           </xa-datasource>
          </datasources>
          


          The type-mapping is from standardjbosscmp-jdbc.xml

          The configuration parameters were identifed in http://wiki.jboss.org/wiki/ConfigDataSources the wiki

          And in your ejb-deployer, you should use your newly configured datasource (in my case XAPostGresDS)

           <mbean code="org.jboss.ejb.txtimer.DatabasePersistencePolicy" name="jboss.ejb:service=EJBTimerService,persistencePolicy=database">
           <!-- DataSourceBinding ObjectName -->
           <depends optional-attribute-name="DataSource">jboss.jca:service=DataSourceBinding,name=XAPostGresDS</depends>
           <!-- The plugin that handles database persistence -->
           <attribute name="DatabasePersistencePlugin">org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin</attribute>
           <!-- The timers table name -->
           <attribute name="TimersTable">TIMERS</attribute>
           </mbean>
          


          I think thats about it.