Tuesday, September 22, 2009

OSGi Demo app design

The application will consist of the following bundles (what are bundles?):
shared: This bundle exports the service interface for the proposed ComplexService.
http.handler: This bundle creates a HTTP handler that takes in an incoming request, finds the appropriate ComplexService, invokes it and returns the response. The bundle depends on the the service interface exported in the shared bundle.
complexapp: This bundle registers an implementation of the ComplexService with OSGi.
You also need external bundles that may be downloaded: (Look at OSGi HTTP Server)
javax:servlet:2.4 – Download from Eclipse Orbit – This provides the Java Servlets necessary to handle HTTP
org.eclipse.osgi:services:3.1.x – Download from Eclipse Equinox
org.eclipse.osgi:http:1.0.x – Download from Eclipse Equinox – These two provide the HTTP Server services
I will be using the Maven plugin (Felix plugin based on BND) to create the bundles I am writing. For example the POM file for shared is defined as (look at source for all):
<project ....>
  ....
  <groupId>com.irahul</groupId>
  <artifactId>shared</artifactId>
  <packaging>bundle</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>shared</name>
 
  <build>
   <plugins>
    <plugin>
     <groupId>org.apache.felix</groupId>
     <artifactId>maven-bundle-plugin</artifactId>
     <version>1.4.0</version>
      <extensions>true</extensions>
      <configuration>
       <instructions>
        <Export-Package>
         com.irahul.shared*,
         !*
        </Export-Package>
        <Private-Package>
         com.irahul.shared*
        </Private-Package>        
         </instructions>
      </configuration>
    </plugin>
 
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <configuration>
      <source>1.5</source>
      <target>1.5</target>
     </configuration>
    </plugin>
   </plugins>
  </build>
 
  <dependencies>
      ....
  </dependencies>
</project>
This results in a nicely created bundle with the MANIFEST.MF file like this:

Manifest-Version: 1.0
Export-Package: com.irahul.shared
Private-Package: com.irahul.shared*
Built-By: rahul
Tool: Bnd-0.0.238
Bundle-Name: shared
Created-By: Apache Maven Bundle Plugin
Bundle-Version: 1.0.0.SNAPSHOT
Build-Jdk: 1.6.0_16
Bnd-LastModified: 1253219746453
Bundle-ManifestVersion: 2
Import-Package: com.irahul.shared
Bundle-SymbolicName: com.irahul.shared
Correctly exported and imported packages are a key to resolving your bundles correctly in the OSGi container.
Next: Pure Java implementation

No comments: