tags:

views:

226

answers:

4

Do i need to supply a custom ClassLoader ? Thinking out loud this does not appear to be the right approach because inside the classloader one does not know the required version.

A: 

You could always download them from database (or whatever) into some local location and then install them dynamically into the OSGi Framework. All you need to give to the framework is the filesystem path of the bundle. Of course, you will have to write all the glue code for this yourself. On the other hand, if you are using Eclipse P2, you might have some more flexibility thanks to the automated provisioning.

omerkudat
That seems unelegant, i would rather skip the temporary dir thing and load the jars myself. I cannot however find a callback so the container will notify me when it needs to load a required dependency.
mP
+1  A: 

Have a look at the PAX URL project: http://wiki.ops4j.org/display/paxurl/Documentation

That demonstrates the separation of concerns of loading an OSGi bundle from how it is stored. In theory, I don't see any major impediment to using a database as the bundle store, though I also don't see any obvious advantages.

To your point on the bundle versions, you need some mechanism to identify which bundles (and versions) to load. You would store the bundles in the database with version information, otherwise how would you store different versions of the same bundle?

hbunny
Exactly how can i tell which bundles are required, there is no official callback that may be used to resolve bundle yourself.
mP
You don't need any callbacks. Think about it, how is an OSGi runtime bootstrapped? You need some mechanism to load the initial set of bundles. You don't say which OSGi container you are using, but if you dig around an Eclipse installation directory you'll find a config.ini file which does the bootstrapping.
hbunny
Even if i take a look at config.ini when in Equinox i then need to examine headers like required-bundles and import statements to figure out what bundles will be loaded. Its not really a callback that is invoked by the container when it attempts to load a bundle.
mP
No you don't. It's easy - Eclipse has a special bundle who's job is to load other bundles (actually, it has 2 of them). You'll have to bootstrap the OSGi runtime + your special loader bundle. How you do this depends on which OSGi runtime you are using. There are NO callbacks involved.
hbunny
+1  A: 

A simple solution is to create your own bootstrap bundle that will provision all other bundles from a database (or other location). OSGi allows you to install bundles from an arbitrary InputStream so it should be reasonably easy to plug this into whatever source you want (e.g. JDBC).

See BundleContext.installBundle() method for more details.

You should not be looking for a "callback" through which the framework would notify you "when it needs to load a required dependency" since automatic dependency management (ala Maven) is not part of the core OSGi functionality (although can be achieved by using services like OBR).

Pavol Juhos
Well i was hoping there would be a callback that was invoked everytime the system found a "import package" or "required bundle" header when it was loading a bundle.
mP
This is not easy, especially when you think about fragmented bundles etc. You might have a look at the Packacge Admin Service.
akr
A: 

Given that the loading mechanism essentially works with an URL, I would suggest to try a custom URL handler. Logically you will need to load and activate it before loading any bundles using this handler, otherwise I think it should work.

See the "URL Handlers Service Specification", R4 OSGi Core Specification.

Glassfish is using this approach to install webapp bundles btw.

Dieter