-
1. Re: Way to control when injection happens?
alesj Oct 14, 2008 5:17 AM (in response to starksm64)"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 Oct 14, 2008 9:58 AM (in response to 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?
adrian.brock Oct 14, 2008 10:04 AM (in response to starksm64)"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 Oct 14, 2008 11:17 AM (in response to starksm64)Ok, that makes sense, thanks.
-
5. Re: Way to control when injection happens?
starksm64 Oct 14, 2008 12:15 PM (in response to 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?
adrian.brock Oct 14, 2008 12:26 PM (in response to starksm64)"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?
adrian.brock Oct 14, 2008 12:33 PM (in response to starksm64)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 Oct 15, 2008 4:16 AM (in response to starksm64)"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>