[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [equinox-dev] getting remote services from the registry
- From: Peter Kriens <Peter.Kriens@xxxxxxxxx>
- Date: Mon, 16 Oct 2006 09:32:56 +0200
- Delivered-to: email@example.com
- Organization: aQute
- Resent-date: Mon, 16 Oct 2006 03:33:00 -0400 (EDT)
- Resent-from: Peter Kriens <Peter.Kriens@xxxxxxxxx>
- Resent-message-id: <20061016073300.69F9044D211@mail.eclipse.org>
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
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.
>>>What would be a better way of handling this ?
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.
>>>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> 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> I hope this helps,
SJA> "Tom Huybrechts" <tom.huybrechts@xxxxxxxxx>
SJA> Sent by: equinox-dev-bounces@xxxxxxxxxxx
SJA> 10/14/2006 06:25 PM
SJA> Please respond to
SJA> Equinox development mailing list <equinox-dev@xxxxxxxxxxx>
SJA> "Equinox development mailing list" <equinox-dev@xxxxxxxxxxx>
SJA> [equinox-dev] getting remote services from the registry
SJA> Hi all,
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> 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> equinox-dev mailing list
Peter Kriens Tel +33467542167
9C, Avenue St. Drézéry AOL,Yahoo: pkriens
34160 Beaulieu, France ICQ 255570717
Skype pkriens Fax +1 8153772599