4 Replies Latest reply on Feb 15, 2007 6:40 PM by Ken Kachnowich

    Can I use @Ejb in an MBean?

    Ken Kachnowich Newbie

      Hi,

      I would like to have access to a Stateless session bean inside an MBean service I will be working on. Can I use the @Ejb annotation to do this?

      For example:

      @Service (objectName="trail:service=calculator")
      @Management(Calculator.class)
      public class CalculatorMBean implements Calculator {

      @Ejb TheBean myBean;

      Thanks,

      Ken

        • 1. Re: Can I use @Ejb in an MBean?
          Andrew Rubinger Master

          The "@EJB" (javax.ejb.EJB) annotation, yep.

          S,
          ALR

          • 2. Re: Can I use @Ejb in an MBean?
            Ken Kachnowich Newbie

            I must be doing something wrong then, the ejb is always null in my MBean.
            Here is my stuff:

            EJB:

            @Local
            public interface WsClientEJB {
            public String getName();
            }
            @Stateless
            public class WsClientEJBBean implements WsClientEJB {

            public String getName() {
            return "Ken";
            }
            }


            MBean:

            public class ContentClient extends ServiceMBeanSupport implements
            ContentClientMBean {

            @EJB
            private WsClientEJB myEjb;

            ...

            public String runWsGetDoc(String id) {
            String rtn = "";

            if (null == myEjb){
            rtn = "its null";
            }
            else {
            rtn = myEjb.getName();
            }

            return rtn;
            }


            I have tried this with and without an ejb-jar.xml and setting @LocalBinding and mappedName= in the @EJB

            I am using 4.0.5.GA

            There is a bunch of logging for the MBean and ejb bean, which I have included below:


            2007-02-14 15:41:59,833 DEBUG [org.jboss.deployment.MainDeployer] Starting deployment of package: file:/usr/local/jboss405/server/default/deploy/ContentClient.sar
            2007-02-14 15:41:59,833 DEBUG [org.jboss.deployment.MainDeployer] Starting deployment (init step) of package at: file:/usr/local/jboss405/server/default/deploy/ContentClient.sar
            2007-02-14 15:41:59,833 DEBUG [org.jboss.deployment.MainDeployer] Copying file:/usr/local/jboss405/server/default/deploy/ContentClient.sar -> /usr/local/jboss405/server/default/tmp/deploy/tmp65014ContentClient.sar
            2007-02-14 15:41:59,833 DEBUG [org.jboss.deployment.MainDeployer] using deployer org.jboss.deployment.SARDeployer@3af42ad0
            2007-02-14 15:41:59,847 DEBUG [org.jboss.deployment.SARDeployer] about to copy 0 local directories
            2007-02-14 15:41:59,847 DEBUG [org.jboss.deployment.SARDeployer] looking for nested deployments in : file:/usr/local/jboss405/server/default/deploy/ContentClient.sar
            2007-02-14 15:41:59,848 DEBUG [org.jboss.deployment.DeploymentInfo] createLoaderRepository from config: LoaderRepositoryConfig(repositoryName: JMImplementation:service=LoaderRepository,name=Default, repositoryClassName: null, configParserClassName: null, repositoryConfig: null)
            2007-02-14 15:41:59,848 DEBUG [org.jboss.mx.loading.RepositoryClassLoader] setRepository, repository=org.jboss.mx.loading.UnifiedLoaderRepository3@6627e353, cl=org.jboss.mx.loading.UnifiedClassLoader3@3ef07355{ url=file:/usr/local/jboss405/server/default/tmp/deploy/tmp65014ContentClient.sar ,addedOrder=0}
            2007-02-14 15:41:59,848 DEBUG [org.jboss.mx.loading.RepositoryClassLoader] setRepository, repository=org.jboss.mx.loading.UnifiedLoaderRepository3@6627e353, cl=org.jboss.mx.loading.UnifiedClassLoader3@3ef07355{ url=file:/usr/local/jboss405/server/default/tmp/deploy/tmp65014ContentClient.sar ,addedOrder=0}
            2007-02-14 15:41:59,848 DEBUG [org.jboss.mx.loading.UnifiedLoaderRepository3] Adding org.jboss.mx.loading.UnifiedClassLoader3@3ef07355{ url=file:/usr/local/jboss405/server/default/tmp/deploy/tmp65014ContentClient.sar ,addedOrder=0}
            2007-02-14 15:41:59,849 DEBUG [org.jboss.deployment.MainDeployer] found 0 subpackages of file:/usr/local/jboss405/server/default/deploy/ContentClient.sar
            2007-02-14 15:41:59,850 DEBUG [org.jboss.deployment.MainDeployer] Watching new file: file:/usr/local/jboss405/server/default/deploy/ContentClient.sar
            2007-02-14 15:41:59,850 DEBUG [org.jboss.deployment.MainDeployer] create step for deployment file:/usr/local/jboss405/server/default/deploy/ContentClient.sar
            2007-02-14 15:41:59,850 DEBUG [org.jboss.deployment.SARDeployer] Deploying SAR, create step: url file:/usr/local/jboss405/server/default/deploy/ContentClient.sar
            2007-02-14 15:41:59,850 DEBUG [org.jboss.deployment.SARDeployer] Registering service UCL=jmx.loading:UCL=3ef07355
            2007-02-14 15:41:59,851 DEBUG [org.jboss.system.ServiceCreator] About to create bean: ken:service=ContentClient with code: wsclient.ContentClient
            2007-02-14 15:41:59,856 DEBUG [org.jboss.system.ServiceCreator] Created bean: ken:service=ContentClient
            2007-02-14 15:41:59,856 DEBUG [org.jboss.system.ServiceController] Creating service ken:service=ContentClient
            2007-02-14 15:41:59,857 DEBUG [wsclient.ContentClient] Creating ken:service=ContentClient
            2007-02-14 15:41:59,857 DEBUG [wsclient.ContentClient] Created ken:service=ContentClient
            2007-02-14 15:41:59,857 DEBUG [org.jboss.system.ServiceController] Creating dependent components for: ken:service=ContentClient dependents are: []
            2007-02-14 15:41:59,865 DEBUG [org.jboss.deployment.MainDeployer] Done with create step of deploying ContentClient.sar
            2007-02-14 15:41:59,865 DEBUG [org.jboss.deployment.MainDeployer] Begin deployment start file:/usr/local/jboss405/server/default/deploy/ContentClient.sar
            2007-02-14 15:41:59,865 DEBUG [org.jboss.deployment.SARDeployer] Deploying SAR, start step: url file:/usr/local/jboss405/server/default/deploy/ContentClient.sar
            2007-02-14 15:41:59,865 DEBUG [org.jboss.system.ServiceController] starting service ken:service=ContentClient
            2007-02-14 15:41:59,865 DEBUG [wsclient.ContentClient] Starting ken:service=ContentClient
            2007-02-14 15:41:59,865 DEBUG [wsclient.ContentClient] Started ken:service=ContentClient
            2007-02-14 15:41:59,865 DEBUG [org.jboss.system.ServiceController] Starting dependent components for: ken:service=ContentClient dependent components: []
            2007-02-14 15:41:59,865 DEBUG [org.jboss.deployment.MainDeployer] End deployment start on package: ContentClient.sar
            2007-02-14 15:41:59,865 DEBUG [org.jboss.deployment.MainDeployer] Deployed package: file:/usr/local/jboss405/server/default/deploy/ContentClient.sar
            2007-02-14 15:41:59,865 DEBUG [org.jboss.deployment.scanner.URLDeploymentScanner] Watch URL for: file:/usr/local/jboss405/server/default/deploy/ContentClient.sar -> file:/usr/local/jboss405/server/default/deploy/ContentClient.sar

            2007-02-14 15:42:15,846 DEBUG [org.jboss.deployment.MainDeployer] Starting deployment of package: file:/usr/local/jboss405/server/default/deploy/beans.jar
            2007-02-14 15:42:15,846 DEBUG [org.jboss.deployment.MainDeployer] Starting deployment (init step) of package at: file:/usr/local/jboss405/server/default/deploy/beans.jar
            2007-02-14 15:42:15,846 DEBUG [org.jboss.deployment.MainDeployer] Copying file:/usr/local/jboss405/server/default/deploy/beans.jar -> /usr/local/jboss405/server/default/tmp/deploy/tmp65098beans.jar
            2007-02-14 15:42:15,878 DEBUG [org.jboss.deployment.MainDeployer] using deployer MBeanProxyExt[jboss.ejb3:service=EJB3Deployer] 2007-02-14 15:42:15,882 DEBUG [org.jboss.ejb3.EJB3Deployer] looking for nested deployments in : file:/usr/local/jboss405/server/default/deploy/beans.jar
            2007-02-14 15:42:15,882 DEBUG [org.jboss.deployment.DeploymentInfo] createLoaderRepository from config: LoaderRepositoryConfig(repositoryName: JMImplementation: service=LoaderRepository,name=Default, repositoryClassName: null, configParserClassName: null, repositoryConfig: null)
            2007-02-14 15:42:15,882 DEBUG [org.jboss.mx.loading.RepositoryClassLoader] setRepository, repository=org.jboss.mx.loading.UnifiedLoaderRepository3@6627e353, cl=org.jboss.mx.loading.UnifiedClassLoader3@58c3d9ac{ url=file:/usr/local/jboss405/server/default/tmp/deploy/tmp65098beans.jar ,addedOrder=0}
            2007-02-14 15:42:15,882 DEBUG [org.jboss.mx.loading.ClassLoaderUtils] Multiple class loaders found for pkg: wsclient
            2007-02-14 15:42:15,882 DEBUG [org.jboss.deployment.MainDeployer] found 0 subpackages of file:/usr/local/jboss405/server/default/deploy/beans.jar
            2007-02-14 15:42:15,882 DEBUG [org.jboss.deployment.MainDeployer] Watching new file: file:/usr/local/jboss405/server/default/deploy/beans.jar
            2007-02-14 15:42:15,882 DEBUG [org.jboss.deployment.MainDeployer] create step for deployment file:/usr/local/jboss405/server/default/deploy/beans.jar
            2007-02-14 15:42:15,882 DEBUG [org.jboss.ws.integration.jboss.DeployerInterceptorEJB3] create: file:/usr/local/jboss405/server/default/deploy/beans.jar
            2007-02-14 15:42:15,882 DEBUG [org.jboss.ejb3.EJB3Deployer] create, beans.jar
            2007-02-14 15:42:15,922 DEBUG [org.jboss.ejb3.EJB3Deployer] Deploying: file:/usr/local/jboss405/server/default/deploy/beans.jar
            2007-02-14 15:42:15,922 DEBUG [org.jboss.system.ServiceController] Creating service jboss.j2ee:service=EJB3,module=beans.jar
            2007-02-14 15:42:15,922 DEBUG [org.jboss.ejb3.Ejb3Module] Creating jboss.j2ee:service=EJB3,module=beans.jar
            2007-02-14 15:42:15,926 DEBUG [org.jboss.ejb3.security.JaccHelper] Initialising JACC Context for deployment: beans.jar
            2007-02-14 15:42:16,022 DEBUG [org.jboss.ejb3.Ejb3AnnotationHandler] found EJB3: ejbName=WsClientEJBBean, class=wsclient.WsClientEJBBean, type=STATELESS
            2007-02-14 15:42:16,038 DEBUG [org.jboss.ejb3.ProxyDeployer] no declared remote bindings for : WsClientEJBBean
            2007-02-14 15:42:16,050 INFO [org.jboss.ejb3.Ejb3Deployment] EJB3 deployment time took: 128
            2007-02-14 15:42:16,050 DEBUG [org.jboss.ejb3.Ejb3Module] Created jboss.j2ee:service=EJB3,module=beans.jar
            2007-02-14 15:42:16,050 DEBUG [org.jboss.system.ServiceController] Creating dependent components for: jboss.j2ee:service=EJB3,module=beans.jar dependents are: []
            2007-02-14 15:42:16,054 DEBUG [org.jboss.deployment.MainDeployer] Done with create step of deploying beans.jar
            2007-02-14 15:42:16,054 DEBUG [org.jboss.deployment.MainDeployer] Begin deployment start file:/usr/local/jboss405/server/default/deploy/beans.jar
            2007-02-14 15:42:16,054 DEBUG [org.jboss.ws.integration.jboss.DeployerInterceptorEJB3] start: file:/usr/local/jboss405/server/default/deploy/beans.jar
            2007-02-14 15:42:16,054 DEBUG [org.jboss.ejb3.EJB3Deployer] start application, deploymentInfo: org.jboss.deployment.DeploymentInfo@8ebcb57e { url=file:/usr/local/jboss405/server/default/deploy/beans.jar }
            deployer: MBeanProxyExt[jboss.ejb3:service=EJB3Deployer]
            status: Starting
            state: START_DEPLOYER
            watch: file:/usr/local/jboss405/server/default/deploy/beans.jar
            altDD: null
            lastDeployed: 1171485735882
            lastModified: 1171485735000
            mbeans:
            , short name: beans.jar, parent short name: null
            2007-02-14 15:42:16,054 DEBUG [org.jboss.system.ServiceController] starting service jboss.j2ee:service=EJB3,module=beans.jar
            2007-02-14 15:42:16,054 DEBUG [org.jboss.ejb3.Ejb3Module] Starting jboss.j2ee:service=EJB3,module=beans.jar
            2007-02-14 15:42:16,106 DEBUG [org.jboss.ejb3.EJBContainer] Initialising interceptors for WsClientEJBBean...
            2007-02-14 15:42:16,106 DEBUG [org.jboss.ejb3.EJBContainer] Default interceptors: null
            2007-02-14 15:42:16,110 DEBUG [org.jboss.ejb3.EJBContainer] Class interceptors:[]
            2007-02-14 15:42:16,110 DEBUG [org.jboss.ejb3.EJBContainer] All applicable interceptor classes: []
            2007-02-14 15:42:16,110 DEBUG [org.jboss.ejb3.JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
            2007-02-14 15:42:16,138 INFO [org.jboss.ejb3.JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3 with dependencies:
            2007-02-14 15:42:16,140 DEBUG [org.jboss.system.ServiceController] Creating service jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3
            2007-02-14 15:42:16,141 DEBUG [org.jboss.system.ServiceController] adding depends in ServiceController.register: []
            2007-02-14 15:42:16,141 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Creating jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3
            2007-02-14 15:42:16,141 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Created jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3
            2007-02-14 15:42:16,141 DEBUG [org.jboss.system.ServiceController] Creating dependent components for: jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3 dependents are: []
            2007-02-14 15:42:16,141 DEBUG [org.jboss.system.ServiceController] starting service jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3
            2007-02-14 15:42:16,141 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Starting jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3
            2007-02-14 15:42:16,141 DEBUG [org.jboss.system.ServiceController] adding depends in ServiceController.register: []
            2007-02-14 15:42:16,141 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Creating jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3
            2007-02-14 15:42:16,141 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Created jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3
            2007-02-14 15:42:16,141 DEBUG [org.jboss.system.ServiceController] Creating dependent components for: jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3 dependents are: []
            2007-02-14 15:42:16,141 DEBUG [org.jboss.system.ServiceController] starting service jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3
            2007-02-14 15:42:16,141 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Starting jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3
            2007-02-14 15:42:16,298 DEBUG [org.jboss.ejb3.interceptor.EJB3InterceptorsFactory] Bound interceptors for joinpoint: public java.lang.String wsclient.WsClientEJBBean.getName() - [Lorg.jboss.ejb3.interceptor.InterceptorInfo;@48586403
            2007-02-14 15:42:16,326 DEBUG [org.jboss.ejb3.tx.UserTransactionImpl] new UserTx: org.jboss.ejb3.tx.UserTransactionImpl@32c5f9fe
            2007-02-14 15:42:16,342 DEBUG [org.jboss.ejb3.interceptor.EJB3InterceptorsFactory] Bound interceptors for joinpoint: public java.lang.String wsclient.WsClientEJBBean.getName() - [Lorg.jboss.ejb3.interceptor.InterceptorInfo;@5f47ff11
            2007-02-14 15:42:16,343 DEBUG [org.jboss.ejb3.security.JaccHelper] WsClientEJBBean has no @SecurityDomain - skipping JACC configuration
            2007-02-14 15:42:16,343 INFO [org.jboss.ejb3.EJBContainer] STARTED EJB: wsclient.WsClientEJBBean ejbName: WsClientEJBBean
            2007-02-14 15:42:16,375 DEBUG [org.jboss.ejb.txtimer.EJBTimerServiceImpl] createTimerService: org.jboss.ejb.txtimer.TimerServiceImpl@1bd4f279
            2007-02-14 15:42:16,381 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Started jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3
            2007-02-14 15:42:16,381 DEBUG [org.jboss.system.ServiceController] Starting dependent components for: jboss.j2ee:jar=beans.jar,name=WsClientEJBBean,service=EJB3 dependent components: []
            2007-02-14 15:42:16,381 DEBUG [org.jboss.ejb3.Ejb3Deployment] Bound ejb3 container jboss.j2ee:service=EJB3,jar=beans.jar,name=WsClientEJBBean
            2007-02-14 15:42:16,381 DEBUG [org.jboss.ejb3.security.JaccHelper] JACC Policy Configuration for deployment has been put in service
            2007-02-14 15:42:16,381 DEBUG [org.jboss.ejb3.Ejb3Module] Started jboss.j2ee:service=EJB3,module=beans.jar 2007-02-14 15:42:16,381 DEBUG [org.jboss.system.ServiceController] Starting dependent components for: jboss.j2ee:service=EJB3,module=beans.jar dependent components: []
            2007-02-14 15:42:16,381 INFO [org.jboss.ejb3.EJB3Deployer] Deployed: file:/usr/local/jboss405/server/default/deploy/beans.jar
            2007-02-14 15:42:16,382 DEBUG [org.jboss.deployment.MainDeployer] End deployment start on package: beans.jar
            2007-02-14 15:42:16,382 DEBUG [org.jboss.deployment.MainDeployer] Deployed package: file:/usr/local/jboss405/server/default/deploy/beans.jar
            2007-02-14 15:42:16,382 DEBUG [org.jboss.deployment.scanner.URLDeploymentScanner] Watch URL for: file:/usr/local/jboss405/server/default/deploy/beans.jar -> file:/usr/local/jboss405/server/default/deploy/beans.jar


            • 3. Re: Can I use @Ejb in an MBean?
              Bruce Deen Newbie

              Have you put a dependency on the EJBDeployer within your @Service?

              Try something like
              @Service (objectName="trail:service=calculator")
              @Management(Calculator.class)
              @Depends( "jboss.ejb3:service=EJB3Deployer" )
              public class CalculatorMBean implements Calculator {

              @Ejb TheBean myBean;


              that way the EJBDeployer has a chance to init and start before your service does thereby ensuring that the EJB is around.

              I wonder can you put a depends directly on the EJB itself. That would be the best I would think.

              • 4. Re: Can I use @Ejb in an MBean?
                Ken Kachnowich Newbie

                I tried adding @Depends ("jboss.ejb3:service=EJB3Deployer") to the
                class and jboss.ejb3:service=EJB3Deployer
                to the jboss-service.xml, but my ejb is still null.


                2007-02-15 18:30:45,342 DEBUG [org.jboss.system.ServiceController] Starting dependent components for: jboss.ejb3:service=EJB3Deployer dependent components: [ObjectName: ken:service=ContentClient
                State: CREATED
                I Depend On:
                jboss.ejb3:service=EJB3Deployer
                , ObjectName: jboss.ws:service=DeployerInterceptorEJB3
                State: CREATED
                I Depend On:
                jboss.ejb3:service=EJB3Deployer
                ]
                2007-02-15 18:30:45,342 DEBUG [org.jboss.system.ServiceController] starting service ken:service=ContentClient
                2007-02-15 18:30:45,342 DEBUG [wsclient.ContentClient] Starting ken:service=ContentClient