felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Imóveis Nacionais <imoveisnacion...@gmail.com>
Subject ServiceListener influenced by import directive: could someone confirm this?
Date Thu, 14 Feb 2013 16:50:31 GMT
Hi all, me again…


Suppose you have the following OSGi bundles and the related exposed
services:

BundleService1 -> exports service 1 and interface for service 1

BundleService2 -> exports service 2 and interface for service 2



Now I want to write the Bundle3 which will use both Service1 and Service2
(for now, just service1).

So, Bundle3 (activator class) implements BundleActivator  and
ServiceListener.

On start() I do: context.addServiceListener(this);

On the serviceChanged() method I simply have a print to console.

This works with no problem.

------------------------------------------------------------------------------------------------------------

Suppose now that you want to call service1 from serviceChanged method (just
an example!):

To call service1 I need to add dependence to pom.xml for BundleService1 in
order to get reference and cast the reference to the service1 interface.

Then, on the activator class I need to put an import for the service1
interface. Then I get the reference, evaluate the property, cast it to
service1 and call the service1.


Now, testing this stuff:

I install Bundle3 and start it.

I install BundleService1 and start it. Nothing happens on bundle3
serviceChanged!!!

Then I install BundleService2 and start it. The bundle3 serviceChanged is
called!!!


If I install and start any other bundles serviceChanged is always called,
except for BundleService1!

If I remove the import directive from Bundle3 (while the POM dependence
remains) and comment the related code, Bundle3 serviceChanged is called for
BundleService1!



My conclusion is that, the ServiceListener only works for those bundles
that have no “connection” (import) with Bundle3. Is this true?

If this is true, how can I get the reference and cast to the service in
order to call it without using imports?



Note: In an attempt to solve the problem I did the following: in the
serviceChanged I called another bundle3 class giving it the event in order
to remove the import from activator class, and move it to the other class.
But serviceChanged did not detects the Service1 too. It seems that if the
(client) bundle project has an import for some service bundles those
bundles are not “detected” in the serviceChanged method.



 Thank you

Alex

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message