I don't really understand your scenario below.  The service tracker will
return null if there are no service register which match your filter.  It
sounds like you have some start order dependencies which we like to avoid
in OSGi.  To me it sounds like you must have all your impl bundles be
started before starting your "main" bundle.  Instead of having your main
bundle call tracker.getService() immediately you should look into using a
ServiceTrackerCustomizer so your main bundle can be informed when a
particular service is available.  Then you can start using it.  Another
option is to use something like Declarative Services which can help
simplify the dynamics of OSGi services.

It sounds like you are using Equinox/Eclipse.  For the strange class loader
issues you describe I suggest you open a bug against Equinox->Framework and
attach a testcase to reproduce.

Tom




|------------>
| From:      |
|------------>
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
  |Daniel Dumitrescu <[email protected]>                              
                                                                     |
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| To:        |
|------------>
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
  |OSGi Developer Mail List <[email protected]>                            
                                                                     |
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Date:      |
|------------>
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
  |06/11/2009 06:52 AM                                                          
                                                                     |
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Subject:   |
|------------>
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
  |Re: [osgi-dev] Same interface implemented multiple times                     
                                                                     |
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|





Hi Mirko

As i promised, i'm back with some results after trying your suggestions.

To clarify from the start the problem, i paste here the short description
of my case: i have an API, something like javax.jms. and
my.package.myinterface packed in a separate bundle used by all satellite
bundles.

Also i use the ServiceTracker class to track the services life, like this:
in each satellite bundle, in the start(BundleContext) method, i put
something like:


MyInterface connection = new ASpecificImpl();
props.put("Name", context.getBundle().getSymbolicName());

ServiceRegistration sr = context.registerService(MyInterface.class.getName
(),
                connection, props);
 this.tracker = new ServiceTracker(context, sr.getReference(), null);
 this.tracker.open();


and from the main bundle i try to get an implementation something like:

        Filter filter = this.bundleContext.createFilter("(Name="+implName
+")");
        ServiceTracker tracker = new ServiceTracker(this.bundleContext,
filter, null);
        tracker.open();

       MyInterface object = (MyInterface)tracker.getService();

Now, from time to time i get null reference for a certain implementation
(although i manually install & start the bundles if these aren;t started, i
use Platform.getBundle(symbolicName) )

More over, i have seen that if an implementation is used for doing a job,
and another implementation is requested from ServiceTracker, then this
second one used the classpath from the first one (that's just weird !),
droping its onw jars & libs !

Also, i've searched over the net for a solution, and the only one it seems
to be

osgi.java.profile.bootdelegation=none.

Now, is this a common situation, that the classloader mixex their
classpath?

Regards,
Daniel_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

<<inline: graycol.gif>>

<<inline: ecblank.gif>>

_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to