3 Replies Latest reply on May 21, 2010 6:10 AM by alesj

    KernelLocator.getKernel returns null always

    abuantar

      I need the kernel reference but KernelLocation.getKernel always returns null, any idea?

      do I need to create new bean for KernelLocation ?

        • 1. Re: KernelLocator.getKernel returns null always
          alesj
          I need the kernel reference but KernelLocation.getKernel always returns null, any idea?

          do I need to create new bean for KernelLocation ?

          Yes, you need to install KernelLocator bean in order to get access to Kernel.

           

          But this is a hack, something we don't really encourage and will almost definitely be removed in the future from our distribution.

          e.g. there might be scoped Kernels involved later on, and with this approach you could get the invalid one

          • 2. Re: KernelLocator.getKernel returns null always
            abuantar

            What does it mean scoped kernels?  why to have multiple kernels?

            Do you think in Jboss 5 production environment will have scoped kernels? or just one kernel?

            Can I get corresponding kernel from class loader instance (for example: BaseClassLoader@a0000{vfszip:/C:/jboss/server/dev/deploy/MyWebApp.war/}

            ?

             

            I have the class loader and I need the MainDeployer / DeploymentContext of the application which was loaded by this class loader, I can't add beans to the application.

             

             

            Thanks

            • 3. Re: KernelLocator.getKernel returns null always
              alesj
              What does it mean scoped kernels?

              Scoped ~ hierarchy, sort of parent / child relationship.

              There can be other models as well (not just hierarchy); e.g. peer model.

              why to have multiple kernels?

              Isolation.

              Overriding.

              Visibility rules.

              ...

               

              Do you think in Jboss 5 production environment will have scoped kernels? or just one kernel?

              We already use some of this in EJB and JNDI naming -- but the api actually needs a lot more work.

              Dunno if this is already in JBoss5 (my guess is no).

               

              But like I said, having single kernel is impl detail, which can be, for any reason, changed at any time.

              e.g. look at OSGi and it's nested frameworks spec / impl

               

              Can I get corresponding kernel from class loader instance (for example: BaseClassLoader@a0000{vfszip:/C:/jboss/server/dev/deploy/MyWebApp.war/}

              ?

               

              I have the class loader and I need the MainDeployer / DeploymentContext of the application which was loaded by this class loader, I can't add beans to the application.

              You can try this hack based on impl details, since direct API isn't meant for such things.

               

              Module module = ClassLoading.getModuleForClassLoader(cl);

              if (module instance of AbstractDeploymentClassLoaderPolicyModule)

              {

                 AbstractDeploymentClassLoaderPolicyModule adclpm = (AbstractDeploymentClassLoaderPolicyModule)module;

                 DeploymentUnit unit = adclpm.getUnit();

                 MainDeployer md = unit.getMainDeployer();

                 ControllerContext context = unit.getTopLevel().getAttachment(ControllerContext.class);

                 ...

              }

               

              But a side note, this way you actually get the unit which owns this Module, which might not be your sub-deployment's unit.

              e.g. jar inside an ear