8 Replies Latest reply on May 16, 2008 10:12 AM by wolfc

    Get at Kernel from Unmanaged Object

    alrubinger

      I've got an unmanaged object into which I'd like to inject/look up an MC Bean.

      KernelLocator.getKernel() won't do the trick, as I've got no KernelControllerContext to set.

      In AS is there any special magic to get at this (ie. Some aspect placing the Kernel/Context/Bus in a ThreadLocal or similar)?

      Note that the unmanaged object is not instanciated under my control, so it's just a POJO from which I need to access MC.

      S,
      ALR

        • 1. Re: Get at Kernel from Unmanaged Object
          alesj

           

          "ALRubinger" wrote:

          KernelLocator.getKernel() won't do the trick, as I've got no KernelControllerContext to set.

          Where to you need KCC here?
          KernelLocator.getKernel gives you Kernel instance, from where you get Controller, ...
          But this is very ugly, and I've never liked this KL static hack.
          We should be able to provide integration point in almost all cases, deployers being the right integration point.

          "ALRubinger" wrote:

          In AS is there any special magic to get at this (ie. Some aspect placing the Kernel/Context/Bus in a ThreadLocal or similar)?

          Hmmm, interesting AOP hack idea. :-)

          "ALRubinger" wrote:

          Note that the unmanaged object is not instanciated under my control, so it's just a POJO from which I need to access MC.

          I would still try to push some handle all the way up to this pojo.

          I've got simialr problems when dealing with Seam and MC.
          Since how Seam apps are started is through some ServletListener, which is of course a few layers from MC.
          Still need to see what is to do there ...

          • 2. Re: Get at Kernel from Unmanaged Object
            alrubinger

             

            "alesj" wrote:
            "ALRubinger" wrote:

            KernelLocator.getKernel() won't do the trick, as I've got no KernelControllerContext to set.

            Where to you need KCC here?
            KernelLocator.getKernel gives you Kernel instance, from where you get Controller,
            ...
            But this is very ugly, and I've never liked this KL static hack.
            We should be able to provide integration point in almost all cases, deployers being the right integration point.


            And if the POJO has no access to the deployer we've got the same problem?

            How about a solution a la JNDI does? ie:

            // Configuration from a "jboss-mc.properties" on the CP
            org.jboss.mc.McContext context = new McContext();
            context.getKernel();


            "alesj" wrote:
            "ALRubinger" wrote:

            Note that the unmanaged object is not instanciated under my control, so it's just a POJO from which I need to access MC.

            I would still try to push some handle all the way up to this pojo.


            Yeah, for now I have a class called "Hack" which puts my MC Bean in a public static variable. :). The POJO in question is a JNDI ObjectFactory, created on each lookup by JNP Server.

            "alesj" wrote:
            Still need to see what is to do there ...


            Cool, lemme know. This is a requirement of the EJB3 Proxy Component, which is designed to heavily leverage MC as an underlying registry and configuration mechanism.

            S,
            ALR

            • 3. Re: Get at Kernel from Unmanaged Object
              alrubinger

               

              "alesj wrote:
              "KernelLocator.getKernel gives you Kernel instance, from where you get Controller, ..


              Should have clarified; this gives me null. :)

              S,
              ALR

              • 4. Re: Get at Kernel from Unmanaged Object
                alesj

                 

                "ALRubinger" wrote:

                Yeah, for now I have a class called "Hack" which puts my MC Bean in a public static variable. :). The POJO in question is a JNDI ObjectFactory, created on each lookup by JNP Server.

                Couldn't you just make this JNP server MC aware, some wrapper, and then with the help of some interface push that handle further.
                Naming should be configurable, I remember having naming -service.xml somewhere.

                • 5. Re: Get at Kernel from Unmanaged Object
                  alrubinger

                   

                  "alesj" wrote:
                  Couldn't you just make this JNP server MC aware, some wrapper, and then with the help of some interface push that handle further.
                  Naming should be configurable, I remember having naming -service.xml somewhere.


                  Let's shelve my one concrete example, for now I have several. :)

                  What, in your view, is more friendly?

                  1) Decorator Pattern for anything wishing to leverage MC
                  2) Kernel is transparent, but available, to anything in the process

                  Security concerns aside for the moment, I'm asking that a Kernel be able to be looked up from a POJO. Is that contrary to the aims of the MicroContainer project? How powerful a feature it'd be.

                  S,
                  ALR



                  • 6. Re: Get at Kernel from Unmanaged Object
                    alesj

                     

                    "ALRubinger" wrote:

                    1) Decorator Pattern for anything wishing to leverage MC

                    I'm bad with names, if you can illustrate what this would do?

                    "ALRubinger" wrote:

                    2) Kernel is transparent, but available, to anything in the process

                    All MC core objects are services inside MC's Controller, so they can be easily injected.
                    But that means your POJOs are MC aware, not really a light decision to take.
                    But if that's AS5 building block, then it should be a np.

                    "ALRubinger" wrote:

                    Security concerns aside for the moment, I'm asking that a Kernel be able to be looked up from a POJO. Is that contrary to the aims of the MicroContainer project? How powerful a feature it'd be.

                    This explains it best ;-)
                    - http://www.jboss.com/index.html?module=bb&op=viewtopic&t=133488

                    • 7. Re: Get at Kernel from Unmanaged Object
                      alrubinger

                       

                      "alesj" wrote:
                      "ALRubinger" wrote:

                      1) Decorator Pattern for anything wishing to leverage MC

                      I'm bad with names, if you can illustrate what this would do?


                      I use the term loosely for any wrapper object which adds behaviour to an existing implementation, just as you'd proposed. But Wikipedia defines it as a Runtime introduction, analogous (in final result anyway) to a Mixin in AOP (load- or instrument-time).

                      http://en.wikipedia.org/wiki/Decorator_pattern

                      "alesj" wrote:
                      "ALRubinger" wrote:

                      2) Kernel is transparent, but available, to anything in the process

                      All MC core objects are services inside MC's Controller, so they can be easily injected.
                      But that means your POJOs are MC aware, not really a light decision to take.
                      But if that's AS5 building block, then it should be a np.
                      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=133488


                      Hm, that does introduce an API dependency which in a perfect universe should be avoided. Problem is, not all of our code is or can be an MC Bean itself.

                      Users of EJB3 have the same problem for unmanaged objects - they can't inject @Resource or @EJB, so they've gotta do a JNDI lookup.

                      For AS5, we're already dependent upon MC for the Deployment API, and we'll probably continue this trend for Standalone/Embedded spins. Plus MC is a perfect project anyway, right? So let's get married.

                      S,
                      ALR

                      • 8. Re: Get at Kernel from Unmanaged Object
                        wolfc