8 Replies Latest reply on Dec 2, 2005 9:49 AM by Gabriel Bermudez

    Calling an EJB method each day

    Gabriel Bermudez Newbie

      Hi, Ive got a question and maybe some can help

      I need to call a EJB Buisness method each day, the method updates data on a data base. The method is inside a Session Bean. Do I have to program a client that calls the method each day or can I configure a timer inside the application server that calls the method. What kind of method has to be, remote, local or both.
      Thanks for the help.

        • 1. Re: Calling an EJB method each day
          Darran Lofthouse Master

          Which JBoss version are you using?

          • 2. Re: Calling an EJB method each day
            Gabriel Bermudez Newbie

            sorry :)
            Im using 4.0.2 wiht EJB 2.0 spec

            • 3. Re: Calling an EJB method each day
              Gabriel Bermudez Newbie

              exactly JBoss 4.0.2 RC1

              • 4. Re: Calling an EJB method each day
                Dirk Koehler Newbie

                You can use the Timer Service provided by JBoss:

                1) Just implement the org.jboss.varia.scheduler.Schedulable Interface
                2) and configure the MBean
                3) and deploy the SAR.

                that's it...

                more infos:

                http://docs.jboss.org/jbossas/jboss4guide/r1/html/ch10.html#ch10.sched.sect

                • 5. Re: Calling an EJB method each day
                  Gabriel Bermudez Newbie

                  Can you give me some example code, or better yet a tutorial, Ive been trying to change the
                  deploy/scheduler-service.xml


                  <!-- ==================================================================== -->
                  <!-- Scheduler Service -->
                  <!-- ==================================================================== -->

                  <!--
                  | This example shows how to use a pluggable Schedulable impl
                  -->

                  false
                  com.navyec.jbalancedsc.model.util.JBSCUtil


                  NOW
                  10000
                  -1



                  and gives the following error:
                  13:29:20,063 INFO [Scheduler] Failed to find: com.navyec.jbalancedsc.model.util.JBSCUtil
                  java.lang.ClassNotFoundException: No ClassLoaders found for: com.navyec.jbalancedsc.model.util.JBSCUtil
                  at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:198)
                  at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:475)
                  at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:377)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
                  at org.jboss.varia.scheduler.Scheduler.setSchedulableClass(Scheduler.java:505)
                  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.AttributeDispatcher.invoke(AttributeDispatcher.java:118)
                  at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                  at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
                  at org.jboss.mx.interceptor.ModelMBeanAttributeInterceptor.invoke(ModelMBeanAttributeInterceptor.java:89)
                  at org.jboss.mx.interceptor.PersistenceInterceptor.invoke(PersistenceInterceptor.java:61)
                  at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
                  at org.jboss.mx.server.AbstractMBeanInvoker.setAttribute(AbstractMBeanInvoker.java:446)
                  at org.jboss.mx.server.MBeanServerImpl.setAttribute(MBeanServerImpl.java:593)
                  at org.jboss.system.ServiceConfigurator.setAttribute(ServiceConfigurator.java:569)
                  at org.jboss.system.ServiceConfigurator.configure(ServiceConfigurator.java:275)
                  at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigurator.java:164)
                  at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java:118)
                  at org.jboss.system.ServiceController.install(ServiceController.java:200)
                  at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
                  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:144)
                  at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                  at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
                  at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
                  at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
                  at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
                  at $Proxy4.install(Unknown Source)
                  at org.jboss.deployment.SARDeployer.create(SARDeployer.java:220)
                  at org.jboss.deployment.MainDeployer.create(MainDeployer.java:918)
                  at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:774)
                  at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:738)
                  at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
                  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:144)
                  at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                  at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:122)
                  at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
                  at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:131)
                  at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
                  at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
                  at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
                  at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
                  at $Proxy8.deploy(Unknown Source)
                  at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:325)
                  at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:501)
                  at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:204)
                  at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:277)
                  at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:272)
                  at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:222)
                  at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
                  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:144)
                  at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                  at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
                  at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
                  at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
                  at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:911)
                  at $Proxy0.start(Unknown Source)
                  at org.jboss.system.ServiceController.start(ServiceController.java:416)
                  at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                  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:144)
                  at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                  at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
                  at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
                  at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
                  at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
                  at $Proxy4.start(Unknown Source)
                  at org.jboss.deployment.SARDeployer.start(SARDeployer.java:273)
                  at org.jboss.deployment.MainDeployer.start(MainDeployer.java:964)
                  at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:775)
                  at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:738)
                  at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:722)
                  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:144)
                  at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                  at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:122)
                  at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
                  at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:131)
                  at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
                  at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
                  at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
                  at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
                  at $Proxy5.deploy(Unknown Source)
                  at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:413)
                  at org.jboss.system.server.ServerImpl.start(ServerImpl.java:310)
                  at org.jboss.Main.boot(Main.java:195)
                  at org.jboss.Main$1.run(Main.java:463)
                  at java.lang.Thread.run(Thread.java:595)

                  I also uncomment the deploy/scheduler-manager-service.xml


                  true



                  BTW what exactly is a SAR and how I can deploy it, thanks

                  • 6. Re: Calling an EJB method each day
                    Gabriel Bermudez Newbie

                    I had tried to create and deploy a .sar, but I've got a question.
                    Those the class that implemets the Schedulable interface must me an EJB? or it can be a simple Java class

                    • 7. Re: Calling an EJB method each day
                      arvind p Newbie

                      Hi,

                      In our application we haven't use the ejb timer. We used the Jdk Timer class and it's working fine.

                      We called the Timer using the startup servlet, which will the call the timer for predined time interval.

                      From the timer class we used to call a Stateless session bean.

                      Arvind




                      • 8. Re: Calling an EJB method each day
                        Gabriel Bermudez Newbie

                        Ok, this is what I understand.
                        A sar is a "service archive" and like ears and wars, its composed of a descriptor and your classes. The descriptor is a "jboss-service.xml" file. I'm using a simple Java class that implementes the Schedulable interface, this interface defines only one method called perfom().
                        From this method I try to call a Stateless EJB but it gives a Naming Exception. One thing I'm deploying my sar and my ear separatly in side the same server, does the sar must be inside the ear as a module or do I need another descriptor that defines the EJBs that the Schedulabe implementation must call?

                        Another question, how do I difine an MBean using JBoss-IDE?
                        I've seen the @jmx tag, but I dont know how to use it

                        Thanks