3 Replies Latest reply on Apr 9, 2010 6:24 AM by fausto72

    Seam 2.2.0.GA: executing task at startup time

    fausto72

      Hello Everyone,


      this is my issue: I have to index some data in a SQL Server 2000 database, and I have to do this task once, at startup time, just after the application is deployed.


      With this configuration I had no problem, all worked fine:




      • JBoss AS 4.2.2.GA

      • Seam 2.0.2.SP1

      • hibernate-search-3.0.1.GA-1.jar

      • hibernate-commons-annotations-3.1.0.GA.jar




      After the migration from Seam 2.0.2.SP1 to Seam 2.2.0.GA (the jars files are the same) at the deployment time I get this error:




      08:20:58,319 ERROR [0]] Exception sending context initialized event to listener
      instance of class org.jboss.seam.servlet.SeamListener
      org.jboss.seam.InstantiationException: Could not instantiate Seam component: indexer
              at org.jboss.seam.Component.newInstance(Component.java:2144)
              at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
              at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
              at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:116)
              at org.jboss.seam.init.Initialization.init(Initialization.java:740)
              at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:36)
              at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3856)
              at org.apache.catalina.core.StandardContext.start(StandardContext.java:4361)
              at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:790)
              at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:770)
              at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
              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:597)
              at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
              at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.apache.catalina.core.StandardContext.init(StandardContext.java:5312)
              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:597)
              at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
              at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
              at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
              at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
              at org.jboss.Main$1.run(Main.java:508)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: javax.naming.NameNotFoundException: IndexerBean not bound
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
              at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
              at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
              at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
              at javax.naming.InitialContext.lookup(InitialContext.java:392)
              at org.jboss.seam.Component.instantiateSessionBean(Component.java:1400)
              at org.jboss.seam.Component.instantiate(Component.java:1364)
              at org.jboss.seam.Component.newInstance(Component.java:2122)
              ... 141 more
      08:20:58,397 ERROR [StandardContext] Error listenerStart
      08:20:58,397 ERROR [StandardContext] Context [/GestioneEdiliziaPrivata_2.0] startup failed
      due to previous errors
      08:20:58,397 WARN  [ServiceController] Problem starting service jboss.web.deployment:war=GestioneEdiliziaPrivata_2.0.war,id=1414335165
      org.jboss.deployment.DeploymentException:
      URL file:/C:/Program Files/jboss-4.2.2.GA/server/default/tmp/deploy/tmp1786721922624674048GestioneEdiliziaPrivata_2.0-ear.ear-contents/
      GestioneEdiliziaPrivata_2.0-exp.war/ deployment failed
              at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:379)
              at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
              at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
              at org.jboss.web.WebModule.startModule(WebModule.java:83)
              at org.jboss.web.WebModule.startService(WebModule.java:61)
              at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
              at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
              at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
              at $Proxy0.start(Unknown Source)
              at org.jboss.system.ServiceController.start(ServiceController.java:417)
              at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
              at $Proxy44.start(Unknown Source)
              at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
              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:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
              at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
              at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
              at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
              at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start
      (SubDeployerInterceptorSupport.java:188)
              at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
              at $Proxy5.deploy(Unknown Source)
              at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
              at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
              at org.jboss.Main.boot(Main.java:200)
              at org.jboss.Main$1.run(Main.java:508)
              at java.lang.Thread.run(Thread.java:619)
      08:20:58,444 ERROR [MainDeployer] Could not start deployment: file:/C:/Program Files/jboss-4.2.2.GA/server/default/tmp/deploy/tmp1786721922624674048GestioneEdiliziaPrivata_2.0-ear.ear-contents/GestioneEdiliziaPrivata_2.0.war
      org.jboss.deployment.DeploymentException: URL file:/C:/Program Files/jboss-4.2.2.GA/server/default/tmp/deploy/tmp1786721922624674048GestioneEdiliziaPrivata_2.0-ear.ear-contents/GestioneEdiliziaPrivata_2.0-exp.war/ deployment failed
              at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:379)
              at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
              at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
              at org.jboss.web.WebModule.startModule(WebModule.java:83)
              at org.jboss.web.WebModule.startService(WebModule.java:61)
              at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
              at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
              at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
              at $Proxy0.start(Unknown Source)
              at org.jboss.system.ServiceController.start(ServiceController.java:417)
              at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
              at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
              at $Proxy44.start(Unknown Source)
              at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
      





      This is my code:


      File: Index.java



      @Local
      public interface Indexer {
         Date getLastIndexingTime();
         void index();
         void stop();
      }
      



      File: IndexerBean.java



      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import org.hibernate.search.FullTextSession;
      
      @Scope(ScopeType.APPLICATION)
      @Startup
      @Stateful
      @Name("indexer")
      public class IndexerBean implements Indexer {
         private Date lastIndexingTime;
      
         @PersistenceContext
         EntityManager em;
      
         @Create
         public void index() {
           indexObject(Dossier.class);
           indexObject(Esibito.class);
           lastIndexingTime = new Date();
         }
         
         public Date getLastIndexingTime() {
              return lastIndexingTime;
         }
         
         @SuppressWarnings("unchecked")
         private void indexObject(Class c) {
              FullTextSession fullTextSession = (FullTextSession) em.getDelegate();
              List records = fullTextSession.createQuery("from " + c.getSimpleName()).list();
              for (Object object: records) {
                  fullTextSession.index(object);
              }
              fullTextSession.clear();
         }
      
         @Remove
         @Destroy
         public void stop() {
         }
      }
      



      Configuration files:


      File: component.xml



         <core:init debug="true" jndi-pattern="@jndiPattern@"/>
      



      File: components.proprieties




      jndiPattern=GestioneEdiliziaPrivata_2.0-ear/\#{ejbName}/local
      embeddedEjb=false
      



      What I've already tried:


      @Startup(depends="org.jboss.seam.core.applicationContext")
      



      using @Observer instead of @Create




      @Observer("org.jboss.seam.postInitialization")
      
      or
      
      @Observer("org.jboss.seam.core.applicationContext")
      



      ... and pushed from the black despair :-) I've upgrade my hibernate jar file to version 3.1.1.GA, and modified my code according to what explained in chapter 1.4:
      Hibernate Search


      Thank you in advance to everyone that can give me some suggestions or help!

        • 1. Re: Seam 2.2.0.GA: executing task at startup time
          gaborj

          hi,


          most probably it is your persistency settings, you should test if the em is injected properly before using that...


          do you use Seam 2.2.0.GA with hibernate core 3.1.1.GA? In this seam package 3.3.1.GA of hibernate is included, did you replace this to older version? Did you also changed to JBoss 5.1?


          PS: I would use some asynchronous scheduled starting of such batch in separate thread not blocking other startup tasks...

          • 2. Re: Seam 2.2.0.GA: executing task at startup time
            fausto72

            Hi Gabor,


            thank you for your reply and yours suggestions.


            You're right, could be something about jars' versions mismatch, I haven't changed the hibernate core, I've used the version delivered with JBoss 4.2.2 (in server/default/lib directory).
            As it is plan to upgrade to JBoss 5.1 I will try to change to this AS version, and I will try to put this task in a separete thread (in this way the AS starup will surely be faster).



            • 3. Re: Seam 2.2.0.GA: executing task at startup time
              fausto72

              The problem has been solved as follow (thanks to Gabor's suggestions):



              • Upgrade to JBoss AS 5.1 (jdk 1.6 compiled version);

              • Use of hibernate-search-3.1.1.GA jar files (all the necessary libraries are included in the zip distribution archive; lucene-core-2.4.1.jar);



              File: Indexer.java


              @Local
              public interface Indexer {
                   @Asynchronous
                   void index();
              }
              



              File: IndexerBean.java



              @Stateless
              @Name("indexer")
              public class IndexerBean implements Indexer {
                 @PersistenceContext
                 EntityManager em;
              
                 @Observer("org.jboss.seam.postInitialization")
                 public void index() {
                        indexObject(Dossier.class);
                        indexObject(Esibito.class);
                 }
                 
                 @SuppressWarnings("unchecked")
                 private void indexObject(Class c) {
                              if(null == em) {
                                  System.out.println("[indexObject]: EntityManager non disponibile (null).");
                                  return;
                              }
                        FullTextSession fullTextSession = (FullTextSession) em.getDelegate();
                        List records = fullTextSession.createQuery("from " + c.getSimpleName()).list();
                        for (Object object: records) {
                            fullTextSession.index(object);
                        }
                        fullTextSession.clear();
                 }
              }
              



              File: persistence.xml



              <properties>
                       <property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/>
                       <property name="hibernate.search.default.indexBase" value="C:\Temp\GestioneEdiliziaPrivataIndexes"/>
                       <property name="hibernate.ejb.event.post-insert" value="org.hibernate.search.event.FullTextIndexEventListener"/>
                       <property name="hibernate.ejb.event.post-update" value="org.hibernate.search.event.FullTextIndexEventListener"/>
                       <property name="hibernate.ejb.event.post-delete" value="org.hibernate.search.event.FullTextIndexEventListener"/>
              </properties>