Difference between revisions of "Teams Winter 2011/team4/lab2"

From CDOT Wiki
Jump to: navigation, search
(Create the Service Interface)
 
(8 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
=Lab 2=
 
=Lab 2=
 
*[http://zenit.senecac.on.ca/wiki/index.php/Teams_Winter_2011/team4 Teampage]
 
*[http://zenit.senecac.on.ca/wiki/index.php/Teams_Winter_2011/team4 Teampage]
 
  
 
==Tutorial==
 
==Tutorial==
Line 24: Line 23:
  
 
==Implement the Service Provider==
 
==Implement the Service Provider==
===Register the service in the class Activator===
+
===Create the Provider Bundle===
 +
* Essentially, the strating steps to creating the service provider are almost identical to the starting steps of creating the service interface
 +
* The only difference here is after creating your plugin project (refer to previous steps for how-to) before clicking finish this time you '''MUST''' make sure generate an activator is checked, as we will need it this time.
 
===Define the MANIFEST.MF for the service provider bundle===
 
===Define the MANIFEST.MF for the service provider bundle===
 +
* By selecting generate activator, when Eclipse creates your plugin, it also creates an activator class which is used to handle the lifecycle of the plug-in and provides access to both the underlying OSGi system and the content of the plug-in.
 +
[[File:T4L2-6.png]]
 +
* In the previous step we exported our package for later use, it is now time to import this package.  To do so, click on your MANIFEST.MF file, select the dependencies tab, and under the the right heading Imported Packages, select the add button (refer to picture below)
 +
[[File:T4L2-7.png]]
 +
* Like before, enter the name of your package and select ok.
 
===Install and run the Service Provider Bundle===
 
===Install and run the Service Provider Bundle===
 +
* It is now time to run the service provider bundle we have created
 +
* Right click on your MANIFEST.MF and select Run As->Run Configuration
 +
* Now RIght click OSGi Framework and select New
 +
* Your workspace should now be populated with numerous options
 +
[[File:T4L2-8.png]]
 +
* Uncheck target platform (by default it is selected) then click Add required bundles, and then click the checkbox Only show selected
 +
* Your workspace should look similar to this:
 +
* Now click Run in the bottom right of your workspace, if everything went correctly, you will see a message saying '''osgi> TimeZones System Registered !'''
 
==Implement the Service Consumer==
 
==Implement the Service Consumer==
 
===Define the MANIFEST.MF for the service consumer bundle===
 
===Define the MANIFEST.MF for the service consumer bundle===
 +
*By selecting generate activator, when Eclipse creates your plugin, it also creates an activator class which is used to handle the lifecycle of the plug-in and provides access to both the underlying OSGi system and the content of the plug-in.
 +
*Select the dependencies tab, and under the the right heading Imported Packages, select the add button (refer to picture below)
 +
[[File:T4L2-9.png]]
 +
* Like before, enter the name of your package and select ok.
 
===Use the class Activator to find the service===
 
===Use the class Activator to find the service===
 +
*Open the '''Activator''' class in the consumer plug in project
 +
*Get the servers reference in the '''Activator's''' ''start()'' method, And provide code to start your consumer class.  Example code in the picture below.
 +
[[File:T4L2-10.png]]
 
===Implement a class where one can consume the service===
 
===Implement a class where one can consume the service===
 +
*Create your consumer class in the consumer project
 +
*Ensure that you create a static field in your consumer: ''static TimeZones tzs'' You will need this to use service provided
 +
[[File:T4L2-11.png]]
 +
 
===Install and run the Service Consumer Bundle===
 
===Install and run the Service Consumer Bundle===
 +
*Run your consumer project: ''Right click -> Run As -> OSGi Framework''. As with the provider select the 3 bundles in our project
 +
*Uncheck ''Target Platform''
 +
*Check ''Add Required Bundles''
 +
*Click ''Run!''
 +
[[File:T4L2-12.png]]
 +
*A sample of our code running, seamless updating of timezones!

Latest revision as of 16:14, 27 March 2011

Lab 2

Tutorial

Create the Service Interface

Define the service interface

  • First download Eclipse Classic from here

Create the Interface Bundle

  • We now need to create a new plugin project, to do so do the following: File->New->Plug-in Project
  • After selecting Plug-in Project from the options, give the Project a name according to the lab structure defined in the previous tutorial (cs.ecl.lab.<name here>

T4L2-1.png

  • After doing so, click next, where you will be presented with a screen that provides you with the project ID, version, name, ect. There will be an options section at the bottom of the window, be sure to unclick generate an activator, as it is not needed for the lab as the bundel is just interfaces and it is not run
  • You will now be presented with a screen that looks like the following:

T4L2-2.png

Creating the Interface

  • We will now add a package to the src folder of our project. Once you have done this you will add a class TimeZones and an Interface name Times to your package.
  • Enter code in both TimeZones and Times according to the following:

T4L2-3.png T4L2-5.png

  • If we want to use our package, we must export it in the interface bundle. First select MANIFEST.MF, then click on the runtime tab, and select "Add", then select your package. (Refer to Image below)

T4L2-4.png

  • Congratulations! You have successfully exported your package and we are ready to move onto step 2, implementing the Service Provider.

Implement the Service Provider

Create the Provider Bundle

  • Essentially, the strating steps to creating the service provider are almost identical to the starting steps of creating the service interface
  • The only difference here is after creating your plugin project (refer to previous steps for how-to) before clicking finish this time you MUST make sure generate an activator is checked, as we will need it this time.

Define the MANIFEST.MF for the service provider bundle

  • By selecting generate activator, when Eclipse creates your plugin, it also creates an activator class which is used to handle the lifecycle of the plug-in and provides access to both the underlying OSGi system and the content of the plug-in.

T4L2-6.png

  • In the previous step we exported our package for later use, it is now time to import this package. To do so, click on your MANIFEST.MF file, select the dependencies tab, and under the the right heading Imported Packages, select the add button (refer to picture below)

T4L2-7.png

  • Like before, enter the name of your package and select ok.

Install and run the Service Provider Bundle

  • It is now time to run the service provider bundle we have created
  • Right click on your MANIFEST.MF and select Run As->Run Configuration
  • Now RIght click OSGi Framework and select New
  • Your workspace should now be populated with numerous options

T4L2-8.png

  • Uncheck target platform (by default it is selected) then click Add required bundles, and then click the checkbox Only show selected
  • Your workspace should look similar to this:
  • Now click Run in the bottom right of your workspace, if everything went correctly, you will see a message saying osgi> TimeZones System Registered !

Implement the Service Consumer

Define the MANIFEST.MF for the service consumer bundle

  • By selecting generate activator, when Eclipse creates your plugin, it also creates an activator class which is used to handle the lifecycle of the plug-in and provides access to both the underlying OSGi system and the content of the plug-in.
  • Select the dependencies tab, and under the the right heading Imported Packages, select the add button (refer to picture below)

T4L2-9.png

  • Like before, enter the name of your package and select ok.

Use the class Activator to find the service

  • Open the Activator class in the consumer plug in project
  • Get the servers reference in the Activator's start() method, And provide code to start your consumer class. Example code in the picture below.

T4L2-10.png

Implement a class where one can consume the service

  • Create your consumer class in the consumer project
  • Ensure that you create a static field in your consumer: static TimeZones tzs You will need this to use service provided

T4L2-11.png

Install and run the Service Consumer Bundle

  • Run your consumer project: Right click -> Run As -> OSGi Framework. As with the provider select the 3 bundles in our project
  • Uncheck Target Platform
  • Check Add Required Bundles
  • Click Run!

T4L2-12.png

  • A sample of our code running, seamless updating of timezones!