13 Replies Latest reply on Sep 6, 2007 10:01 AM by wolfc

    How do I programmatically declare a JNDI name dependency?

    wolfc

      How can I install a bean (via the KernelController) which has a dependency on a JNDI entry?

        • 1. Re: How do I programmatically declare a JNDI name dependency
          alesj

          What you can do is this:
          1) just add a plain demand with the JNDI name
          2) add a bean that implements KernelRegistryPlugin and does the JNDI lookup

          The demand dependency will be resolved once your JNDI entry is found through JNDIKernelRegistryPlugin.

          • 2. Re: How do I programmatically declare a JNDI name dependency
            wolfc

            How do I translate a JNDI name to a KernelRegistryEntry?

            • 3. Re: How do I programmatically declare a JNDI name dependency
              alesj

               

              "wolfc" wrote:
              How do I translate a JNDI name to a KernelRegistryEntry?


              ?

              You don't need to translate it.
              All existing KernelRegistryEntry-ies will be asked if they are able to locate the entry with (some-jndi-name) name. And only your JNDIKernelRegistryEntry bean will be able to do that.
              What name you give to your JNDIKernelRegistryEntry, has no meaning.

              Is this what you are asking?

              • 4. Re: How do I programmatically declare a JNDI name dependency
                alesj

                 

                /**
                 * JNDI aware KernelRegistryPlugin.
                 *
                 * @author <a href="mailto:ales.justin@gmail.com">Ales Justin</a>
                 */
                public class JNDIKernelRegistryPlugin implements KernelRegistryPlugin
                {
                 private Hashtable properties;
                 private Context context;
                
                 public void setProperties(Hashtable properties)
                 {
                 this.properties = properties;
                 }
                
                 public void create() throws NamingException
                 {
                 if (properties != null)
                 context = new InitialContext(properties);
                 else
                 context = new InitialContext();
                 }
                
                 public void destroy() throws NamingException
                 {
                 if (context != null)
                 context.close();
                 context = null;
                 }
                
                 public KernelRegistryEntry getEntry(Object name)
                 {
                 try
                 {
                 Object target = context.lookup(name.toString());
                 if (target != null)
                 return new AbstractKernelRegistryEntry(name, target);
                 }
                 catch (NamingException e)
                 {
                 }
                 return null;
                 }
                }
                


                • 5. Re: How do I programmatically declare a JNDI name dependency
                  wolfc

                   

                  // @todo SORT THIS OUT, i.e. dependency that doesn't go through controller

                  That's nasty and putting people on the wrong foot. So in effect I don't return a context, but just a simple name/value.
                  Thanks.

                  • 6. Re: How do I programmatically declare a JNDI name dependency
                    alesj

                     

                    "wolfc" wrote:
                    // @todo SORT THIS OUT, i.e. dependency that doesn't go through controller

                    That's nasty and putting people on the wrong foot. So in effect I don't return a context, but just a simple name/value.
                    Thanks.


                    That's true, but I think this example is not that nasty.
                    Perhaps try to limit the scope in which the lookup is done.

                    We could introduce new JNDI 'personality', which would only have 2 states: NOT_INSTALLED and INSTALLED. But that would mean that all local JNDI registry would have to go over MC, not sure what to do with remote/global lookups.

                    • 7. Re: How do I programmatically declare a JNDI name dependency
                      wolfc

                      Doh!

                      13:12:36,630 ERROR [ProfileServiceBootstrap] Failed to load profile: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):
                      
                      *** CONTEXTS IN ERROR: Name -> Error
                      
                      HASessionState -> java.lang.IllegalArgumentException: Wrong arguments. setHAPartition for target AOPContainerProxy$4@bb0257 expected=[org.jboss.ha.framework.interfaces.HAPartition] actual=[org.jnp.interfaces.NamingContext]
                      
                      JGCacheInvalidationBridge -> java.lang.IllegalArgumentException: Wrong arguments. setHAPartition for target AOPContainerProxy$9@536500 expected=[org.jboss.ha.framework.interfaces.HAPartition] actual=[org.jnp.interfaces.NamingContext]
                      
                      HASingletonDeployer -> java.lang.IllegalArgumentException: Wrong arguments. setHAPartition for target AOPContainerProxy$11@1f84d01 expected=[org.jboss.ha.framework.interfaces.HAPartition] actual=[org.jnp.interfaces.NamingContext]
                      
                      HAJNDI -> java.lang.IllegalArgumentException: Wrong arguments. setHAPartition for target AOPContainerProxy$5@e6f8d7 expected=[org.jboss.ha.framework.interfaces.HAPartition] actual=[org.jnp.interfaces.NamingContext]

                      We could have predicated this one. For the moment I'll prefix "jndi:" to the dependencies.

                      • 8. Re: How do I programmatically declare a JNDI name dependency
                        wolfc

                        The only thing I don't like yet is the fact that after dependencies are satisfied I do another lookup. Thus for a SFSB two instances are created. Either the plugin shouldn't do a lookup (iterate list?) or I should use the target.

                        • 9. Re: How do I programmatically declare a JNDI name dependency
                          alesj

                           

                          "wolfc" wrote:
                          The only thing I don't like yet is the fact that after dependencies are satisfied I do another lookup. Thus for a SFSB two instances are created. Either the plugin shouldn't do a lookup (iterate list?) or I should use the target.


                          Hey, you're the JNDI expert, I just hacked a simple KernelRegistryPlugin for you to see how things are/can be done. :-)

                          But why is another lookup issued?
                          And what's the deal with those exceptions?


                          • 10. Re: How do I programmatically declare a JNDI name dependency
                            wolfc

                             

                            "alesj" wrote:
                            But why is another lookup issued?

                            Because the EJB 3 injection framework itself doesn't know about MC. It only knows the JNDI name. I could change this to kernel.getRegistry().getEntry(name) but that would just mean another lookup. (Note: the (JNDI) registry should never cache, because I might actually want a new SFSB.)
                            "alesj" wrote:
                            And what's the deal with those exceptions?

                            At some point someone is asking for the HAPartition bean which is also a JNDI context, so the context is returned instead of the bean.

                            • 11. Re: How do I programmatically declare a JNDI name dependency
                              alesj

                               

                              "wolfc" wrote:

                              Because the EJB 3 injection framework itself doesn't know about MC. It only knows the JNDI name.

                              I'm not asking about this - I know it shouldn't be MC aware.
                              There are as many lookups as there is tries to resolve dependency on that JNDI component.
                              But that shouldn't be a problem, right?

                              "wolfc" wrote:

                              I could change this to kernel.getRegistry().getEntry(name) but that would just mean another lookup. (Note: the (JNDI) registry should never cache, because I might actually want a new SFSB.)

                              This is wrong.
                              You might call it hacking then. ;-)

                              "wolfc" wrote:

                              At some point someone is asking for the HAPartition bean which is also a JNDI context, so the context is returned instead of the bean.

                              I don't get this one.

                              • 12. Re: How do I programmatically declare a JNDI name dependency
                                wolfc

                                 

                                "alesj" wrote:
                                I'm not asking about this - I know it shouldn't be MC aware.
                                There are as many lookups as there is tries to resolve dependency on that JNDI component.
                                But that shouldn't be a problem, right?

                                Except that it is a problem, because each lookup results in a new SFSB. Which eats up precious resources. If a lot of EJBs depend on this entry than the SFSB cache will be quickly saturated.
                                "alesj" wrote:
                                I don't get this one.

                                getEntry("HAPartion") returns an entry from the JNDI plugin instead of the basic registry. Thus problems (fixed with the "jndi:" prefix).

                                • 13. Re: How do I programmatically declare a JNDI name dependency
                                  wolfc

                                  Why does MC not spit out an exception when KernelRegistryPlugin fails!!!???

                                  Wasted a day just to find out that something is going wrong.

                                  2007-09-06 15:56:04,209 TRACE [org.jboss.ejb3.kernel.JNDIKernelRegistryPlugin:87] get entry for jndi:WSHandlerTest_wsejb_vehicleHome
                                  2007-09-06 15:56:04,212 ERROR [STDERR:151] javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: No ClassLoaders found for: com.sun.ts.tests.common.vehicle.wsejb.WSEJBVehicleHome (no security manager: RMI class loader disabled)]
                                  2007-09-06 15:56:04,214 ERROR [STDERR:151] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:788)
                                  2007-09-06 15:56:04,215 ERROR [STDERR:151] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
                                  2007-09-06 15:56:04,215 ERROR [STDERR:151] at javax.naming.InitialContext.lookup(InitialContext.java:351)
                                  2007-09-06 15:56:04,216 ERROR [STDERR:151] at org.jboss.ejb3.kernel.JNDIKernelRegistryPlugin.getEntry(JNDIKernelRegistryPlugin.java:91)
                                  2007-09-06 15:56:04,217 ERROR [STDERR:151] at org.jboss.kernel.plugins.registry.AbstractKernelRegistry.getEntry(AbstractKernelRegistry.java:85)
                                  2007-09-06 15:56:04,218 ERROR [STDERR:151] at org.jboss.kernel.plugins.dependency.AbstractKernelController.getContext(AbstractKernelController.java:120)
                                  2007-09-06 15:56:04,219 ERROR [STDERR:151] at org.jboss.dependency.plugins.AbstractController.getInstalledContext(AbstractController.java:355)
                                  2007-09-06 15:56:04,220 ERROR [STDERR:151] at org.jboss.beans.metadata.plugins.AbstractDemandMetaData$DemandDependencyItem.resolve(AbstractDemandMetaData.java:165)
                                  2007-09-06 15:56:04,221 ERROR [STDERR:151] at org.jboss.dependency.plugins.AbstractDependencyInfo.resolveDependencies(AbstractDependencyInfo.java:140)
                                  2007-09-06 15:56:04,221 ERROR [STDERR:151] at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:901)
                                  2007-09-06 15:56:04,222 ERROR [STDERR:151] at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:839)
                                  2007-09-06 15:56:04,223 ERROR [STDERR:151] at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:784)
                                  2007-09-06 15:56:04,224 ERROR [STDERR:151] at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:622)
                                  2007-09-06 15:56:04,227 ERROR [STDERR:151] at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:411)
                                  2007-09-06 15:56:04,228 ERROR [STDERR:151] at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:495)
                                  2007-09-06 15:56:04,229 ERROR [STDERR:151] at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:354) 2007-09-06 15:56:04,229 ERROR [STDERR:151] at org.jboss.deployment.services.DeploymentManagerService.deploy_phase2(DeploymentManagerService.java:412)
                                  2007-09-06 15:56:04,230 ERROR [STDERR:151] at org.jboss.deployment.services.DeploymentManagerService.deploy(DeploymentManagerService.java:295)
                                  2007-09-06 15:56:04,231 ERROR [STDERR:151] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  2007-09-06 15:56:04,232 ERROR [STDERR:151] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                  2007-09-06 15:56:04,234 ERROR [STDERR:151] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                  2007-09-06 15:56:04,235 ERROR [STDERR:151] at java.lang.reflect.Method.invoke(Method.java:585)
                                  2007-09-06 15:56:04,237 ERROR [STDERR:151] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
                                  2007-09-06 15:56:04,237 ERROR [STDERR:151] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
                                  2007-09-06 15:56:04,238 ERROR [STDERR:151] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                                  2007-09-06 15:56:04,239 ERROR [STDERR:151] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                                  2007-09-06 15:56:04,240 ERROR [STDERR:151] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
                                  2007-09-06 15:56:04,241 ERROR [STDERR:151] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  2007-09-06 15:56:04,241 ERROR [STDERR:151] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                  2007-09-06 15:56:04,243 ERROR [STDERR:151] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                  2007-09-06 15:56:04,244 ERROR [STDERR:151] at java.lang.reflect.Method.invoke(Method.java:585)
                                  2007-09-06 15:56:04,245 ERROR [STDERR:151] at org.jboss.jmx.connector.invoker.InvokerAdaptorService.invoke(InvokerAdaptorService.java:270)
                                  2007-09-06 15:56:04,245 ERROR [STDERR:151] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  2007-09-06 15:56:04,247 ERROR [STDERR:151] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                  2007-09-06 15:56:04,249 ERROR [STDERR:151] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                  2007-09-06 15:56:04,249 ERROR [STDERR:151] at java.lang.reflect.Method.invoke(Method.java:585)
                                  2007-09-06 15:56:04,251 ERROR [STDERR:151] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
                                  2007-09-06 15:56:04,253 ERROR [STDERR:151] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
                                  2007-09-06 15:56:04,254 ERROR [STDERR:151] at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:138)
                                  2007-09-06 15:56:04,255 ERROR [STDERR:151] at org.jboss.mx.server.Invocation.invoke(Invocation.java:90)
                                  2007-09-06 15:56:04,256 ERROR [STDERR:151] at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:140)
                                  2007-09-06 15:56:04,256 ERROR [STDERR:151] at org.jboss.jmx.connector.invoker.SerializableInterceptor.invoke(SerializableInterceptor.java:74)
                                  2007-09-06 15:56:04,257 ERROR [STDERR:151] at org.jboss.mx.server.Invocation.invoke(Invocation.java:90)
                                  2007-09-06 15:56:04,261 ERROR [STDERR:151] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                                  2007-09-06 15:56:04,263 ERROR [STDERR:151] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
                                  2007-09-06 15:56:04,264 ERROR [STDERR:151] at org.jboss.invocation.jrmp.server.JRMPProxyFactory.invoke(JRMPProxyFactory.java:179)
                                  2007-09-06 15:56:04,265 ERROR [STDERR:151] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  2007-09-06 15:56:04,266 ERROR [STDERR:151] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                  2007-09-06 15:56:04,266 ERROR [STDERR:151] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                  2007-09-06 15:56:04,267 ERROR [STDERR:151] at java.lang.reflect.Method.invoke(Method.java:585)
                                  2007-09-06 15:56:04,269 ERROR [STDERR:151] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
                                  2007-09-06 15:56:04,270 ERROR [STDERR:151] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
                                  2007-09-06 15:56:04,272 ERROR [STDERR:151] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                                  2007-09-06 15:56:04,273 ERROR [STDERR:151] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                                  2007-09-06 15:56:04,274 ERROR [STDERR:151] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
                                  2007-09-06 15:56:04,275 ERROR [STDERR:151] at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:815)
                                  2007-09-06 15:56:04,276 ERROR [STDERR:151] at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:416)
                                  2007-09-06 15:56:04,277 ERROR [STDERR:151] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                  2007-09-06 15:56:04,280 ERROR [STDERR:151] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                  2007-09-06 15:56:04,280 ERROR [STDERR:151] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                  2007-09-06 15:56:04,282 ERROR [STDERR:151] at java.lang.reflect.Method.invoke(Method.java:585)
                                  2007-09-06 15:56:04,283 ERROR [STDERR:151] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
                                  2007-09-06 15:56:04,283 ERROR [STDERR:151] at sun.rmi.transport.Transport$1.run(Transport.java:153)
                                  2007-09-06 15:56:04,284 ERROR [STDERR:151] at java.security.AccessController.doPrivileged(Native Method)
                                  2007-09-06 15:56:04,285 ERROR [STDERR:151] at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
                                  2007-09-06 15:56:04,285 ERROR [STDERR:151] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
                                  2007-09-06 15:56:04,286 ERROR [STDERR:151] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
                                  2007-09-06 15:56:04,287 ERROR [STDERR:151] at java.lang.Thread.run(Thread.java:595)
                                  2007-09-06 15:56:04,289 ERROR [STDERR:151] Caused by: java.lang.ClassNotFoundException: No ClassLoaders found for: com.sun.ts.tests.common.vehicle.wsejb.WSEJBVehicleHome (no security manager: RMI class loader disabled)
                                  2007-09-06 15:56:04,289 ERROR [STDERR:151] at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:531)
                                  2007-09-06 15:56:04,291 ERROR [STDERR:151] at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:628)
                                  2007-09-06 15:56:04,292 ERROR [STDERR:151] at org.jboss.system.JBossRMIClassLoader.loadProxyClass(JBossRMIClassLoader.java:82)
                                  2007-09-06 15:56:04,292 ERROR [STDERR:151] at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294)
                                  2007-09-06 15:56:04,293 ERROR [STDERR:151] at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:238)
                                  2007-09-06 15:56:04,296 ERROR [STDERR:151] at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1499)
                                  2007-09-06 15:56:04,297 ERROR [STDERR:151] at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1462)
                                  2007-09-06 15:56:04,298 ERROR [STDERR:151] at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1698)
                                  2007-09-06 15:56:04,300 ERROR [STDERR:151] at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
                                  2007-09-06 15:56:04,301 ERROR [STDERR:151] at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
                                  2007-09-06 15:56:04,301 ERROR [STDERR:151] at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
                                  2007-09-06 15:56:04,302 ERROR [STDERR:151] at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
                                  2007-09-06 15:56:04,307 ERROR [STDERR:151] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:712)
                                  2007-09-06 15:56:04,308 ERROR [STDERR:151] ... 67 more