Hi Jean-Philippe,

Thanks for all these info, a step further in blueprint understanding as a
day to day use: I was not aware of the single-injection when prototype
reference :).

I thought I tested the destroy-method reference and it didn't worked (I
retested now and its all ok!), maybe a code mistake.

Best regards,
Charlie

2014-11-04 18:47 GMT+01:00 CLEMENT Jean-Philippe <
[email protected]>:

> Hi Charlie,
>
>
>
> I don’t catch your problem. The bean you described will only call the
> factory once… to create the bean itself. So you may add a destroy method on
> it:
>
> [CODE]
>
> <bean id="myQueueListener" factory-ref="myManagedJmsListenerFactory"
> factory-method="create" *destroy-method=”stopIt”*>
>
> <argument name="queue" value="MY.QUEUE"/></bean>
>
> ​[/CODE]
>
> Same remark for prototypes. Prototypes *statically* creates beans, i.e.
> creates one bean per XML reference to it. However you can cheat and make
> your own factory based on the blueprint container and a bean prototype
> refid via:
>
>             BlueprintContainer.getComponentInstance(refid)
>
>
>
> But the best thing is to create your own factory. You can either keep
> trace of created beans or expose created beans as services and use the
> whiteboard pattern, for instance:
>
>             public interface StoppableService {
>
>                         void stopService();
>
> }
>
> …and having a reference-list to StoppableServices with a
> reference-listener calling StoppableService.stopService() on the
> unbind-method:
>
>             <bean id=”serviceStopper” class=”somepackage.ServiceStopper/>
>
>             <reference-list interface=”somepackage.StoppableService”
> availability=”optional”>
>
>                         <reference-listener ref=”serviceStopper”
> unbind-method=”stopIt”/>
>
>             </reference-list>
>
> with:
>
>             public final class ServiceStopper {
>
>                         public void stopIt(final StoppableService service)
> {
>
>                                    if (service!=null) { // Null means
> nothing to add, as per enterprise spec 121.7.12
>
>                                                service.stopService();
>
>                                    }
>
>                         }
>
> }
>
>
>
> JP
>
>
>
> [@@ OPEN @@]
>
>
>
> *De :* Charlie Mordant [mailto:[email protected]]
> *Envoyé :* mardi 4 novembre 2014 13:33
> *À :* [email protected]
> *Objet :* Calling a destroy method of a bean created by a factory
>
>
>
> ​​
>
> ​​
>
> Hi fish addicts community!
>
> I just didn't found a solution to my problem, so I'm asking to the experts
> (thank you in advance).
>
> I'm exposing a bean factory from a producer bundle (let say
> ManagedJmsListenerFactory).
>
> Then reference this factory in some consumer bundles creating my bean:
>
> [CODE]
>
> <bean id="myQueueListener" factory-ref="myManagedJmsListenerFactory"
> factory-method="create">
>
> <argument name="queue" value="MY.QUEUE"/></bean>
>
> ​[/CODE]
>
> ​Now, I've got to call a stop() method on all consumer-instanciated
> Listener when the consumer bundle stops (or calling stop on predestroy
> phase of the instanciated bean).
>
> I may have found a way:
> * Making the factory bean prototyped-scope.
> * Exposing the factory-bean service with a service registration listener
> keeping and index map of factory keys and created Listeners values
>
> * Calling stop on each map values when a factory is unregistered
>
>
>
> Is it feasible? Is there a better way (e.g. not duplicating factories)?
>
> Best regards, I love Apache, Aries and all that OSGI stuff.
>
>
>
> --
>
> Charlie Mordant
>
> Full OSGI/EE stack made with Karaf:
> https://github.com/OsgiliathEnterprise/net.osgiliath.parent
>



-- 
Charlie Mordant

Full OSGI/EE stack made with Karaf:
https://github.com/OsgiliathEnterprise/net.osgiliath.parent

Reply via email to