I am really new on this one (OSGI), trying to do simple examples. I cant make lazy actication work. I know there a few Blueprint impl out there to resolve such issues, but before proceeding with one, I thought it would be good to learn a few basics.
Bundle DataService: Manifest-Version: 1.0 Bundle-Version: 1.0.0 Bundle-Name: DataService Bundle-ManifestVersion: 2 Bundle-Activator: DataService.Activator Import-Package: org.osgi.framework Bundle-SymbolicName: DataService Export-Package: DataService;version="1.0.0" Bundle-ActivationPolicy: lazy Bundle DataServiceClient: Manifest-Version: 1.0 Bundle-Version: 1.0.0 Bundle-Name: DataServiceClient Bundle-ManifestVersion: 2 Bundle-Activator: DataServiceClient.Activator Import-Package: org.osgi.framework, DataService;version="[1.0.0,1.0.0]" Bundle-SymbolicName: DataServiceClient
Ok I have changed my code, but still no luck.
Outer application, install bundles, starts framework and then only starts DataServiceClient bundle. No access to any bundle class.
File bundleDir = new File("./bundles/"); String[] bundleResources = bundleDir.list(); for(String bundleResourcePath : bundleResources) { File bundleResource = new File(bundleDir, bundleResourcePath); InputStream bs =new FileInputStream(bundleResource); mFramework.getBundleContext().installBundle(bundleResource.getName(), bs); } mFramework.start(); bl = mFramework.getBundleContext().getBundles(); for(Bundle b : bl) { if (b.getBundleId() != 0 && b.getSymbolicName().contains("DataServiceClient")) { b.start(); } }
Here is the start of DataServiceClient:
System.out.println("DataServiceClient Start"); IDataService service = new DummyService(); System.out.println(service.getData());
Here is the DummyService class in "DataService" bundle.
public class DummyService implements IDataService { @Override public String getData() { return "DummyService Data"; } }
Here is the start of "DataService" bundle:
System.out.println("DataService Start");
The output I am getting:
DataServiceClient Start DummyService Data
However I expect to see:
DataServiceClient Start DataService Start DummyService Data
a little quatation from http://www.osgi.org/Design/LazyStart
Lazy Activation
Lazy activation is a life cycle policy that mandates a bundle MUST be activated upon the first successful request to load a class from that bundle.
However since it doesnt work, i guess i completely misunderstand the concept of lazy activation or i am doing something wrong.
Unless I explicitly call start for DataService bundle, it seems it doesnt invoke Activator.start for DataService bundle. This is what I am not getting atm.
Thx for your time