felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Offermans <marcel.offerm...@luminis.nl>
Subject Re: Contribution of the dependency manager to Feli
Date Sat, 28 Jan 2006 11:12:21 GMT
John E. Conlon wrote:

>If only one field is specified and if there are multiple services; and
>the services are dynamically coming and going how will the service
>referenced in the one field react?  
Let's use an example scenario here. Say we have an optional dependency 
with LogService (quite common) and that at first, there is no log 
service available. The field will then be initialized with a "null 
object" so you can safely invoke methods on this log service (but these 
methods will do nothing).

Now a log service is registered. At this moment, the instance field will 
be changed (using reflection). So from this point on, all methods you 
invoke on log service will actually invoke the freshly added log service.

Now another log service is registered with a higher ranking. Again, the 
instance field will be modified, rerouting all new calls to the higher 
ranked log service.

Now if that higher ranked log service is removed again, the instance 
will revert to the other, still registered log service. If that one is 
removed too, you will get a null object again.

For the example of a log service, this instance changing all the time 
will be just fine. Some log messages will be ignored, or written to the 
log service, depending on what's available at that time. The log service 
itself has no state or anything so bundles using it won't care as much 
about the implementation changing. In these cases, just using the 
instance field.

If you do care about changes, you can still use the instance field, but 
you should at least use the callback hooks too so you are notified and 
can act on changes to this field (of course, it might be a little more 
complicated then that, because you will also be notified when a lower 
ranked service is added and that will not change our instance field).

So really the bottom line is:
 - Use the instance field if you want to use the highest ranked service 
and you don't really care about changing services.
 - Use callback hooks if you do care about changes, in which case you 
can decide what to do yourself.

>(Thanks Marcel - your article is very well written.)

Greetings, Marcel

View raw message