9 Replies Latest reply on Feb 27, 2007 5:05 AM by Ales Justin

    Beans loading with Microcontainer in JBoss AS

    Dmitry Guralnik Newbie

      Hi,

      I have ear with mcp.beans in with jboss-beans.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd" xmlns="urn:jboss:bean-deployer">




      I wanted get my beans defined in xml to use them in stateless beans.
      I tried first approach in http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossMicrocontainerFAQ implementing KernelControllerContextAware at ActionFactory. I am wondering how should I instantiate ActionFactory? Just new ActionFactory() doesn't affect calling setKernelControllerContext so I get controller uninitialized.

      It seems I missed something. Please help what should I do.
      Thank you.

      Dmitry

        • 1. Re: Beans loading with Microcontainer in JBoss AS
          Dmitry Guralnik Newbie

          Sorry, here is jboss-beans.xml:

          <?xml version="1.0" encoding="UTF-8"?>
          <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd" xmlns="urn:jboss:bean-deployer">
           <bean name="addProvider" class="com.mcp.server.action.AddProvider" />
           <bean name="McpController" class="com.mcp.server.action.ActionFactory"/>
          </deployment>


          • 2. Re: Beans loading with Microcontainer in JBoss AS
            Ales Justin Master

             

            "DGuralnik" wrote:

            <?xml version="1.0" encoding="UTF-8"?>
            <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd" xmlns="urn:jboss:bean-deployer">
            <bean name="addProvider" class="com.mcp.server.action.AddProvider" />
            <bean name="McpController" class="com.mcp.server.action.ActionFactory"/>
            </deployment>


            Try using bean-deployer_2_0.xsd.
            With the latest MC release - 2.0.Beta.

            "DGuralnik" wrote:

            I wanted get my beans defined in xml to use them in stateless beans.


            How do you wire stateless beans?

            "DGuralnik" wrote:

            I tried first approach in http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossMicrocontainerFAQ implementing KernelControllerContextAware at ActionFactory. I am wondering how should I instantiate ActionFactory? Just new ActionFactory() doesn't affect calling setKernelControllerContext so I get controller uninitialized.


            ActionFactory?

            • 3. Re: Beans loading with Microcontainer in JBoss AS
              Dmitry Guralnik Newbie

              I wouldn't like switching to 2.0 because JBoss AS 4.0.5 has Microcontainer 1.0.

              I think the stateless bean is not important in the discussion. I don't understant how to use this Microcontainer. Spring was pretty easy.

              So I has beans I declared in jboss-beans.xml. To load them I need a kernel controller as Wiki says. Well, I create ActionFactory with the kernel controller in it and expected using it as a factory for other beans (defined in jboss-beans.xml). The question is how to create ActionFactory. If it was Spring I would use some factory class provided by Spring. But here I didn't find a common approach to get the class instance. What should I do to get ActionFactory instance and then call getBean("addProvider").


              package com.mcp.server.action;
              
              import org.jboss.dependency.spi.ControllerContext;
              import org.jboss.kernel.spi.dependency.KernelController;
              import org.jboss.kernel.spi.dependency.KernelControllerContext;
              import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
              
              public class ActionFactory implements KernelControllerContextAware {
               private KernelController controller;
              
              
               public Object getBean(String name) {
               ControllerContext context = controller.getInstalledContext(name);
               return context.getTarget();
               }
              
               public void setKernelControllerContext(KernelControllerContext arg0) throws Exception {
               controller = arg0.getKernel().getController();
              
               }
              
               public void unsetKernelControllerContext(KernelControllerContext arg0) throws Exception {
               // TODO Auto-generated method stub
              
               }


              • 4. Re: Beans loading with Microcontainer in JBoss AS
                Ales Justin Master

                 

                "DGuralnik" wrote:
                I wouldn't like switching to 2.0 because JBoss AS 4.0.5 has Microcontainer 1.0.


                Yes, but as a separate deployer, right?

                "DGuralnik" wrote:

                I think the stateless bean is not important in the discussion. I don't understant how to use this Microcontainer. Spring was pretty easy.

                MC as an IoC is a lot more than Spring.
                But it is meant for different purpose - app. server kernel, service state machine... not so much with huge Utils and good alround hooks.
                We are working on it to provide better hooks, more documentation, examples, ...

                "DGuralnik" wrote:

                So I has beans I declared in jboss-beans.xml. To load them I need a kernel controller as Wiki says. Well, I create ActionFactory with the kernel controller in it and expected using it as a factory for other beans (defined in jboss-beans.xml). The question is how to create ActionFactory. If it was Spring I would use some factory class provided by Spring. But here I didn't find a common approach to get the class instance. What should I do to get ActionFactory instance and then call getBean("addProvider").


                package com.mcp.server.action;
                
                import org.jboss.dependency.spi.ControllerContext;
                import org.jboss.kernel.spi.dependency.KernelController;
                import org.jboss.kernel.spi.dependency.KernelControllerContext;
                import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
                
                public class ActionFactory implements KernelControllerContextAware {
                 private KernelController controller;
                
                
                 public Object getBean(String name) {
                 ControllerContext context = controller.getInstalledContext(name);
                 return context.getTarget();
                 }
                
                 public void setKernelControllerContext(KernelControllerContext arg0) throws Exception {
                 controller = arg0.getKernel().getController();
                
                 }
                
                 public void unsetKernelControllerContext(KernelControllerContext arg0) throws Exception {
                 // TODO Auto-generated method stub
                
                 }


                There are ways - register bean into JNDI, MBeanServer, ... And then get them out from there as well.
                I agree, should be better documented, but currently you are on your own - hopefully not for long.

                • 5. Re: Beans loading with Microcontainer in JBoss AS
                  Dmitry Guralnik Newbie

                  Thank you.
                  I am new with JBoss. Well....
                  Is it NOT enough to have mcp.beans file with the beans and the xml description that is packed to my ear?

                  If it is NOT, what way is to have all environment things about Microcontainer beans in ear? Anyway, please give me some detail (example) how to use MBeanServer for that purpose.

                  Thank you.

                  • 6. Re: Beans loading with Microcontainer in JBoss AS
                    Ales Justin Master

                     

                    "DGuralnik" wrote:

                    Is it NOT enough to have mcp.beans file with the beans and the xml description that is packed to my ear?

                    It is enough, but I would still change it to v2.0.Beta (or trunk from SVN) - a lot of new features.


                    If it is NOT, what way is to have all environment things about Microcontainer beans in ear? Anyway, please give me some detail (example) how to use MBeanServer for that purpose.

                    See JMXIntroduction test case.
                    Or search the MC developers or POJO server forum, I know we had a huge debate about this.

                    • 7. Re: Beans loading with Microcontainer in JBoss AS
                      Dmitry Guralnik Newbie

                      Is it really enough just to register ActionFactory in MBeanServer or provide it a jndi name? Why KernelControllerContextAware must be called in this case by the server?

                      • 8. Re: Beans loading with Microcontainer in JBoss AS
                        Ales Justin Master

                        If you use something similar to JMXIntroduction or JNDIIntroduction (see TestCases), you don't have to use KCCA.