6 Replies Latest reply on Oct 2, 2008 7:16 PM by Graeme Harnish

    Schedular MBean & Injection

    Graeme Harnish Newbie

      Hello. When my Scheduler mBean starts up it can't find my injected EJB's (it works fine from the jmx-console, when I click the method button) Any ideas?

      Code snippet:

      <!-- ==================================================================== --> <!-- Scheduler Service -->
       <!-- ==================================================================== -->
       <!--
       | This example shows how to use a target MBean
       -->
       <mbean code="org.jboss.mx.timer.JBossTimer"
       name="jboss:service=Timer">
       </mbean>
      
       <mbean code="com.craneae.t1.schedular.ejb.jmx.TeamCenterADSchedulerBean"
       name=":name=TeamCenterADSchedulerBean">
       </mbean>
       <mbean code="org.jboss.varia.scheduler.Scheduler"
       name=":service=Scheduler,name=TeamCenterADSchedulerBean">
       <attribute name="StartAtStartup">true</attribute>
       <attribute name="SchedulableMBean">:name=TeamCenterADSchedulerBean</attribute>
       <attribute name="SchedulableMBeanMethod">expireAccounts()</attribute>
       <attribute name="InitialStartDate">NOW</attribute>
       <attribute name="SchedulePeriod">10000</attribute>
       <attribute name="InitialRepetitions">1</attribute>
       <attribute name="FixedRate">true</attribute>
       </mbean>
      
      
       // Inject the UserDAO bean
       @EJB (beanName="UserDAOBean") private UserDAOBeanLocal userDAOBean;
      
       // Update email addresses once per night
       @SuppressWarnings("unchecked")
       public void expireAccounts()
       {
       List<User> resultList = userDAOBean.getActiveUsers();
      


      The userDAOBean is always null on startup.

      Thanks!

        • 1. Re: Schedular MBean & Injection
          Peter Johnson Master

          Services are started before EJBs, therefore the EJB is probably not ready at the time the code is run. You need to add a depends tag that references the BMean generated for the EJB. Something like this:

          <mbean ...>
          <depends>jboss.j2ee:ear=xxx.ear,jar=xxx.jar,name=MyEjb,service=EJB3</depends>
          </mbean>


          You can use the jmx console to look up the name for your ejb's mbean.

          • 2. Re: Schedular MBean & Injection
            Graeme Harnish Newbie

             

            "PeterJ" wrote:
            Services are started before EJBs, therefore the EJB is probably not ready at the time the code is run. You need to add a depends tag that references the BMean generated for the EJB. Something like this:

            <mbean ...>
            <depends>jboss.j2ee:ear=xxx.ear,jar=xxx.jar,name=MyEjb,service=EJB3</depends>
            </mbean>


            You can use the jmx console to look up the name for your ejb's mbean.


            Hi Peter. Thanks for the response. The strange thing is the application server can be completely started and it still fails (for example setting the SchedulePeriod to 10000 will launch the method after it's completely started) It still works from the console however. It's almost as it's being launched from outside of the servers context or something?

            • 3. Re: Schedular MBean & Injection
              Peter Johnson Master

              If the EJB is already deployed when the service runs, then it sounds like this could be a bug. You should probably file a JIRA.

              • 4. Re: Schedular MBean & Injection
                Graeme Harnish Newbie

                 

                "PeterJ" wrote:
                If the EJB is already deployed when the service runs, then it sounds like this could be a bug. You should probably file a JIRA.


                Thanks. I did open up a support case with Redhat. Funny enough under 4.2.3 I get this error when starting:

                09:35:03,980 ERROR [STDERR] java.lang.NullPointerException
                09:35:03,980 ERROR [STDERR] at org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:49)
                09:35:03,980 ERROR [STDERR] at org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:87)
                09:35:03,980 ERROR [STDERR] at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:112)
                09:35:03,980 ERROR [STDERR] at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:107)
                09:35:03,980 ERROR [STDERR] at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:65)
                09:35:03,980 ERROR [STDERR] at org.jboss.ejb3.service.ServiceContainer.injectDependencies(ServiceContainer.java:446)
                09:35:03,980 ERROR [STDERR] at org.jboss.ejb3.service.ServiceContainer.start(ServiceContainer.java:172)
                09:35:03,980 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                09:35:03,980 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                09:35:03,980 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                09:35:03,980 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                09:35:03,980 ERROR [STDERR] at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:103)
                09:35:03,980 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                09:35:03,980 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                09:35:03,980 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                09:35:03,980 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                09:35:03,980 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                09:35:03,980 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                09:35:03,980 ERROR [STDERR] at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                09:35:03,980 ERROR [STDERR] at $Proxy0.start(Unknown Source)
                09:35:03,980 ERROR [STDERR] at org.jboss.system.ServiceController.start(ServiceController.java:417)
                09:35:03,980 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                09:35:03,980 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                09:35:03,980 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                09:35:03,980 ERROR [STDERR] at $Proxy99.start(Unknown Source)
                09:35:03,980 ERROR [STDERR] at org.jboss.ejb3.JmxKernelAbstraction.install(JmxKernelAbstraction.java:120)
                09:35:03,980 ERROR [STDERR] at org.jboss.ejb3.Ejb3Deployment.registerEJBContainer(Ejb3Deployment.java:301)
                09:35:03,980 ERROR [STDERR] at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:362)
                09:35:03,980 ERROR [STDERR] at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:91)
                09:35:03,980 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                09:35:03,980 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                09:35:03,980 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                09:35:03,980 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                09:35:03,980 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                09:35:03,980 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                09:35:03,980 ERROR [STDERR] at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                09:35:03,980 ERROR [STDERR] at $Proxy0.start(Unknown Source)
                09:35:03,980 ERROR [STDERR] at org.jboss.system.ServiceController.start(ServiceController.java:417)
                09:35:03,980 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                09:35:03,980 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                09:35:03,980 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                09:35:03,980 ERROR [STDERR] at $Proxy33.start(Unknown Source)
                09:35:03,980 ERROR [STDERR] at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:512)
                09:35:03,980 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                09:35:03,980 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                09:35:03,980 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                09:35:03,980 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
                09:35:03,980 ERROR [STDERR] at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
                09:35:03,980 ERROR [STDERR] at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
                09:35:03,980 ERROR [STDERR] at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
                09:35:03,980 ERROR [STDERR] at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                09:35:03,980 ERROR [STDERR] at $Proxy34.start(Unknown Source)
                09:35:03,980 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
                09:35:03,980 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
                09:35:03,980 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
                09:35:03,980 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
                09:35:03,980 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
                09:35:03,980 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                09:35:03,980 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                09:35:03,980 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                09:35:03,980 ERROR [STDERR] at $Proxy9.deploy(Unknown Source)
                09:35:03,980 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
                09:35:03,980 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:610)
                09:35:03,980 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
                09:35:03,980 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
                09:35:03,980 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
                


                Is there a way to wait for JNDI or something?

                Thanks.

                • 5. Re: Schedular MBean & Injection
                  Peter Johnson Master

                  To wait on JNDI add a depends on jboss:service=Naming

                  • 6. Re: Schedular MBean & Injection
                    Graeme Harnish Newbie

                    Ok, I found out the problem. I was declaring my mBean as an EJB 3.0 bean, but still implementing a 2.0 class. Therefore, it couldn't get an EJB 3.0 context. I guess I went a little cut and paste happy with Internet examples. Here's what works in case anyone else has this issue:

                    schedular-service.xml

                     <mbean code="org.jboss.varia.scheduler.Scheduler"
                     name=":service=Scheduler,scheduable=TeamCenterADSchedulerMBean">
                     <attribute name="StartAtStartup">true</attribute>
                     <attribute name="SchedulableMBean">name:service=TeamCenterADSchedulerMBean</attribute>
                     <attribute name="SchedulableMBeanMethod">expireAccounts()</attribute>
                     <attribute name="InitialStartDate">NOW</attribute>
                     <attribute name="SchedulePeriod">20000</attribute>
                     <attribute name="InitialRepetitions">1</attribute>
                     <attribute name="FixedRate">true</attribute>
                     <depends>jboss.j2ee:ear=schedular.ear,jar=schedular.jar,name=TeamCenterADSchedulerBean,service=EJB3</depends>
                     </mbean>
                    


                    code:
                    
                    @Service (objectName="name:service=TeamCenterADSchedulerMBean")
                    @Management(TeamCenterADScheduler.class)
                    public class TeamCenterADSchedulerMBean implements TeamCenterADScheduler
                    {
                    ...
                    }
                    public interface TeamCenterADScheduler
                    {
                    
                     public void updateEmail() ;
                     public void expireAccounts();
                    }
                    


                    It's that easy =) Thanks Peter & Chris from JBoss support on this one.