9 Replies Latest reply on Oct 5, 2002 8:38 AM by adrian.brock

    Integreate custom services via MBeans

    roysun

      I tried code sample in "How to Integreate custom services via MBeans" in 3.0 document.

      The bind seems work fine. I can see jndi name and Hashtable registed on naming server through JNDIView->list. But I got a null from lookup of client code.
      The client code is as following. Thanks for help.

      Roy

      =====

      Hashtable h = new Hashtable();
      h.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      h.put(Context.PROVIDER_URL, "localhost:1099");
      h.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

      try{
      InitialContext initial = new InitialContext(h);
      Object obj = (Object) initial.lookup(jndiname);
      System.out.println("obj=" + obj);
      }
      catch(Exception e)
      {
      e.printStackTrace();
      }

        • 1. Re: Integreate custom services via MBeans

          Which jndiname?

          Have you tried listing the initial context?

          Regards,
          Adrian

          • 2. Re: Integreate custom services via MBeans
            roysun

            The jndiName is "ValidatorFactory" defined like ValidatorFactory in user-service.xml.
            I use the following code to list and got NamingEnumeration which include the information like "ValidatorFactory: java.util.HashMap". But I still get null from lookup("ValidatorFactory").
            Any others I need to consider?
            Thanks

            Roy
            ====
            NamingEnumeration e = initial.list("");
            while(e.hasMore())
            {
            System.out.println("e=" + e.next());
            }

            • 3. Re: Integreate custom services via MBeans

              Does it work when you lookup inside JBoss?

              What does the binding code look like?

              Regards,
              Adrian

              • 4. Re: Integreate custom services via MBeans
                roysun

                It is same as the sample code in document.

                Roy

                ===

                private void rebind() throws NamingException
                {
                InitialContext rootCtx = new InitialContext();
                // Get the parent context into which we are to bind
                Name fullName = rootCtx.getNameParser("").parse(jndiName);
                log.debug("fullName="+fullName);
                Name parentName = fullName;
                if( fullName.size() > 1 )
                parentName = fullName.getPrefix(fullName.size()-1);
                else
                parentName = new CompositeName();
                Context parentCtx = createContext(rootCtx, parentName);
                Name atomName = fullName.getSuffix(fullName.size()-1);
                String atom = atomName.get(0);
                NonSerializableFactory.rebind(parentCtx, atom, new java.util.HashMap());
                }

                • 5. Re: Integreate custom services via MBeans

                  There's your answer,
                  NonSerializableFactory is for binding
                  stuff locally. If you send it over the wire,
                  the bindings are lost, they are held in a static map.

                  Regards,
                  Adrian

                  • 6. Re: Integreate custom services via MBeans
                    roysun

                    If there is any way to solve the problem? I want the registered object be accessed globally.

                    Thanks
                    Roy

                    • 7. Re: Integreate custom services via MBeans

                      I assume you are talking about an MBean from the
                      title of this thread.

                      Binding an object into JNDI won't work for anything
                      but trivial objects, because the client will get a
                      serialized copy.

                      You need to bind a proxy or remote object that
                      invokes back on the server object.

                      Alteratively, for an MBean use an adaptor/connector
                      such as the RMI adaptor. There are plenty of threads
                      on this.

                      Next week, somebody is commiting a remoting system
                      to JBossMX. I've not had chance to look at the details
                      yet, but the basic function is to allow discovery
                      of remote mbeans and bind them into your local
                      MBeanServer. The remote nature of the MBean is
                      transparent, I think?

                      Regards,
                      Adrian

                      • 8. Re: Integreate custom services via MBeans
                        roysun

                        Very interesting.

                        In my case, I'll use session bean to wrap the registered object through JNDI lookup. The remote client can access the registered object via the session bean. It should work. Right?

                        Thank you very much.

                        Roy

                        • 9. Re: Integreate custom services via MBeans

                          That is one way of doing it :-)

                          Regards,
                          Adrian