Difference between revisions of "Teams Winter 2011/team1/OSGI/Implement the Service Consumer"

From CDOT Wiki
Jump to: navigation, search
 
(5 intermediate revisions by the same user not shown)
Line 22: Line 22:
 
6. You should have three bundles now: <br />
 
6. You should have three bundles now: <br />
 
[[Image: Consumer1.jpg | 300px ]]
 
[[Image: Consumer1.jpg | 300px ]]
 +
<br/>7. Open your consumer's '''Activator''' and get the servers's reference in it's start() method: <br/>
 +
<pre>
 +
public void start(BundleContext context) throws Exception {
 +
        Activator.context = context;
 +
       
 +
        ServiceReference reference = context
 +
                .getServiceReference(Ticketing.class.getName());
 +
        if (reference != null) {
 +
            tkg = (Ticketing) context.getService(reference);
 +
</pre>
 +
<br/>8. Add code for your GUI(get it from repository [https://ecl500_111a11:pmGN9329@zenit.senecac.on.ca/svn/ecl500_111rep1/Lab2/branches/Consumer/] ) and use this service functionalities in it. In order to use it(reference) create a static field in your GUI: <br/>
 +
<code>static Ticketing tkg;</code>
 +
<br/>9. Run your consumer. ''Right click -> Run as -> Run Configuration... -> OSGi Framework''. Select all three bundles and click Add Required bundles. Click ''OK''
 +
<br/>10. Now you can test your provider services:<br/>
 +
[[Image: Consumer2.jpg | 500px]]

Latest revision as of 16:28, 16 February 2011

3. Implement the Service Consumer

1. You need service interface and service provider bundles to run your consumer
2. Create a new Plug-in-Project Ticketing Consumer (File -> New -> Other -> Plug-in-Project)
3. Give it a distinctive name and accept all defaults for the next screens. Click Finish
4. Your project is created and MANIFEST file opens. Click on Dependences and add interface bundle
5. Check your manifest file:

 
Manifest-Version: 1.0 
Bundle-ManifestVersion: 2
Bundle-Name: Consumer
Bundle-SymbolicName: cs.ecl.osgi.lab.ticketing.consumer
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: cs.ecl.osgi.lab.ticketing.consumer.Activator
Bundle-Vendor: Team1
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Import-Package: cs.ecl.osgi.lab.ticketing,
org.osgi.framework;version="1.3.0"

6. You should have three bundles now:
Consumer1.jpg
7. Open your consumer's Activator and get the servers's reference in it's start() method:

 public void start(BundleContext context) throws Exception {
        Activator.context = context;
         
        ServiceReference reference = context
                .getServiceReference(Ticketing.class.getName());
        if (reference != null) {
            tkg = (Ticketing) context.getService(reference);


8. Add code for your GUI(get it from repository [1] ) and use this service functionalities in it. In order to use it(reference) create a static field in your GUI:
static Ticketing tkg;
9. Run your consumer. Right click -> Run as -> Run Configuration... -> OSGi Framework. Select all three bundles and click Add Required bundles. Click OK
10. Now you can test your provider services:
Consumer2.jpg