OSGi : Lab Example

From CDOT Wiki
Revision as of 21:17, 3 February 2011 by Jordan.anastasiade (talk | contribs) (First bundle)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Example of OSGi service system

Let us suppose that you were asked to implement a voting system as an OSGi service system.

The system should be generic enough so that it could be used for any election. Therefore you will not be using specific candidate names, as they can change for different elections.

As a proof of concept, you will be given three candidates and as the election takes place you have to print the number of votes for each candidate.

Design and implementation

1. Define the Bundle Service Interface

Create the bundle cs.ecl.osgi.voting_1.0.1.qualifier

1.1 Create the VotingSystem.java
package cs.ecl.osgi.voting;

public interface VotingSystem {
	int[] countVotesFor(String code);
}
1.2 Define the MANIFEST.MF for the bundle interface
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Voting System
Bundle-SymbolicName: cs.ecl.osgi.voting
Bundle-Version: 1.0.1.qualifier
Bundle-Vendor: Seneca College - Eclipse Course
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: cs.ecl.osgi.voting

Note: The bundle does not need an activator.