getting started with the open services gateway initiative (osgi) cnt 5517 dr. sumi helal, ph.d....
TRANSCRIPT
![Page 1: Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bff31a28abf838cbc5a5/html5/thumbnails/1.jpg)
Getting Started with the Open Services Gateway
Initiative (OSGi)
CNT 5517
Dr. Sumi Helal, Ph.D.Professor
Computer & Information Science & Engineering Department
University of Florida, Gainesville, FL [email protected]
Most of this presentation was developed by Hen-I Yang
![Page 2: Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bff31a28abf838cbc5a5/html5/thumbnails/2.jpg)
Outline
• Introduction to OSGi
• Introduction to the Knopflerfish reference implementation
![Page 3: Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bff31a28abf838cbc5a5/html5/thumbnails/3.jpg)
OSGi ™ Platform
• A dynamic module system for Java™. – It provides the standardized primitives that allow applications to be
constructed from small, reusable and collaborative components. – Components can be composed into an application and deployed.
• Allow changing of the composition dynamically on the device of a variety of networks, without requiring restarts.
• A service-oriented architecture that decouples components, and enables these components to dynamically discover each other for collaboration.
• Many standard component interfaces for common functions like HTTP servers, configuration, logging, security, user administration, XML and many more are available and well-tested.
http://www.osgi.org/osgi_technology/index.asp?section=2
![Page 4: Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bff31a28abf838cbc5a5/html5/thumbnails/4.jpg)
OSGi ™ Platform
http://www.osgi.org/osgi_technology/index.asp?section=2
![Page 5: Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bff31a28abf838cbc5a5/html5/thumbnails/5.jpg)
OSGi Bundles• Bundles: Basic components in OSGi environment • Standard Bundle Composition:
– Manifest– Code
• Interface class– Methods that will be exposed to other bundles– Defines the visible external behavior of the bundle– Methods that would allow other bundles to invoke
• Activator class– Life cycle management– The class that gets invoked first when an bundle becomes active– Handles details such as a) The starting condition b) The cleanup actions c)
The plan of action when other bundles joins or leaves d) bind the local variables to instances of the bundles that would be used later
• Implementation class– The real deal: the actual implementation of the functionalities/methods
specified in the interface class– Actual usage of the variables specified and bound in the activator class– Where the real application logic is
![Page 6: Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bff31a28abf838cbc5a5/html5/thumbnails/6.jpg)
OSGi Bundles -- Interface
package demo.test;
import com.pervasa.atlas.dev.service.AtlasClient;
public interface Demo extends AtlasClient {
public void shutdown();}
![Page 7: Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bff31a28abf838cbc5a5/html5/thumbnails/7.jpg)
OSGi Bundles -- Activatorpublic class DemoActivator extends AtlasActivator { private DemoImpl service = null; public void start(BundleContext context) throws Exception { final String c[] = {Demo.class.getName()}; service = new DemoImpl(context, this); //Registering the Demo Service context.registerService(c, service, new Properties()); new Thread(service).start(); } public void stop(BundleContext context) throws Exception { service.shutdown(); } public void serviceChanged(ServiceEvent event) { ... }}
![Page 8: Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bff31a28abf838cbc5a5/html5/thumbnails/8.jpg)
OSGi Bundles -- Implementation
public class DemoImpl extends AtlasImpl implements Demo {protected InterlinkPressureSensor ps;protected LED led;protected HS322Servo servo;protected boolean running;
public void assignEntity(Object obj) { if (obj instanceof InterlinkPressureSensor) { this.ps = (InterlinkPressureSensor) obj; }else if (obj instanceof HS322Servo){ this.servo = (HS322Servo) obj; }else if (obj instanceof LED){ this.led = (LED) obj; }
} public void unassignEntity(Object obj) { … } public void ReceivedData(String arg0, Properties props) { // Real Application Logic Comes Here }
}
![Page 9: Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bff31a28abf838cbc5a5/html5/thumbnails/9.jpg)
OSGi Bundles – Manifest
Bundle-Name: DemoBundle-Activator: demo.test.impl.DemoActivatorDevice-Type: ApplicationImport-Package:
org.osgi.framework,com.pervasa.atlas.dev.service,org.sensorplatform.sensors.pressure,org.sensorplatform.actuators.servo.hs322
Bundle-Vendor: PervasaBundle-Author: PervasaBundle-SymbolicName: DemoBundle-Category: applicationBundle-Version: 1.0.0
![Page 10: Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bff31a28abf838cbc5a5/html5/thumbnails/10.jpg)
Download Knopflerfish
• Knopflerfish is an open source OSGi reference implementation
• The goal with the Knopflerfish project is to develop and distribute easy to use open source code, build tools and applications, related to the OSGi framework.
• http://www.knopflerfish.org/download.html– Download Knopflerfish 1.3.5– http://www.knopflerfish.org/releases/1.3.5/
knopflerfish_fullbin_osgi_1.3.5.jar– Self extracting and easy installation
![Page 11: Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bff31a28abf838cbc5a5/html5/thumbnails/11.jpg)
Exercise 2: Implementing an Application Bundle
• Work in groups of 2 – 3• Download the sample Atlas Application from:
http://www.cise.ufl.edu/~helal/classes/AtlasKitSampleApp.zip
• It is an Eclipse project so, use the File→Import option in the Eclipse IDE.
• Implement the Interface• Implement the Activator class• Implement the Implementation class• Try to compile and deploy the bundle to verify if
that it actually works!