4 Replies Latest reply on Aug 10, 2006 3:19 PM by Adrian Brock

    Pushing beans into the kernel

    Scott Stark Master

      One thing I'm hung up on in terms of the SARDeployer migration is getting the ServerImpl bean into the kernel for use by the JMXKernel so that a ServerImplMBean can be exposed. What I have tried to do is just put the server instance into the kernel registry with a ControllerState.CONFIGURED requiredState and state value:

       // Register the Server instance in the kernel
       KernelRegistry registry = getKernel().getRegistry();
       AbstractKernelRegistryEntry serverEntry = new AbstractKernelRegistryEntry(server)
       {
       @Override
       public ControllerState getRequiredState()
       {
       return ControllerState.CONFIGURED;
       }
      
       @Override
       public ControllerState getState()
       {
       return ControllerState.CONFIGURED;
       }
       };
       registry.registerEntry("org.jboss.system.server.Server", serverEntry);
      
       // Validate that everything is ok
       kernelDeployer.validate();
      


      however the validation of the deployer-beans.xml initialization is failing with this error:
      *** DEPLOYMENTS MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}
      JMXKernel -> org.jboss.system.server.Server{Configured:Configured}, JMXClassLoader{Described:Installed}
      SARDeployer -> JMXClassLoader{Described:Installed}, JMXKernel{Configured:Instantiated}, JMXKernel{Configured:Instantiated}
      


      It looks like everything is to the required state so I'm not sure why this error is occuring. What is it telling me?

      The bigger question is what is the correct way to push a fully Instantiated bean into the kernel for use in dependency relationships?


        • 1. Re: Pushing beans into the kernel
          Scott Stark Master

          So the problem is that the KernelController knows nothing about the server. I did get past this doing:

           // Register the Server instance in the kernel
           Kernel kernel = getKernel();
           KernelController controller = kernel.getController();
           KernelRegistry registry = kernel.getRegistry();
           KernelConfigurator config = kernel.getConfigurator();
           BeanInfo info = config.getBeanInfo(server.getClass());;
           AbstractBeanMetaData metaData = new AbstractBeanMetaData("org.jboss.system.server.Server", null);
           AbstractKernelControllerContext serverEntry = new AbstractKernelControllerContext(info, metaData, server);
           controller.install(serverEntry);
          


          At first this failed because the server instance was being restarted by the kernel while it was already in start due to the ServerLoader calling start. I just worked around this for now by checking for a duplicate call. I need to figure out how to install a bean that is already started.


          • 2. Re: Pushing beans into the kernel
            Adrian Brock Master

             

            "scott.stark@jboss.org" wrote:
            So the problem is that the KernelController knows nothing about the server. I did get past this doing:

             // Register the Server instance in the kernel
             Kernel kernel = getKernel();
             KernelController controller = kernel.getController();
             KernelRegistry registry = kernel.getRegistry();
             KernelConfigurator config = kernel.getConfigurator();
             BeanInfo info = config.getBeanInfo(server.getClass());;
             AbstractBeanMetaData metaData = new AbstractBeanMetaData("org.jboss.system.server.Server", null);
             AbstractKernelControllerContext serverEntry = new AbstractKernelControllerContext(info, metaData, server);
             controller.install(serverEntry);
            


            At first this failed because the server instance was being restarted by the kernel while it was already in start due to the ServerLoader calling start. I just worked around this for now by checking for a duplicate call. I need to figure out how to install a bean that is already started.


            There currently is no way to do this.

            Don't get hung up on the kernel controller.install(BeanMetaData)
            this is just a convenience over the
            controller.install(ControllerContext)

            What you need to do is create an AbstractKernelControllerContext
            that has a minimal set of actions

            e.g. add

             /** The no actions */
             private static final KernelControllerContextActions noActions = KernelControllerContextActions.getNoActions();
            
             /**
             * Create an abstract controller context
             * with no actions and no meta data
             *
             * @name the name of the bean
             * @param target the target object
             */
             public AbstractKernelControllerContext(Object name, Object target)
             {
             super(name, noActions, new AbstractDependencyInfo(), target);
             if (System.getSecurityManager() != null)
             accessContext = AccessController.getContext();
             }
            


            • 4. Re: Pushing beans into the kernel
              Adrian Brock Master

              It's related but not the same.

              The feature there was to pass an Object and some metadata.
              It goes through all the normal lifecycle except instantation.