I have been trying to understand a strange OSGI behavior. Hoping someone can shed some light on it. Here is my setup
1) Using eclipse\plugins\org.eclipse.osgi_3.7.0.v20110613.jar
2) I have a Bundle that exports a service (HelloworldService)
It registers the service in the activator as such
public void start(BundleContext context) throws Exception { IHelloService helloService = new HelloServiceImpl(); helloServiceRegistration =context.registerService( IHelloService.class.getName(), helloService, null ); }
3) I have a 'consumer' bundle that uses the service via a ServiceTracker
ServiceReference externalServiceReference = Activator.getContext().getServiceReference(IHelloService.class.getName()); IHelloService externalService = (IHelloService) Activator.getContext().getService(externalServiceReference);
Now when I deploy both these jars to OSGI (helloworld.jar and helloworldservice.jar); it works fine. I am able to get a 'IHelloService' impl object and make calls on it. I can start/stop the bundles and when they come back; it works just fine
The problem happens when I 'uninstall' and then 'install' the HelloWorldservice bundle. In that case; the 'Helloworld' consumer externalServiceReference is NULL. If I view the bundle info; I see this
osgi> bundle 1 mypackage.helloworld_1.0.0.qualifier [1] Id=1, Status=RESOLVED Data Root=C:\Users\\dev\eclipse\plugins\configuration\org.eclipse.obundles\1\data No registered services. No services in use. No exported packages Imported packages mypackage.helloworldservice; version="0.0.0" **stale** org.osgi.framework; version="1.6.0" org.osgi.util.tracker; version="1.5.0" No fragment bundles Named class space mypackage.helloworld; bundle-version="1.0.0.qualifier"[provided] No required bundles
Notice that its 'imported packages' has GONE STALE. Here is the line in question
Imported packages mypackage.helloworldservice; version="0.0.0"<stale>
Now I can fix this by issuing an 'update' command from the console.
Here is my question
1) How do I programatically do this from within my 'consumer' bundle.. 2) If I am on a production system and I deploy a new 'copy' of the helloworlservice.jar (replacing the existing version); Do I have to update all its users.. I thought the ServiceTracker would give me the service on the fly
Thanks