1 2 Previous Next 27 Replies Latest reply on Feb 26, 2007 9:16 AM by alesj Go to original post
      • 15. Re: Scoped Kernels

         

        "alesj" wrote:
        "adrian@jboss.org" wrote:
        but also needs to use ConstrollerContext.getScopeKey()


        From previous problem (duplicate 'context') temp fix, I currently have Context's hashCode under WORK level to diff the contexts. What's the appropriate fix?


        I don't understand that.


        What about this new scope key - gained from class/bean (deployment) annotations? Should it be considered once it is resolved - with some update to current context scope - or is this how I used it ok --> install ScopeKey.


        It's generally a bad idea to change an identity (hashCode/equals)
        unless you are sure that nobody storing an object in a collection
        is going to be broken by it.

        • 16. Re: Scoped Kernels
          alesj

           

          "alesj" wrote:

          From previous problem (duplicate 'context') temp fix, I currently have Context's hashCode under WORK level to diff the contexts. What's the appropriate fix?


           public ScopeKey getFullScope(KernelControllerContext context)
           {
           ScopeKey scope = ScopeKey.DEFAULT_SCOPE.clone();
           scope.addScope(CommonLevels.INSTANCE, context.getName().toString());
           BeanMetaData beanMetaData = context.getBeanMetaData();
           if (beanMetaData != null)
           {
           String bean = beanMetaData.getBean();
           if (bean != null)
           scope.addScope(CommonLevels.CLASS, bean);
           }
           // todo - some other level
           scope.addScope(CommonLevels.WORK, String.valueOf(context.hashCode()));
           return scope;
           }
          


          Otherwise I cannot differentiate between these two beans:
           <bean name="simple" class="org.jboss.test.kernel.deployment.support.SimpleBeanImpl">
           <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
           <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment1")</annotation>
           <constructor>
           <parameter>deployment1</parameter>
           </constructor>
           </bean>
          
           <bean name="simple" class="org.jboss.test.kernel.deployment.support.SimpleBeanImpl">
           <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
           <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment2")</annotation>
           <constructor>
           <parameter>deployment2</parameter>
           </constructor>
           </bean>
          


          • 17. Re: Scoped Kernels
            bkeh12

            Hi,Ales
            I try this for MC's "ScopingTestCase".

            <?xml version="1.0" encoding="UTF-8"?>
            
            <deployment xmlns="urn:jboss:bean-deployer:2.0">
            
             <!--classloader>
             <bean name="cl" class="org.jboss.test.kernel.deployment.support.NullClassLoader" />
             </classloader-->
            
            
             <beanfactory name="InterceptedAdvice" class="org.jboss.test.kernel.deployment.test.CalledInterceptor"/>
            
             <bean name="appScopeObject" class="org.jboss.test.kernel.deployment.support.SimpleObjectWithBean">
             <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
             <!--classloader><inject bean="cll" /> </classloader-->
             </bean>
            
             <bean name="AspectManager" class="org.jboss.aop.AspectManager">
             <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
             <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment2")</annotation>
             <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
             </bean>
            
             <bean name="InterceptedAspect" class="org.jboss.aop.microcontainer.beans.Aspect">
             <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
             <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment2")</annotation>
             <property name="advice"><inject bean="InterceptedAdvice"/></property>
             <property name="manager"><inject bean="AspectManager"/></property>
             </bean>
            
             <bean name="InterceptedBinding" class="org.jboss.aop.microcontainer.beans.AspectBinding">
             <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
             <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment2")</annotation>
             <property name="pointcut">execution(* $instanceof{org.jboss.test.kernel.deployment.support.SimpleObjectWithBean}->*(..))</property>
             <property name="aspect"><inject bean="InterceptedAspect" property="definition"/></property>
             <property name="manager"><inject bean="AspectManager"/></property>
             </bean>
            
             <bean name="deploy1" class="org.jboss.test.kernel.deployment.support.SimpleObjectWithBean">
             <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
             <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment1")</annotation>
             <property name="simpleBean"><inject bean="simple"/></property>
             </bean>
            
             <bean name="deploy2" class="org.jboss.test.kernel.deployment.support.SimpleObjectWithBean">
             <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
             <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment2")</annotation>
             <property name="simpleBean"><inject bean="simple"/></property>
             </bean>
            
             <bean name="deploy3" class="org.jboss.test.kernel.deployment.support.SimpleObjectWithBean">
             <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
             <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment3")</annotation>
             <property name="simpleBean"><inject bean="simpleFromBoot"/></property>
             </bean>
            
             <bean name="deploy4" class="org.jboss.test.kernel.deployment.support.SimpleObjectWithBean">
             <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
             <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment4")</annotation>
             <property name="simpleBean"><inject bean="simpleFromApp"/></property>
             </bean>
            
             <bean name="simple" class="org.jboss.test.kernel.deployment.support.SimpleBeanImpl">
             <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
             <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment1")</annotation>
             <constructor>
             <parameter>deployment1</parameter>
             </constructor>
             </bean>
            
             <bean name="simple" class="org.jboss.test.kernel.deployment.support.SimpleBeanImpl">
             <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
             <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment2")</annotation>
             <constructor>
             <parameter>deployment2</parameter>
             </constructor>
             </bean>
            
             <bean name="simpleFromBoot" class="org.jboss.test.kernel.deployment.support.SimpleBeanImpl">
             <constructor>
             <parameter>fromBoot</parameter>
             </constructor>
             </bean>
            
             <bean name="simpleFromApp" class="org.jboss.test.kernel.deployment.support.SimpleBeanImpl">
             <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
             <constructor>
             <parameter>fromApp</parameter>
             </constructor>
             </bean>
            
            </deployment>
            

            But result for this..

            [ScopedKernelController] Still unresolved Instantiated:..{name=deploy1..idependOn=..name=deploy1 dependsOn=InterceptedAspect...
            [ScopedKernelController] Still unresolved Instantiated:..{name=deploy3..idependOn=..name=deploy3 dependsOn=InterceptedAspect...
            [ScopedKernelController] Still unresolved Instantiated:..{name=deploy4..idependOn=..name=deploy4 dependsOn=InterceptedAspect...


            deploy2 work for InterceptedAspect is right.
            why deploy1,3,4 dependsOn=InterceptedAspect ?

            thank

            • 18. Re: Scoped Kernels
              bkeh12

              Hi,kabir
              pls,see previously posts for Ales.

               <beanfactory name="InterceptedAdvice" class="org.jboss.test.kernel.deployment.test.CalledInterceptor"/>
              
               <bean name="appScopeObject" class="org.jboss.test.kernel.deployment.support.SimpleObjectWithBean">
               <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
               <!--classloader><inject bean="cll" /> </classloader-->
               </bean>
              
               <bean name="AspectManager" class="org.jboss.aop.AspectManager">
               <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
               <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment2")</annotation>
               <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
               </bean>
              
               <bean name="InterceptedAspect" class="org.jboss.aop.microcontainer.beans.Aspect">
               <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
               <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment2")</annotation>
               <property name="advice"><inject bean="InterceptedAdvice"/></property>
               <property name="manager"><inject bean="AspectManager"/></property>
               </bean>
              
               <bean name="InterceptedBinding" class="org.jboss.aop.microcontainer.beans.AspectBinding">
               <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
               <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment2")</annotation>
               <property name="pointcut">
               execution(* $instanceof{org.jboss.test.kernel.deployment.support.SimpleObjectWithBean}->*(..))
               </property>
               <property name="aspect"><inject bean="InterceptedAspect" property="definition"/></property>
               <property name="manager"><inject bean="AspectManager"/></property>
               </bean> ....

              result this ..

              [ScopedKernelController] Error installing to Start: name=InterceptedBinding state=Create
              org.jboss.aop.pointcut.ast.TokenMgrError: Lexical error at line 1, column 1. Encountered: "\n" (10), after : ""


              thank

              • 19. Re: Scoped Kernels
                alesj

                 

                "bkeh12" wrote:

                deploy2 work for InterceptedAspect is right.
                why deploy1,3,4 dependsOn=InterceptedAspect ?


                After the bean is described, we look for all managed aspects that apply to that bean, and we include their dependencies as dependencies of the bean.
                But this dependency builder has no notion of scopes, so deploy1(,3,4) also get dependency on InterceptedAspect.

                Will look into how pointcut can be applied to scopes as well.

                • 20. Re: Scoped Kernels
                  alesj

                  I've added simple scope + AOP test case to aop-int module:
                  - ScopingAopTestCase

                  It is currently failing - we need to add some notion of scope to aspect / pointcut definition when we have AspectBinding bean in some non-root scope.

                  • 21. Re: Scoped Kernels
                    kabirkhan

                    Workaround for

                    [ScopedKernelController] Error installing to Start: name=InterceptedBinding state=Create
                    org.jboss.aop.pointcut.ast.TokenMgrError: Lexical error at line 1, column 1. Encountered: "\n" (10), after : ""
                    

                    is
                    <property name="pointcut">execution(* $instanceof{org.jboss.test.kernel.deployment.support.SimpleObjectWithBean}->*(..))</property>
                    


                    • 22. Re: Scoped Kernels

                       

                      "alesj" wrote:
                      "alesj" wrote:

                      From previous problem (duplicate 'context') temp fix, I currently have Context's hashCode under WORK level to diff the contexts. What's the appropriate fix?


                       public ScopeKey getFullScope(KernelControllerContext context)
                       {
                       ScopeKey scope = ScopeKey.DEFAULT_SCOPE.clone();
                       scope.addScope(CommonLevels.INSTANCE, context.getName().toString());
                       BeanMetaData beanMetaData = context.getBeanMetaData();
                       if (beanMetaData != null)
                       {
                       String bean = beanMetaData.getBean();
                       if (bean != null)
                       scope.addScope(CommonLevels.CLASS, bean);
                       }
                       // todo - some other level
                       scope.addScope(CommonLevels.WORK, String.valueOf(context.hashCode()));
                       return scope;
                       }
                      


                      Otherwise I cannot differentiate between these two beans:
                       <bean name="simple" class="org.jboss.test.kernel.deployment.support.SimpleBeanImpl">
                       <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
                       <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment1")</annotation>
                       <constructor>
                       <parameter>deployment1</parameter>
                       </constructor>
                       </bean>
                      
                       <bean name="simple" class="org.jboss.test.kernel.deployment.support.SimpleBeanImpl">
                       <annotation>@org.jboss.metadata.plugins.scope.ApplicationScope("testApp")</annotation>
                       <annotation>@org.jboss.metadata.plugins.scope.DeploymentScope("deployment2")</annotation>
                       <constructor>
                       <parameter>deployment2</parameter>
                       </constructor>
                       </bean>
                      


                      That looks like a very dirty hack to me.

                      I'm beginning to think that if we are going to add one hack
                      (pretending mutating the name to avoid clashes) because
                      of another hack (moving the controller) then we are on the wrong
                      track.

                      In fact, what is really required to fix this problem is something we discussed a while ago
                      where the bean is given a UID (unique identifier) to store its internal state.

                      • 23. Re: Scoped Kernels

                        We really need to split off some of this discussion into other topics.
                        I already forked this discussion once because it was becoming too entangled
                        (see the original post on this thread).

                        Let's try to keep the discussions focused on one issue and use links
                        if there is some relation to other issues.

                        • 24. Re: Scoped Kernels
                          alesj

                           

                          "adrian@jboss.org" wrote:

                          In fact, what is really required to fix this problem is something we discussed a while ago
                          where the bean is given a UID (unique identifier) to store its internal state.

                          This means adding getUniqueName() on BeanMetaData?
                          Where all should it be applied?

                          I think we mentioned this with aliases and inner un-named beans.
                          Any other place?

                          • 25. Re: Scoped Kernels
                            bkeh12

                            Hi,kabir
                            if try this

                            <property name="pointcut">
                             execution(* $instanceof{org.jboss.test.kernel.deployment.support.SimpleObjectWithBean}->*(..))
                            </property>
                            


                            Why ast get "\n" ?
                            isn't property metadata "execution(* $instanceof{org.jboss.test.kernel.deployment.support.SimpleObjectWithBean}->*(..))" ?

                            thank

                            • 26. Re: Scoped Kernels

                               

                              "alesj" wrote:

                              I think we mentioned this with aliases and inner un-named beans.
                              Any other place?


                              I'm saying that even before then we (probably before you got involved)
                              discussed not using ControllerContext.getName() as the key to store the state
                              but use a ControllerContext.getId() which would be a system generated
                              unique id. See UUID in the common module.

                              It was discussed in the context of giving better error messages
                              when two deployments have the same name for a context.

                              Currently you get a failure upfront about trying to install a duplicate context
                              when you should get a summary at the end saying one (or maybe both?) is not installed
                              because it has a duplicate name.

                              It also supports the "anonymous" bean concept better since the name becomes
                              "optional". It is only used in the external api when somebody wants to do
                              give me a context by name (e.g. an explicit dependency injection).

                              But I think it is a bit too close to the JBoss5-beta2 release to do this
                              refactoring at the moment.
                              If you are going to do it, it would be better if it was on a branch in SVN.
                              This is probably also true of the scoping development in general?

                              • 27. Re: Scoped Kernels
                                alesj

                                 

                                "adrian@jboss.org" wrote:

                                But I think it is a bit too close to the JBoss5-beta2 release to do this
                                refactoring at the moment.
                                If you are going to do it, it would be better if it was on a branch in SVN.
                                This is probably also true of the scoping development in general?

                                Scott already updated MC_2.0-beta branch before I commited my latest changes.
                                Ok, but as you said, refactoring would change things quite a bit, and it would be hard to merge it once JBoss5-beta2 is out.
                                I'll wait, and do my OSGi work with current trunk.
                                Once JBoss5-beta2 is out (and I'm back from US :-), we can discuss this further.

                                1 2 Previous Next