JNDI lookup for EJBs between parallel app deployment
arun168403 Sep 13, 2013 6:01 AMI have the application structure as follows:
deployment
|-gem.ear
| | ------ gem-ejb-ezSetup.jar
| |------- EzSetUpEJB
|
|-initService.sar
| -------- EzSetupInitService
My agenda is to invoke a method to defined in EzSetupEJB.onDeployment() from EzSetupInitService MBean as follows:
InitialContext ic = new InitialContext(); final String createMethod = "create"; final String meth = "onDeployment"; String jndi = "java:app/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup"; Class[] emptyArgs = new Class[] {}; EJBMetaData metaData = null; EJBObject ejb = null; EJBHome home = null; Object obj = null; Method m = null; Class c = null; // For a session bean, call "create" to get an instance // then call the named method on the instance. obj = ic.lookup(jndi); home = (EJBHome)PortableRemoteObject.narrow(obj, EJBHome.class); metaData = home.getEJBMetaData(); c = metaData.getHomeInterfaceClass(); m = c.getMethod(createMethod, emptyArgs); obj = m.invoke(home, emptyArgs); ejb =(EJBObject)PortableRemoteObject.narrow(obj, EJBObject.class); c = metaData.getRemoteInterfaceClass(); m = c.getMethod(meth, emptyArgs); m.invoke(ejb, emptyArgs);
I made a dependency between the initiservice.sar and gem.ear using the MANIFEST.MF of initService.sar as below:
Manifest-Version: 1.0 Dependencies: deployment.gem.ear
When I deploy the application, I see the EzSetupEJB is already bounded at the tine EzSetupIniService is trying to lookup(but gem.ear is not fully deployed as few more ejb jar deployment is still in progess).
I tried to use all the JNDI bindings as below that is logged in server.log
07:01:32,515 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named EzSetup in deployment unit subdeployment "ejb-jar-ezsetup.jar" of deployment "gem.ear" are as follows: java:global/gem/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetupLocalHome java:app/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetupLocalHome java:module/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetupLocalHome java:global/gem/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetupLocal java:app/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetupLocal java:module/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetupLocal java:global/gem/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup java:app/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup java:module/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup java:jboss/exported/gem/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup java:global/gem/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetupHome java:app/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetupHome java:module/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetupHome java:jboss/exported/gem/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetupHome
But I'm getting exception on the console when I try to lookup:
[com.alcatel.trace] (MSC service thread 1-4) Initialization failure (onDeployment).: javax.naming.NamingException: javax.naming.NameNotFoundException: gem/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup -- service jboss.naming.context.java.global.gem.ejb-jar-ezsetup."EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup" [Root exception is java.lang.RuntimeException: javax.naming.NameNotFoundException: gem/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup -- service jboss.naming.context.java.global.gem.ejb-jar-ezsetup."EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup"] at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:135) at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:74) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178) at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:113) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214) at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_25] at com.alcatel.gem.jbservice.init.EzSetupInitService.invokeBeans(EzSetupInitService.java:274) [initService.sar:] at com.alcatel.gem.jbservice.init.EzSetupInitService.callOneTimeDeploymentList(EzSetupInitService.java:186) [initService.sar:] at com.alcatel.gem.jbservice.init.EzSetupInitService.startService(EzSetupInitService.java:102) [initService.sar:] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_25] at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_25] at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptorFactory$ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptorFactory.java:130) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:95) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:333) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.ejb3.tx.SingletonLifecycleCMTTxInterceptor.processInvocation(SingletonLifecycleCMTTxInterceptor.java:56) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final] at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:85) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:116) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.ejb3.component.singleton.SingletonComponent.start(SingletonComponent.java:130) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final] at org.jboss.as.ee.component.ComponentStartService.start(ComponentStartService.java:44) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final] at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25] at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25] Caused by: java.lang.RuntimeException: javax.naming.NameNotFoundException: gem/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup -- service jboss.naming.context.java.global.gem.ejb-jar-ezsetup."EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup" at org.jboss.as.naming.subsystem.NamingBindingAdd$2.getReference(NamingBindingAdd.java:204) at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:133) ... 41 more Caused by: javax.naming.NameNotFoundException: gem/ejb-jar-ezsetup/EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup -- service jboss.naming.context.java.global.gem.ejb-jar-ezsetup."EzSetup!com.alcatel.gem.ezsetup.interfaces.EzSetup" at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178) at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:123) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214) at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_25] at org.jboss.as.naming.subsystem.NamingBindingAdd$2.getReference(NamingBindingAdd.java:201) ... 42 more
Is there any way to tell initService.sar to wait till gem.ear is completly deployed.
Also, what is the JNDI name to be used to lookup the EJB in this case?