8 Replies Latest reply on Oct 15, 2008 4:16 AM by alesj

    Way to control when injection happens?

    starksm64

      It turns out the clustering beans have a screwy relationship that is not working in general with the mc dependency injection:
      http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4181999

      The problem is that the HAPartitionCacheHandler relies on other beans to setup its properties, but does not express this relationship as a dependency because the other beans inject the HAPartitionCacheHandler so that they can call methods on it. In reality either these need to be rewritten, or a bean factory written that can wire these together correctly.

      The configuration that exists is:
      JBossCacheDistributedTreeManager injects HAPartitionCacheHandler.cache and depends on HAPartion and HAPartitionCacheHandler implicitly depends on HAPartition to initialize its cache.

      My question is can one delay injection of the HAPartitionCacheHandler.cache until the HAPartition bean is started?

        • 1. Re: Way to control when injection happens?
          alesj

           

          "scott.stark@jboss.org" wrote:

          My question is can one delay injection of the HAPartitionCacheHandler.cache until the HAPartition bean is started?

          You could add
          <demand state="Configured">HAPartition</demand>
          

          to
           <bean class="org.jboss.ha.jndi.impl.jbc.JBossCacheDistributedTreeManager">
           <property name="clusteredCache"><inject bean="HAPartitionCacheHandler" property="cache"/></property>
           </bean>
          

          which would halt injection until HAPartition is installed (instead of started).

          If you really need HAPartition at started state,
          I don't see how you can currently do that,
          but this can be easily fixed / hacked. :-)


          • 2. Re: Way to control when injection happens?
            starksm64

            That does work, but I don't understand why. Configured is an earlier state than Started or Installed (which I also tried, and this does not work for this demand). Why would a demand on Configured allow the HAPartition bean to move further than Started or Installed?

            • 3. Re: Way to control when injection happens?

               

              "scott.stark@jboss.org" wrote:
              That does work, but I don't understand why. Configured is an earlier state than Started or Installed (which I also tried, and this does not work for this demand). Why would a demand on Configured allow the HAPartition bean to move further than Started or Installed?


              I think you're misunderstand what it is doing. :-)

              The "state" is really "whenRequired"
               @XmlAttribute(name="state")
               public void setWhenRequired(ControllerState whenRequired)
               {
              


              So the above says that the HAPartition must be the Installed state
              before the JBossCacheDistributedTreeManager moves to the Configured state
              where it injects the HAPartitionCacheHandler.cache

              • 4. Re: Way to control when injection happens?
                starksm64

                Ok, that makes sense, thanks.

                • 5. Re: Way to control when injection happens?
                  starksm64

                  I added that to the mc FAQ (https://www.jboss.org/community/docs/DOC-10669) so the question now is the difference between depend and demand.

                  Looking at AbstractDemandMetaData and AbstractDependencyMetaData, a depend is a dependencyItem on the referenced bean reaching its Start state before the dependee will be allowed to reach its Start state.

                  Demand is a dependencyItem on the referenced bean reaching its Installed state before the dependee will be allowed to reach its whenRequired(state attribute of demand) state.

                  Correct? Is there a full generalization super-depend element, whenRequired=X, dependentState=Y? The AbstractDependencyItem class supports this information.

                  • 6. Re: Way to control when injection happens?

                     

                    "scott.stark@jboss.org" wrote:

                    Correct? Is there a full generalization super-depend element, whenRequired=X, dependentState=Y? The AbstractDependencyItem class supports this information.


                    Yes. There's no generic dependency in the xml, but some of the other
                    xml lets you set both, e.g. install
                    Programmatically, you can add whatever dependency you like.

                    There's a feature request somewhere to let you do:
                    <bean ...>
                     <dependencies>
                     <my-dependency1 xmlns="foo" .../>
                     <my-dependency2 xmlns="foo" .../>
                     </dependencies>
                    


                    i.e. write your own dependency like you can write your own "Requirement"
                    in the classloaders. :-)

                    • 7. Re: Way to control when injection happens?

                      It's here:
                      https://jira.jboss.org/jira/browse/JBMICROCONT-81
                      but Ales has closed it.

                      He's done it for annotations but not for xml.

                      Which maybe enough if you do?

                      <bean>
                       <annotation>@com.acme.MyDependency(...)</annotation>
                      


                      • 8. Re: Way to control when injection happens?
                        alesj

                         

                        "adrian@jboss.org" wrote:
                        It's here:
                        https://jira.jboss.org/jira/browse/JBMICROCONT-81
                        but Ales has closed it.

                        He's done it for annotations but not for xml.

                        Which maybe enough if you do?

                        Sure. ;-)

                        I've written two examples (they are commited to the trunk)
                        of what you can do to enable this:

                        (1) annotation based
                        <deployment xmlns="urn:jboss:bean-deployer:2.0">
                        
                         <bean name="AnnotationHandlerFactory">
                         <constructor factoryClass="org.jboss.kernel.plugins.annotations.BeanAnnotationAdapterFactory" factoryMethod="getInstance" />
                         </bean>
                         <bean name="AnnotationHandler">
                         <constructor factoryMethod="getBeanAnnotationAdapter">
                         <factory bean="AnnotationHandlerFactory"/>
                         </constructor>
                         <incallback method="addAnnotationPlugin" />
                         <uncallback method="removeAnnotationPlugin" />
                         </bean>
                         <bean name="SuperDemandAnnotationPlugin" class="org.jboss.test.kernel.deployment.support.SuperDemandAnnotationPlugin" />
                        
                         <bean name="Manager" class="org.jboss.test.kernel.deployment.support.SomeCacheTreeManager">
                         <property name="clusteredCache"><inject bean="HAPartitionCacheHandler" property="cache"/></property>
                         <annotation>@org.jboss.test.kernel.deployment.support.SuperDemand(demand="Partition", whenRequired="Configured", dependentState="Start")</annotation>
                         </bean>
                        
                         <bean name="HAPartitionCacheHandler" class="org.jboss.test.kernel.deployment.support.HAPartitionCacheHandler"/>
                        
                         <bean name="Partition" class="org.jboss.test.kernel.deployment.support.HAPartition">
                         <property name="handler"><inject bean="HAPartitionCacheHandler"/></property>
                         </bean>
                        
                        </deployment>
                        


                        (2) install
                        <deployment xmlns="urn:jboss:bean-deployer:2.0">
                        
                         <bean name="SuperDemand" class="org.jboss.test.kernel.deployment.support.SuperDemandCreator"/>
                        
                         <bean name="Manager" class="org.jboss.test.kernel.deployment.support.SomeCacheTreeManager">
                         <property name="clusteredCache"><inject bean="HAPartitionCacheHandler" property="cache"/></property>
                         <install bean="SuperDemand" method="createDependency" whenRequired="Instantiated">
                         <parameter><inject fromContext="name"/></parameter>
                         <parameter>Partition</parameter>
                         <parameter>Configured</parameter>
                         <parameter>Start</parameter>
                         </install>
                         </bean>
                        
                         <bean name="HAPartitionCacheHandler" class="org.jboss.test.kernel.deployment.support.HAPartitionCacheHandler"/>
                        
                         <bean name="Partition" class="org.jboss.test.kernel.deployment.support.HAPartition">
                         <property name="handler"><inject bean="HAPartitionCacheHandler"/></property>
                         </bean>
                        
                        </deployment>