Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » OSGi Bundle Dependency Question
OSGi Bundle Dependency Question [message #89503] Mon, 04 June 2007 15:16 Go to next message
Brett Humphreys is currently offline Brett HumphreysFriend
Messages: 17
Registered: July 2009
Junior Member
All,
I'm very new to OSGi but have been working with it in earnest over the
past three weeks. My question stems from section 3.5.6 in the R4 spec
where it states:

"Therefore, two bundles that both export the same package,
but do not import it, cannot share objects from that package. This is
very important for a collaboration mechanism like the Service Layer.
Bundles can only use the same service objects if their classes and
interfaces come from the same class loaders."


I had a very contrived example of two bundles:
Bundle A:
test.SimpleService
test.impl.SimpleServiceImpl
test.impl.Activator (Registered an instance of SimpleServiceImpl in
the service registry)
(Export-Package: test)
(Import-Package: org.osgi.framework)

Bundle B:
cmdtest.Activator (this was a simple CommandProvider used to trigger
method calls on the SimpleService, this was also a ServiceListener and
simply printed out service registrations)
(Import-Package: org.osgi.framework, test)



What I noticed was upon startup of Equinox Bundle A and Bundle B were
loaded, and Bundle B was able to find the SimpleService that was
registered and use the simple service. When I uninstalled bundle A,
Bundle B's activator did see the service unregister event. However when
I re-installed Bundle A (no recompile, no changes in the bundle at all),
bundle B's activator did not see the new SimpleService being registered.

Once I changed Bundle A to import the test package which it exported,
all worked fine. I could uninstall and reinstall Bundle A to my heart's
content and Bundle B's activator would always see the unregister and
register event.s

My question boils down to, why didn't Bundle B's Activator (the service
listener) see the services coming and going until Bundle A started
importing his own exports? I suspect this is a class loader issue where
there was two versions of the test.SimpleService interface loaded within
equinox, where Bundle B was using the original version and Bundle A was
now using a new version, but I didn't expect this to affect the service
listener interface. Is this the case or is something else going on?

Thanks.

Brett Humphreys
Senior Software Engineer
Applied Innovation Inc.
Re: OSGi Bundle Dependency Question [message #89646 is a reply to message #89503] Tue, 05 June 2007 13:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

I'm no expert, but I'd imagine that something in your Bundle B may have still held a reference to the classloader of (old)A, and you'd had (new)A. Although they're the same semantic package, they'd use different ClassLoaders, and as such, wouldn't be the same.

If you have a set of bundles that export 'test', but don't import them, then the binding occurs to only one of them. Slightly more concretely, imagine T1 and T2 that both export 'test', and 'X' that imports 'test'. It can only bind to T1.test or T2.test, even though they're the same package, because they may have incompatible classes; and one thing that OSGi does (but JSR277 hasn't got a clue about) is ensuring that the classpath is valid and no incompatible classpaths will be shown. (Which T gets bound is somewhat undefined, although it wouldn't surprise me if it was the first bundle by bundleid).

Anyhoo, to make this work for the T1/T2 test case, they both need to import 'test' as well as export 'test'. That way, T1 can see T2's classes (and vice versa), but more importantly, clients of that package (X) sees a unified package across the two.

In your case, you don't have T1 and T2, but you have T 1.0 and T 2.0, which are pretty much the same concept. What happened was your service binder was mapped to T 1.0, and when you installed T 2.0, it couldn't unify the package 'test' that was imported because of (e.g.) dangling references, so it hid the service notifications from you.

As soon as you imported as well as exported test, then there was only one package binding, so it could deliver both events to you.

At least, that's (a) my understanding, (b) I could be wrong, and (c) that's why this clause is in the spec.

Peter K's blogged about this:

http://www.osgi.org/blog/2007/04/importance-of-exporting-nd- importing.html

and I'm pretty sure I had too, but I couldn't find it ...

Alex.
Re: OSGi Bundle Dependency Question [message #89714 is a reply to message #89646] Tue, 05 June 2007 15:42 Go to previous messageGo to next message
Brett Humphreys is currently offline Brett HumphreysFriend
Messages: 17
Registered: July 2009
Junior Member
Alex,
Thanks for your insight. What you explained is the general conclusion I
came to as well, but wanted to make sure my understanding of the class
space was correct. I'm almost amazed that the service registry is so
sophisticated as to be able to notify or not notify based on appropriate
class loader availability. Very cool.

Thanks again for your help.

-Brett
Re: OSGi Bundle Dependency Question [message #89742 is a reply to message #89714] Tue, 05 June 2007 18:30 Go to previous message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

Yeah, and this is exactly the kind of issue that JSR277 is shuffling under the covers. Want to bet how well that will work?

Alex.
Previous Topic:Equinox in a servlet container and container dependencies
Next Topic:Dynamic Bundle Discovery from Equinox Embedded in a J2SE Application
Goto Forum:
  


Current Time: Thu Apr 25 11:02:59 GMT 2024

Powered by FUDForum. Page generated in 0.04614 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top