Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different osgi bundles with implementations of the same interface - where to place that interface?

Tags:

osgi

I'm currently testing out osgi (Spring DM) on a new application. The application needs to be able to listen to file system events. Today I've solved this with a simple time based poller, but when Java 7 is released I probably want to replace that with a NIO2 based implementation.

So far I'm looking at three bundles, two for the file service implementations and one for the business logic consuming one of the services. The two implementations should implement the same interface so my question is, where to place that interface? Placing the interface in the bundle containing the implementation would cause the service to depend on one of its consumers.

What would be the best and most osgi-like way to structure this? So far my best bet is to create a new "api" bundle defining the common interfaces for the implementations.

like image 553
Kimble Avatar asked Dec 21 '09 11:12

Kimble


1 Answers

Separete api-bundle is probably the best choise. It allows you to replace bundle implentation later. Also with separate api-bundle you are able to hot-replace your current bundle with out the need for consumer to restart as well.

Classes (and interfaces) are recognized by their name and class loader. So if you place the service-interface in the same bundle as the implementation you lose the ability to hot-replace running bundle. Even though the interface has the same name, and it is identical in every sense newly deployed bundle has a different class loader => consumer considers the newly deployed bundles interface as a new class, and its dependencies are no longer met.

For more information on service compatibility and versions (see comments): http://wiki.osgi.org/wiki/Service_Compatibility

like image 124
Ahe Avatar answered Nov 07 '22 12:11

Ahe