[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re[2]: [equinox-dev] getting remote services from the registry

It is -very- difficult to handle the events with ServiceListener
objects, except when you only care about changes. However, in my
experience you do not just want to get changes, you want to get an
overview.

If on time t1, you get an overview (getServiceReferences), and then on
time t2 you register the listener, you might have missed a few
registrations or unregistrations. If you do it reverse, you might have
received duplicate registrations/unregistrations. In both cases you
are likely to get hurt. Most people that use Service Listener objects
do not correctly handle this gap, actually, I have never seen it done
right in any of the code I have reviewed so far.

This problem is solved with the service tracker. You get a callback
for -each- service in the registry as well as the ones that come and
go. You therefore can treat existing services as well as dynamically
appearing services in the same way.

So I -strongly- suggest to use the ServiceTracker (or iPOJO,
declarative services, etc) to handle your service tracking needs.

Kind regards,

     Peter Kriens





SJA>  
SJA> Tom 
SJA>  
>>>What would be a better way of handling this ? 
SJA>  
SJA> Not quite sure what you mean here.  But you can certainly
SJA> register/unregister OSGi services dynamically in response to JNDI
SJA> service changes.  Alas I know little about JNDI, but I would
SJA> imagine that some form of event notification is available to
SJA> which you could subscribe.  Just use the OSGi BundleContext and
SJA> ServiceRegistration interfaces to register/unregister OSGi services.
SJA>  
>>>Ideally, I would like to just try to get a service from the registry, and have the framework (or some bundle) try to look it up through JNDI behind the scenes. 
SJA>  
SJA> Getting a service from the OSGi registry is a two step process.
SJA>  First you must get a ServiceReference to the service, then
SJA> de-reference the ServiceReference to get the service.  OSGi
SJA> offers at least two ways to track services: First there is the
SJA> ServiceListener/ServiceEvent approach where you register for
SJA> changes in the service registry (with an optional LDAP filter).
SJA>  Secondly there is the ServiceTracker, which is simply an
SJA> abstraction that  is supposed to make it easier to handle changes
SJA> in the service registry.  Frankly I prefer the
SJA> ServierListener/ServiceEvent approach, but I must confess that
SJA> this is partly due to my using it long before the ServiceTracker
SJA> was available.  So I suggest starting with the
SJA> ServiceListener/ServiceEvent approach. 
SJA>  
SJA> I hope this helps, 
SJA>  
SJA> Simon 
SJA>  
SJA>  
SJA>  
SJA>    "Tom Huybrechts" <tom.huybrechts@xxxxxxxxx>  
SJA> Sent by: equinox-dev-bounces@xxxxxxxxxxx 
SJA> 10/14/2006 06:25 PM 
SJA>    
SJA> Please respond to
SJA>  Equinox development mailing list <equinox-dev@xxxxxxxxxxx>
SJA>  
SJA>      
SJA> To
SJA>  "Equinox development mailing list" <equinox-dev@xxxxxxxxxxx>   
SJA> cc
SJA>     
SJA> Subject
SJA>  [equinox-dev] getting remote services from the registry 
SJA>      
SJA>  
SJA>  
SJA>  
SJA> Hi all,
SJA>  
SJA>  I'm working on an application that uses remote services which
SJA> are acquired using JNDI. I would like to hide the use of JNDI, by
SJA> exposing these services through the OSGi service registry. For
SJA> the moment, I'm doing this by asking for a list of services when
SJA> the platform starts, and registering service factories for all of
SJA> them. However this ignores the fact that remote services might
SJA> disappear or be added, which is one of the nice features o OSGi. 
SJA>  
SJA>  What would be a better way of handling this ? Ideally, I would
SJA> like to just try to get a service from the registry, and have the
SJA> framework (or some bundle) try to look it up through JNDI behind the scenes.
SJA>  
SJA>  Tom
SJA>  _______________________________________________
SJA>  equinox-dev mailing list
SJA>  equinox-dev@xxxxxxxxxxx
SJA>  https://dev.eclipse.org/mailman/listinfo/equinox-dev
SJA>   
SJA>  

-- 
Peter Kriens                              Tel +33467542167
9C, Avenue St. Drézéry                    AOL,Yahoo: pkriens
34160 Beaulieu, France                    ICQ 255570717
Skype pkriens                             Fax +1 8153772599