Den 7. des. 2010 kl. 16:41 skrev Niclas Hedhman <[email protected]>:
> On Tue, Dec 7, 2010 at 8:46 PM, Paul Merlin <[email protected]> wrote: >> >> Le 7 déc. 2010 à 13:24, Ronnie Nessa <[email protected]> a écrit : >> >> How can you define the order services are activated in when you call the >> instantiateOnStartup method? > > I can't really see the usecase where you would need an ordered startup > without having the services dependent on each other, since if they > have injection of the depenendency, then Qi4j will ensure that the > injected service is activated before any methods are called... (Note > to myself; Does this means that instantiateOnStartup should actually > be called activatedOnStartup?? ) In my application I have a re-indexer service that under certain conditions reindexes the entire database when the application is started ( I think I borrowed some of the code from streamflow). Also I have a service that when activated conditionally bootstraps some initial data. My problem is that it is important that the re-indexer service runs before the bootstrap service, but as I see it they are not really dependent on each other, so making them dependent would be weird I think. Maybe I'm attacking this from the wrong angle though. Have any of you solved a similar problem in a different way? > >> From what I know, injection dependencies dictate the order of services >> activation. Simply because a service is activated before being injected into >> another. > > IIRC (Rickard can correct me), the ServiceReference is created at Qi4j > application activation and kept in each Module. When a service is > selected for injection by a direct service type reference, such as > > @Service > MyService instance; > > then the Composite is created, but the activate() (if any) is not > called until prior to first method invocation (unless > instantiateOnStartup() has been specified). > > If the ServiceReference is injected; > > @Service > ServiceReference<MyService> reference; > > then the service composite instance is not created until the > reference.get() method is called. > > For > @Service > Iterable<MyService> instances; > > injection style, I am guessing that the service composite instance is > not created until next() on the iterator is called > > and for > > @Service > Iterable<ServiceReference<MyService>> references; > > I would assume that the creation is happening on the > ServiceReference.get() method. > > Finally, > for ServiceFinder lookups, I think the general idea of "as late as > possible" holds true, unless the instantiateOnStartup() is specified. > This makes a lot of sense. Thanks for the explanation. > >> But I wonder how the activation order is computed for services appart from >> the dependencies point of view too. > > That order is "undefined" and may not remain constant over time, so > even if you can figure it out, it may change without notice. I think > all ServiceReferences will end up in a HashMap at some point, and then > iterated through to see which ones has the instantiateOnStartup() set. > > > _______________________________________________ qi4j-dev mailing list [email protected] http://lists.ops4j.org/mailman/listinfo/qi4j-dev

