Changes

Jump to: navigation, search

Sudoku Generator (Example for the OSGi Lab)

2,623 bytes added, 19:49, 13 February 2011
Design and Implementation
}
</source>
 
<h6> 2.4 Define the MANIFEST.MF </h6>
 
<source lang="xml">
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Provider
Bundle-SymbolicName: ca.on.senecac.scs.sudoku.provider
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: ca.on.senecac.scs.sudoku.provider.SudokuActivator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: ca.on.senecac.scs.sudoku,
org.osgi.framework;version="1.3.0"
</source>
 
<h4> 3. Define the Service Consumer </h4>
 
Create the bundle ''ca.on.senecac.scs.sudoku.client''
 
<h6> 3.1 Create ClientActivator.java </h6>
 
<source lang="java">
package ca.on.senecac.scs.sudoku.client;
 
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
 
import ca.on.senecac.scs.sudoku.*;
 
/**
* Sudoku Generator client starts computing the Sudoku grid
* with a call to generate(0,0)
*
* @author John Selmys
*
*/
public class ClientActivator implements BundleActivator {
 
private static BundleContext context;
private SudokuGenerator sg;
static BundleContext getContext() {
return context;
}
 
public void start(BundleContext bundleContext) throws Exception {
ClientActivator.context = bundleContext;
ServiceReference reference = context
.getServiceReference(SudokuGenerator.class.getName());
if (reference != null) {
sg = (SudokuGenerator) context.getService(reference);
if (sg != null) {
sg.generate(0,0);
context.ungetService(reference);
} else
System.err.println("The Sudoku Generator cannot be used !!!");
} else
System.err.println("The Sudoku Generator cannot be found !!!");
}
 
public void stop(BundleContext bundleContext) throws Exception {
ClientActivator.context = null;
}
 
}
</source>
 
<h6> 3.2 Define the MANIFEST.MF </h6>
 
<source lang="xml">
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Client
Bundle-SymbolicName: ca.on.senecac.scs.sudoku.client
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: ca.on.senecac.scs.sudoku.client.ClientActivator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: ca.on.senecac.scs.sudoku,
org.osgi.framework;version="1.3.0"
</source>
 
<h4> 4. Configure the Sudoku Generator for running as an OSGi Implementation in the Eclipse Equinox container. Then run the application. </h4>
 
Note: In the console window you should see a valid Sudoku Puzzle printed out.
63
edits

Navigation menu