title: OSGI Bundle Lazy Activation
body: <p>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.</p>
  
  <pre>
  
      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
  
  </pre>
  
  <p>Ok I have changed my code, but still no luck.</p>
  
  <p>Outer application, install bundles, starts framework and then only starts DataServiceClient bundle.
  No access to any bundle class.</p>
  
  <pre>
  
      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();  
          }           
      }   
  
  
  </pre>
  
  <p>Here is the start of DataServiceClient: </p>
  
  <pre>
  
      System.out.println("DataServiceClient Start");
      IDataService  service = new DummyService();
      System.out.println(service.getData());
  
  
  
  </pre>
  
  <p>Here is the DummyService class in "DataService" bundle.</p>
  
  <pre>
  
      public class DummyService implements IDataService {
  
          @Override
          public String getData() {
              return "DummyService Data";
          }
      }
  
  </pre>
  
  <p>Here is the start of "DataService" bundle:</p>
  
  <pre>
      System.out.println("DataService Start");
  
  </pre>
  
  <p>The output I am getting:</p>
  
  <pre>
  
      DataServiceClient Start
      DummyService Data
  
  </pre>
  
  <p>However I expect to see:</p>
  
  <pre>
  
      DataServiceClient Start
      DataService Start
      DummyService Data
  
  </pre>
  
  <p>a little quatation from <a href="http://www.osgi.org/Design/LazyStart" rel="nofollow">http://www.osgi.org/Design/LazyStart</a></p>
  
  <p><strong>Lazy Activation</strong></p>
  
  <p><strong>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.</strong></p>
  
  <p>However since it doesnt work, i guess i completely misunderstand the concept of lazy activation or i am doing something wrong.</p>
  
  <p>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. </p>
  
  <p>Thx for your time</p>