1 2 Previous Next 20 Replies Latest reply on Aug 6, 2008 9:28 AM by alesj

    Pushing correct aspect manager for a deployment

    kabirkhan

      I am working on an edge case for deploying aop in AS using aop-mc-int. I have a deployment1 using default classloading:

      <deployment xmlns="urn:jboss:bean-deployer:2.0">
      
       <bean name="GlobalDependency" class="org.jboss.test.aop.scopeddependency.GlobalDependency"/>
      
      </deployment>
      


      and a deployment2 using a scoped classloader
      <deployment xmlns="urn:jboss:bean-deployer:2.0">
      
       <interceptor xmlns="urn:jboss:aop-beans:1.0"
       name="ScopedInterceptor"
       class="org.jboss.test.aop.scopeddependency.ScopedInterceptor"
       manager-bean="AspectManager"
       manager-property="aspectManager">
       <property name="scopedDependency"><inject bean="ScopedDependency"/></property>
       </interceptor>
      
       <bind xmlns="urn:jboss:aop-beans:1.0"
       pointcut="execution(* org.jboss.test.aop.scopeddependency.ScopedTester->*(..))"
       manager-bean="AspectManager"
       manager-property="aspectManager">
       <interceptor-ref name="ScopedInterceptor"/>
       </bind>
      
       <bean name="ScopedTester" class="org.jboss.test.aop.scopeddependency.ScopedTester"/>
      
      </deployment>
      


      ScopedTester is incorrectly deployed since the dependencies are not picked up. The problem seems to be that AOPDependencyBuilder calls AspectManager.instance() which uses TCL to determine the scoped aspect domain to use, however in the DESCRIBE phase this classloader has not been set yet, and so the top-level AspectManager which does not contain the bindings deployed to the scoped aspect domain is used. My deployer has created the scoped aspect domain at this stage, but I need some nice way to make it available to AOPDependencyBuilder. I could push it onto a ThreadLocal, but that might be a bit hacky. What would be nice would be to be able to add it to the bean's MetaData, but as far as I can tell I have no control/access to that, I think the bean's MetaData is created by the BeanMetaDataDeployer? If such a thing exisits, is adding it to the deployments metadata an option? How do I do that?




        • 1. Re: Pushing correct aspect manager for a deployment
          kabirkhan

          Whatever we go for this will need to be part of the next aop-mc-int release

          • 2. Re: Pushing correct aspect manager for a deployment
            kabirkhan

            I have attempted to add the correct manager to the metadata for the deployment in my deployer

             unit.getMutableMetaData().addMetaData(scopedManager, AspectManager.class);
            


            This gets added to a MemoryMetaDataLoader with
            ScopeKey=[APPLICATION=vfszip:/Users/kabir/sourcecontrol/jboss-head/testsuite/output/lib/aop-scopeddependency-scoped.sar]
            


            However, the bean's MetaData does not contain that, it only contains MetaDataRetrievals for the following levels:
            WORK=10814978]
            [INSTANCE=ScopedManager_6_vfszip:/Users/kabir/sourcecontrol/jboss-head/testsuite/output/lib/aop-scopeddependency-scoped.sar]
            [CLASS=class org.jboss.test.aop.scopeddependency.ScopedTester]
            [JVM=THIS]
            

            Is this a bug, or have I completely misunderstood?



            • 3. Re: Pushing correct aspect manager for a deployment
              alesj

               

              "kabir.khan@jboss.com" wrote:

              Is this a bug, or have I completely misunderstood?

              Misunderstood. :-)

              I really don't see exactly what you're trying to do,
              so I'll try to guess as I don't understand how scoped aspect domains work. ;-)

              Probably this is not an issue with scoped beans,
              since we've gone over that - proper @annotation + PreInstallAction do all the tricks.
              Or is it, since I see you've got something called scopedManager:
              unit.getMutableMetaData().addMetaData(scopedManager, AspectManager.class);
              


              Perhaps what you're missing here, is what I've added to scoped kernels impl - the @Search notion.
              Meaning you can localize your loookup - in this case just the same scope, not doing any parent lookup.
              Hence dependency doesn't depend on the order global and scoped aspect manager are deployed.
              But this is currently only annotation based, no xml.

              As for DeploymentUnit and its MetaData, I don't think this is currently used.
              But that should be how we eventually do scoped kernels - initial control/creation from the deployment.

              • 4. Re: Pushing correct aspect manager for a deployment

                 

                "kabir.khan@jboss.com" wrote:
                I have attempted to add the correct manager to the metadata for the deployment in my deployer
                 unit.getMutableMetaData().addMetaData(scopedManager, AspectManager.class);
                


                This gets added to a MemoryMetaDataLoader with
                ScopeKey=[APPLICATION=vfszip:/Users/kabir/sourcecontrol/jboss-head/testsuite/output/lib/aop-scopeddependency-scoped.sar]
                


                However, the bean's MetaData does not contain that, it only contains MetaDataRetrievals for the following levels:
                WORK=10814978]
                [INSTANCE=ScopedManager_6_vfszip:/Users/kabir/sourcecontrol/jboss-head/testsuite/output/lib/aop-scopeddependency-scoped.sar]
                [CLASS=class org.jboss.test.aop.scopeddependency.ScopedTester]
                [JVM=THIS]
                

                Is this a bug, or have I completely misunderstood?



                It's not implemented. The ScopeInfo used by the KernelControllerContext
                that it passes to the metadata repository is not populated from the
                scope created for the Deployment component by the ScopeBuilder.

                To make this work, you'd need something like the following (untested):
                Index: src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java
                ===================================================================
                --- src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java (revision 76634)
                +++ src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java (working copy)
                @@ -27,12 +27,14 @@
                 import org.jboss.beans.metadata.spi.ClassLoaderMetaData;
                 import org.jboss.beans.metadata.spi.ValueMetaData;
                 import org.jboss.dependency.spi.Controller;
                +import org.jboss.dependency.spi.ScopeInfo;
                 import org.jboss.deployers.spi.DeploymentException;
                 import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
                 import org.jboss.deployers.structure.spi.DeploymentUnit;
                 import org.jboss.kernel.Kernel;
                 import org.jboss.kernel.plugins.dependency.AbstractKernelControllerContext;
                 import org.jboss.kernel.spi.dependency.KernelControllerContext;
                +import org.jboss.metadata.spi.scope.ScopeKey;
                
                 /**
                 * BeanMetaDataDeployer.<p>
                @@ -108,6 +110,9 @@
                 }
                 }
                 KernelControllerContext context = new AbstractKernelControllerContext(null, deployment, null);
                + ScopeInfo scopeInfo = context.getScopeInfo();
                + scopeInfo.setScope(unit.getScope());
                + scopeInfo.setMutableScope(unit.getMutableScope());
                 try
                 {
                 controller.install(context);
                


                • 5. Re: Pushing correct aspect manager for a deployment
                  • 6. Re: Pushing correct aspect manager for a deployment

                    You should be able to try this when Ales does the betas this week.

                    • 7. Re: Pushing correct aspect manager for a deployment
                      alesj

                       

                      "adrian@jboss.org" wrote:
                      You should be able to try this when Ales does the betas this week.

                      So, we're fine to do the last round of betas?
                      Or can I even do CR1 of Reflect and MDR?
                      If yes, I'll do it first thing tomorrow morning.


                      • 8. Re: Pushing correct aspect manager for a deployment

                         

                        "alesj" wrote:
                        "adrian@jboss.org" wrote:
                        You should be able to try this when Ales does the betas this week.

                        So, we're fine to do the last round of betas?


                        Let me do the StructureContext stuff today.

                        I'm going to do it in a backwards compatible way initially and deprecate
                        the old api.

                        That way we do a 2 phase change. i.e. add the new api in the beta
                        and remove the old one in CR1 of deploiyers.


                        Or can I even do CR1 of Reflect and MDR?
                        If yes, I'll do it first thing tomorrow morning.


                        I don't have a problem with doing CRs for reflect and mdr.

                        • 9. Re: Pushing correct aspect manager for a deployment
                          alesj

                           

                          "adrian@jboss.org" wrote:

                          Let me do the StructureContext stuff today.

                          I'm going to do it in a backwards compatible way initially and deprecate
                          the old api.

                          That way we do a 2 phase change. i.e. add the new api in the beta
                          and remove the old one in CR1 of deployers.

                          OK, I'll wait for it.
                          And then I'll try to do my part depending on your today's work:
                          - https://jira.jboss.org/jira/browse/JBDEPLOY-67

                          Once I'm done, I'll start the release process.
                          First doing Reflect and MDR CR1, and then betas of all the rest.

                          • 10. Re: Pushing correct aspect manager for a deployment
                            kabirkhan

                            Adrian's suggestion for JBDEPLOY-69 looks most like what I am after. Unfortunately, it does not do the job. While I get a metadata retrieval at APPLICATION scope, it is empty and does not have the metadata I put in.

                            I'm pretty sure that is the way it works, but I've spent most of the day trying to get all the snapshots working in my local copy of AS, so I could be wrong.

                            • 11. Re: Pushing correct aspect manager for a deployment
                              kabirkhan

                               

                              "adrian@jboss.org" wrote:

                              To make this work, you'd need something like the following (untested):
                              Index: src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java
                              ===================================================================
                              --- src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java (revision 76634)
                              +++ src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java (working copy)
                              @@ -27,12 +27,14 @@
                               import org.jboss.beans.metadata.spi.ClassLoaderMetaData;
                               import org.jboss.beans.metadata.spi.ValueMetaData;
                               import org.jboss.dependency.spi.Controller;
                              +import org.jboss.dependency.spi.ScopeInfo;
                               import org.jboss.deployers.spi.DeploymentException;
                               import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
                               import org.jboss.deployers.structure.spi.DeploymentUnit;
                               import org.jboss.kernel.Kernel;
                               import org.jboss.kernel.plugins.dependency.AbstractKernelControllerContext;
                               import org.jboss.kernel.spi.dependency.KernelControllerContext;
                              +import org.jboss.metadata.spi.scope.ScopeKey;
                              
                               /**
                               * BeanMetaDataDeployer.<p>
                              @@ -108,6 +110,9 @@
                               }
                               }
                               KernelControllerContext context = new AbstractKernelControllerContext(null, deployment, null);
                              + ScopeInfo scopeInfo = context.getScopeInfo();
                              + scopeInfo.setScope(unit.getScope());
                              + scopeInfo.setMutableScope(unit.getMutableScope());
                               try
                               {
                               controller.install(context);
                              


                              I tried modifying this to
                               KernelControllerContext context = new AbstractKernelControllerContext(null, deployment, null);
                               //Make sure that the metadata from the deployment gets put into the context
                               ScopeInfo scopeInfo = context.getScopeInfo();
                               scopeInfo.setScope(unit.getScope());
                               scopeInfo.setMutableScope(unit.getMutableScope());
                               scopeInfo.addMetaData(controller.getKernel().getMetaDataRepository().getMetaDataRepository(), context);
                              


                              but still do not see the required metadata from the deploymentunit

                              • 12. Re: Pushing correct aspect manager for a deployment
                                kabirkhan

                                I see TestMetaDataBeanDeployer from JBDEPLOY-69 adds the metadata in a different way

                                 public void deploy(DeploymentUnit unit) throws DeploymentException
                                 {
                                 Scope applicationScope = unit.getScope().getScope(CommonLevels.APPLICATION);
                                
                                 MemoryMetaDataLoader applicationMetaData = new MemoryMetaDataLoader(new ScopeKey(applicationScope));
                                 repository.addMetaDataRetrieval(applicationMetaData);
                                
                                 applicationMetaData.addMetaData("test", this, TestMetaDataBeanDeployer.class);
                                 }
                                


                                from what I have been doing

                                 unit.getMutableMetaData().addMetaData(scopedManager, AspectManager.class);
                                


                                I will try that instead

                                • 13. Re: Pushing correct aspect manager for a deployment

                                   

                                  "kabir.khan@jboss.com" wrote:
                                  I see TestMetaDataBeanDeployer from JBDEPLOY-69 adds the metadata in a different way


                                  The only reason I did it a different way was because the deployers
                                  were not fully configured in that test.

                                  I modified the test so it sets up the Deployer's MetaDataRepository
                                  from the Kernel's MetaDataRepository.

                                  The test now uses the mechanism you had originally and passes.

                                  public class TestMetaDataBeanDeployer extends AbstractDeployer
                                  {
                                   public TestMetaDataBeanDeployer()
                                   {
                                   setStage(DeploymentStages.PRE_REAL);
                                   }
                                  
                                   public void deploy(DeploymentUnit unit) throws DeploymentException
                                   {
                                   unit.getMutableMetaData().addMetaData("test", this, TestMetaDataBeanDeployer.class);
                                   }
                                  }
                                  


                                  I don't what you are seeing? Can you modify the test to show it?

                                  • 14. Re: Pushing correct aspect manager for a deployment
                                    kabirkhan

                                    I still do not get what I expect in the MetaData repository, none of the MetaDataRetrievals have a initialised metadataByName property.

                                    I noticed something else, before the call to

                                    scopeInfo.setScope(unit.getScope());
                                    

                                    in BeanMetaDataDeployer scopeInfo.scopeKey is
                                    [JVM=THIS, CLASS=org.jboss.beans.metadata.plugins.factory.GenericBeanFactory, INSTANCE=ScopedAlias_13_Factory$ScopedInterceptor, WORK=5644960]
                                    

                                    after the call it is
                                    [JVM=THIS, APPLICATION=vfszip:/Users/kabir/sourcecontrol/jboss-head/testsuite/output/lib/aop-scopeddependency-scoped.sar, DEPLOYMENT=vfszip:/Users/kabir/sourcecontrol/jboss-head/testsuite/output/lib/aop-scopeddependency-scoped.sar]
                                    


                                    I will take a closer look at your KernelScopeUnitTestCase.

                                    Another problem is that for scoped deployments I am changing the beans name to something unique and adding an alias annotation containing the bean name. This breaks with the new code in BeanMetaDataDeployer. I will post more on this once I have some more information about what exactly is going on...

                                    1 2 Previous Next