1 2 3 Previous Next 31 Replies Latest reply on Sep 20, 2007 8:24 AM by adrian.brock Go to original post
      • 15. Re: AOP asintegration WITHOUT the integration :-)

         

        "kabir.khan@jboss.com" wrote:
        How do I turn on these new classloaders in jboss-head? I'd like to see how this all hangs together...


        You and Bill are cut from the same cloth. ;-)
        http://www.jboss.com/index.html?module=bb&op=viewtopic&t=113494

        • 16. Re: AOP asintegration WITHOUT the integration :-)
          kabirkhan

           

          "adrian@jboss.org" wrote:
          "kabir.khan@jboss.com" wrote:

          You and Bill are cut from the same cloth. ;-)
          http://www.jboss.com/index.html?module=bb&op=viewtopic&t=113494


          lol - well he was the one who discovered me - or the other way round or something


          • 17. Re: AOP asintegration WITHOUT the integration :-)

             

            "kabir.khan@jboss.com" wrote:

            From the tests I wrote in the AOP integration, the basic ScopedClassPool of javassist
            seems to be able to handle what we need for OSGi?


            That depends a bit what happens inside the new classloaders. The javassist.LoaderClassPath, which seems to be the main type of ClassPath used, uses the underlying classloader and calls loader.getResource("org/acme/SomeClass.class") to load up the class bytes. Does getResource() on the OSGi classloaders follow the full rules for export and import?

            i.e. if:
            -loaderA exports org.acme, and also has the private org.private package (which contains the class Something)
            -loaderB imports loaderA (see my question at the end, I'm not 100% sure how this works), and does not redefine org.acme or org.private classes

            Then as I understand it, we can do
            loaderB.loadClass("org.acme.Blah")
            while this will return nothing
            loaderB.loadClass("org.private.Something")

            Will this still hold?
            loaderB.getResource("org/acme/Blah.class") //valid
            loaderB.getResource("org/private/Something.class) //nothing

            If this is the case, then we are probably good, unless you think it is a bad idea to depend on this?

            One further question regarding importAll and delegates... Does importAll=true imply that every other classloader in the domain is a delegate. If importAll is false, will we only look in the delegates we have explicitly declared?

            • 18. Re: AOP asintegration WITHOUT the integration :-)
              kabirkhan

              That's bizarre, my last post seems to have overwritten yours, and our names have been reversed?!?!?

              For completeness, here is the post that I was replying to

              "adrian" wrote:


              "kabir.khan@jboss.com" wrote:
              wrote : Do you have some pointers to the classloading rules? I still need to get my head around this part, but in the meantime do you think we need special ClassPools as well?


              I think the javassist ClassPath is closer to how the new classloaders work.
              The deployers could create a ClassPool/ClassPath structure
              that matches the classloader configuration.

              Like I said I don't think determining what configuration applies based on class
              locations/visibility is the correct solution anyway, even though I did manage to fix
              some issues by making AOP use ClassPool.getClassLoader() instead of the TCL.

              >From the tests I wrote in the AOP integration, the basic ScopedClassPool of javassist
              seems to be able to handle what we need for OSGi?



              • 19. Re: AOP asintegration WITHOUT the integration :-)

                 

                "adrian@jboss.org" wrote:

                i.e. if:
                -loaderA exports org.acme, and also has the private org.private package (which contains the class Something)
                -loaderB imports loaderA (see my question at the end, I'm not 100% sure how this works), and does not redefine org.acme or org.private classes

                Then as I understand it, we can do
                loaderB.loadClass("org.acme.Blah")
                while this will return nothing
                loaderB.loadClass("org.private.Something")

                Will this still hold?
                loaderB.getResource("org/acme/Blah.class") //valid
                loaderB.getResource("org/private/Something.class) //nothing

                If this is the case, then we are probably good, unless you think it is a bad idea to depend on this?


                Its not necessarily true (there's seperate filters for resources and classes)
                but I don't see why you would implement something that did it differently?
                The seperate filters is more so you can do things optimized to the different
                syntaxes.


                One further question regarding importAll and delegates... Does importAll=true imply that every other classloader in the domain is a delegate. If importAll is false, will we only look in the delegates we have explicitly declared?


                Effectively yes. But importAll isn't implemented that way. It would be too
                much of a pain to update all the other classloaders every time a classloader appears or
                disappears. :-)

                • 20. Re: AOP asintegration WITHOUT the integration :-)
                  kabirkhan

                   

                  "adrian@jboss.org" wrote:

                  My preferred solution to use the scopes. i.e. you can choose
                  to deploy aop config at the SERVER, SUBSYSTEM, APPLICATION level, etc.

                  Is there an existing deployer for selecting at what level things should be deployed at? Or should this be something specific to the AOP deployer?

                  • 21. Re: AOP asintegration WITHOUT the integration :-)
                    alesj

                     

                    "kabir.khan@jboss.com" wrote:

                    Is there an existing deployer for selecting at what level things should be deployed at? Or should this be something specific to the AOP deployer?

                    Read the first paragraph of this post :-)
                    http://www.jboss.org/index.html?module=bb&op=viewtopic&t=117444

                    • 22. Re: AOP asintegration WITHOUT the integration :-)
                      kabirkhan

                      Since Module is in the deployers-impl package I assume I should not use that from my AspectDeployer? I don't see any other way to get hold of of the information from ClassLoaderPolicy?

                      • 23. Re: AOP asintegration WITHOUT the integration :-)
                        kabirkhan

                         

                        "adrian@jboss.org" wrote:
                        "adrian@jboss.org" wrote:

                        My preferred solution to use the scopes. i.e. you can choose
                        to deploy aop config at the SERVER, SUBSYSTEM, APPLICATION level, etc.
                        but this requires doing a lot work fixing everything to make sure
                        it sets the correct thread local MetaData for AOP to know which Scope
                        applies at runtime.


                        This thead local is really just a generalization of ejbs/mbeans
                        setting the correct context classloader and java:/comp/env

                        In principle once this is done. The only work required by AOP
                        would be for the deployer to create hierarchical ...


                        Is this work in progress? Or please let me know how I can help make this happen.


                        • 24. Re: AOP asintegration WITHOUT the integration :-)

                           

                          "kabir.khan@jboss.com" wrote:
                          Since Module is in the deployers-impl package I assume I should not use that from my AspectDeployer? I don't see any other way to get hold of of the information from ClassLoaderPolicy?


                          When I created the "Module" class, I only anticipated it was an implementation detail
                          of the classloader dependencies so I didn't put it in the spi.

                          Any use of it would be a "hack" until the proper scoped metadata solution is done.

                          • 25. Re: AOP asintegration WITHOUT the integration :-)

                             

                            "kabir.khan@jboss.com" wrote:
                            "adrian@jboss.org" wrote:
                            "adrian@jboss.org" wrote:

                            My preferred solution to use the scopes. i.e. you can choose
                            to deploy aop config at the SERVER, SUBSYSTEM, APPLICATION level, etc.
                            but this requires doing a lot work fixing everything to make sure
                            it sets the correct thread local MetaData for AOP to know which Scope
                            applies at runtime.


                            This thead local is really just a generalization of ejbs/mbeans
                            setting the correct context classloader and java:/comp/env

                            In principle once this is done. The only work required by AOP
                            would be for the deployer to create hierarchical ...


                            Is this work in progress? Or please let me know how I can help make this happen.


                            It's not work in progress, at least not yet.
                            I only added the deployments scope a week ago.

                            I'd suggest you try it yourself with a mock test, e.g. write an aspect
                            that pushes the metadata from the advisor onto the stack and test it using
                            the aop proxy where you can pass in the metadata.

                            • 26. Re: AOP asintegration WITHOUT the integration :-)
                              kabirkhan

                               

                              "adrian@jboss.org" wrote:

                              It's not work in progress, at least not yet.
                              I only added the deployments scope a week ago.

                              I'd suggest you try it yourself with a mock test, e.g. write an aspect
                              that pushes the metadata from the advisor onto the stack and test it using
                              the aop proxy where you can pass in the metadata.


                              I've created some simple tests on my machine emulating what I think will happen at deployer level.
                               public void testDomain() throws Exception
                               {
                               URL url = null;
                               Domain domain = null;
                               try
                               {
                               //Create our instance to be proxied before we start deploying stuff
                               TestIntercepted test = new TestIntercepted();
                              
                               //Deployer creates metadata and populates that with the necessary domain
                               createAndPushMetaData(createScopedDomain("xxx"));
                              
                               //We get the domain out of the metadata and deploy into that
                               MetaData md = MetaDataStack.peek();
                               domain = md.getMetaData(Domain.class);
                               assertNotNull(domain);
                               url = deploy("1", Thread.currentThread().getContextClassLoader(), domain);
                              
                               //create the proxy, the scoped manger is taken from the metadata stack
                               AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
                               params.setTarget(test);
                               params.setMetaData(md);
                              
                               AOPProxyFactory factory = new GeneratedAOPProxyFactory();
                               TestIntercepted proxy = (TestIntercepted)factory.createAdvisedProxy(params);
                               assertFalse(proxy.getClass() == TestIntercepted.class);
                              
                               TestInterceptor.intercepted = null;
                               proxy.doSomething();
                               assertNotNull(TestInterceptor.intercepted);
                               assertEquals("First", TestInterceptor.intercepted);
                               }
                               finally
                               {
                               if (MetaDataStack.peek() != null)
                               {
                               MetaDataStack.pop();
                               }
                               undeploy(url, domain);
                               }
                               }
                              
                               private ScopeKey createScope(String app, String dep)
                               {
                               ScopeKey result = ScopeKey.DEFAULT_SCOPE.clone();
                               result.addScope(CommonLevels.APPLICATION, app);
                               result.addScope(CommonLevels.DEPLOYMENT, dep);
                               return result;
                               }
                              
                               private void createAndPushMetaData(Domain scopedDomain)
                               {
                               //Deployer creates Domain depending on classloader rules, and adds it to metadata for deployment
                               ScopeKey scopeKey = createScope("Test", scopedDomain.getDomainName());
                               MutableMetaDataRepository repository = new BasicMetaDataRepository();
                               MetaDataRetrieval retrieval = new MemoryMetaDataLoader(scopeKey);
                               repository.addMetaDataRetrieval(retrieval);
                              
                               if (scopedDomain != null)
                               {
                               ((MutableMetaData)retrieval).addMetaData(scopedDomain, Domain.class);
                               }
                               MetaData metadata = repository.getMetaData(scopeKey);
                               MetaDataStack.push(metadata);
                               }
                              
                               private Domain createScopedDomain(String name)
                               {
                               AspectManager manager = AspectManager.getTopLevelAspectManager();
                               Domain scopedDomain = new Domain(manager, name, false);
                               return scopedDomain;
                               }
                              
                              


                              I think I am missing a part in the metadata stuff. What I have pasted in above works fine for generating the proxies, but I don't see how this will work when doing weaving? What if there is no metadata on the stack? Or would that be a bug when running within JBoss. Alternatively, we would need something to map from the classloader passed in to AspectManager.translate() to the metadata, but that sounds suspiciously like a variation of what we have at the moment (classloader=>ScopedClassLoaderDomain)?

                              The second part of this is that the metadata is currently only really used at weaving/advisor population time. i.e we use the metadata to get the domain, and the annotations etc. to be used for the bindings etc. I think you have in mind something for the same class to have different interceptor chains invoked depending on the MetaData on the stack?

                              • 27. Re: AOP asintegration WITHOUT the integration :-)
                                kabirkhan

                                 

                                "adrian@jboss.org" wrote:
                                "kabir.khan@jboss.com" wrote:
                                Since Module is in the deployers-impl package I assume I should not use that from my AspectDeployer? I don't see any other way to get hold of of the information from ClassLoaderPolicy?


                                When I created the "Module" class, I only anticipated it was an implementation detail
                                of the classloader dependencies so I didn't put it in the spi.

                                Any use of it would be a "hack" until the proper scoped metadata solution is done.


                                Are you saying "don't use it", or "use it and we'll retrofit an SPI"? :-) As far as I can tell I will need information from the ClassLoaderPolicy.

                                • 28. Re: AOP asintegration WITHOUT the integration :-)

                                   

                                  "kabir.khan@jboss.com" wrote:

                                  Are you saying "don't use it", or "use it and we'll retrofit an SPI"? :-) As far as I can tell I will need information from the ClassLoaderPolicy.


                                  I'm saying any use of the classloading metadata for the AOP domain construction
                                  would be a hack until we have a real solution based on metadata context
                                  rather than the classloader of the aspectized class/aspect class/joinpoint.

                                  The latter (classloader solution) is just a temporary solution to reproduce
                                  what jboss4 does. I don't think we need to create a SPI (which we will need to
                                  support forever) for something that is a temporary hack.

                                  If we created a SPI, it wouldn't be the Unified ClassLoader or the new classloader
                                  it would have to cover all possible classloading models that people might want
                                  to plugin to the deployers.

                                  • 29. Re: AOP asintegration WITHOUT the integration :-)

                                     

                                    "kabir.khan@jboss.com" wrote:
                                    What if there is no metadata on the stack? Or would that be a bug when running within JBoss.


                                    It wouldn't necessarily be a bug, e.g. you can use the default scope if there isn't one,
                                    but it would be a bug for stuff that is JBoss Managed, e.g. invocations from the
                                    EJB, JMX, JCA container, etc.


                                    The second part of this is that the metadata is currently only really used at weaving/advisor population time. i.e we use the metadata to get the domain, and the annotations etc. to be used for the bindings etc. I think you have in mind something for the same class to have different interceptor chains invoked depending on the MetaData on the stack?


                                    That's the second part of completing the aop/metadata stuff.
                                    A scoped deployment should be able to aspectize a class (e.g. the OracleConnection)
                                    in a different way to the non-scoped usage (which might not even be aspectized).

                                    I proposed it should be a function of what metadata context creates the Object
                                    (Class instance) and so would require extra work to intercept the instantiation
                                    and check the context to see whether a proxy is needed instead of the original
                                    (aspectized) class in a scoped environment.

                                    You might be able to think of a more efficient way to do this?
                                    Especially for when the default scope doesn't want an aspectized version of the class.