Difference between revisions of "OSGi : Develop Simple Apps"

From CDOT Wiki
Jump to: navigation, search
 
(23 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Ecl_activities|type=OSGi|type-repo=osgi}}
+
{{Ecl_activities|type=OSGi|type-repo=osgi}}__NOTOC__
 
+
<h2>Bundels and Java Applications</h2>
 
# Check out the [https://guest:1673852@zenit.senecac.on.ca/svn/ecl500/Lectures/trunk/w11-osgi-simple-interface/ Service Interface]
 
# Check out the [https://guest:1673852@zenit.senecac.on.ca/svn/ecl500/Lectures/trunk/w11-osgi-simple-interface/ Service Interface]
 
# Check out the [https://guest:1673852@zenit.senecac.on.ca/svn/ecl500/Lectures/trunk/w11-osgi-simple-serviceprovider/ Service Provider]
 
# Check out the [https://guest:1673852@zenit.senecac.on.ca/svn/ecl500/Lectures/trunk/w11-osgi-simple-serviceprovider/ Service Provider]
 
# Check out the [https://guest:1673852@zenit.senecac.on.ca/svn/ecl500/Lectures/trunk/w11-osgi-simple-serviceconsumer/ Service Consumer]
 
# Check out the [https://guest:1673852@zenit.senecac.on.ca/svn/ecl500/Lectures/trunk/w11-osgi-simple-serviceconsumer/ Service Consumer]
 +
<h3>[[Steps for Building Applications from Bundels]]</h3>
  
<strong>Steps for Building Bundels</strong>
+
[[File:OSGi-DS.png|border|SOA in JVM|400px| ]]
 
 
<h4>1. Study the Interfaces</h4>
 
 
 
* [http://www.osgi.org/javadoc/r4v42/org/osgi/framework/Bundle.html Bundle]
 
* [http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleContext.html BundleContext]
 
* [http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleActivator.html BundleActivator]
 
 
 
<h4>2. Define the Bundle that provide the service (Provider Bundle)</h4>
 
<h5>2.1 Define the Java Interface that exposes the services</h5>
 
Let us suppose that you want to define a service that allows the user to find a book from the book isbn. Then the interface should look similare with this one:
 
<source lang="java">
 
package cs.ecl.osgi.simple.bookfinder;
 
 
 
public interface BookFinder {
 
Book findBook(int isbn) throws BookNotFoundException;
 
}
 
</source>
 
Define in the same bundle the classes that you need such as: Book and BookNotFoundException
 
<source lang="java">
 
package cs.ecl.osgi.simple.bookfinder;
 
 
 
public class Book {
 
private int isbn;
 
private String title;
 
 
public Book(int isbn, String title) {
 
super();
 
this.isbn = isbn;
 
this.title = title;
 
}
 
 
 
public String getTitle() {
 
return title;
 
}
 
 
 
public void setTitle(String title) {
 
this.title = title;
 
}
 
 
 
public int getIsbn() {
 
return isbn;
 
}
 
 
 
public void setIsbn(int isbn) {
 
this.isbn = isbn;
 
}
 
}
 
 
 
package cs.ecl.osgi.simple.bookfinder;
 
 
 
public class BookNotFoundException extends Exception {
 
private static final long serialVersionUID = -6184839510952070091L;
 
 
 
public BookNotFoundException() {
 
super();
 
}
 
 
 
public BookNotFoundException(String arg0) {
 
super(arg0);
 
}
 
}
 
</source>
 
 
 
  
Define in the MANIFEST.MF that cs.ecl.osgi.simple.bookfinder is the '''Exported-Package'''
+
<h2>Bundels and the Declarative Services</h2>
<source lang="xml">
+
# Check out the [https://guest:1673852@zenit.senecac.on.ca/svn/ecl500/Lectures/trunk/w11-osgi-simple-declarativeservice-consumer Declarative Service Consumer]
Manifest-Version: 1.0
+
# Check out the [https://guest:1673852@zenit.senecac.on.ca/svn/ecl500/Lectures/trunk/w11-osgi-simple-declarativeservice-provider Declarative Service Provider]
Bundle-ManifestVersion: 2
+
<h3>[[Steps for Building Declarative Services]]</h3>
Bundle-Name: Bookfinder
 
Bundle-SymbolicName: cs.ecl.osgi.simple.bookfinder
 
Bundle-Version: 1.0.0.qualifier
 
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 
Bundle-Vendor: Seneca College - Eclipse Course
 
Export-Package: cs.ecl.osgi.simple.bookfinder
 
</source>
 

Latest revision as of 23:56, 24 January 2011


OSGi Activities



Start the lab activities in the order defined below:

Bundels and Java Applications

  1. Check out the Service Interface
  2. Check out the Service Provider
  3. Check out the Service Consumer

Steps for Building Applications from Bundels

OSGi-DS.png

Bundels and the Declarative Services

  1. Check out the Declarative Service Consumer
  2. Check out the Declarative Service Provider

Steps for Building Declarative Services