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?? )

> 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.


> 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.



Cheers
-- 
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I  live here; http://tinyurl.com/2qq9er
I  work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to