Download presentation
Presentation is loading. Please wait.
Published byTodd Clark Modified over 9 years ago
1
OSGi & UPnP Technology 2009 Summer Ya-Lin Huang
2
2 Outline What is OSGi Technology Introduction Alliance Specifications Key Benefits OSGi Framework Service & Bundle Use Cases OSGi Implementation
3
3 What is OSGi Technology It’s a module system for the Java platform It’s dynamic It’s service-oriented A specification of the OSGi Alliance, a non-profit organization
4
4 Outline What is OSGi Technology Introduction Alliance Specifications Key Benefits OSGi Framework Service & Bundle Use Cases OSGi Implementation
5
5 Alliance OSGi - “Open Service Gateway Institute” The Alliance has been founded by Sun Microsystems, IBM, Ericsson and others in March 1999. Among its members are (as of April 2006) more than 35 companies from quite different business areas, for example Nokia, Motorola, Philips, BenQ, Siemens VDO Automotive, BMW, Gatespace Telematics, ProSyst, Samsung Electronics…
6
6 Specifications OSGi Release 1 (R1): May 2000 OSGi Release 2 (R2): October 2001 OSGi Release 3 (R3): March 2003 OSGi Release 4 (R4): October 2005 / September 2006 Core Specification (R4 Core): October 2005 Mobile Specification (R4 Mobile / JSR-232): September 2006 Latest release (R4.1 / JSR-291): May 2007
7
7 Specifications OSGi framework Standard service definitions Log Service Http Service Device Service Package Administration Service Permission Administration Service Configuration Administration Service Preferences Service User Administration Service
8
8
9
9 Key Benefits Platform Independence: OSGi member companies work in many different environments and as such they suffer different constraints, resulting in widely varying product characteristics and capabilities. Application Independence: The OSGi specifications focus on defining common APIs for service deployment. This makes the specifications suitable for Service Platforms for a variety of applications in different markets.
10
10 Key Benefits Multiple Service Support: OSGi environments should be capable of hosting multiple applications from different Service Providers on a single Service Platform with each application providing an independent set of services to the end user. Service Collaboration Support: An important aspect of the OSGi deployment model is that it allows the core platform to be extended with deployed services. This is not limited to end user oriented services only, which is a limitation of some other deployment models.
11
11 Key Benefits Multiple Network Technology Support: OSGi Service Platforms can work with wide area technologies like xDSL, Cable modems, Satellite, ISDN and PSTN and local area networks like Bluetooth, USB, IEEE 1394 Firewire. Popular service discovery techniques like UPnP, Jini, Salutation and several others work very well in conjunction with an OSGi Service Platform and can even potentially interwork transparently.
12
12 Key Benefits Security: The OSGi offers a fine grained security architecture that limits the potential harm a malicious or badly written application can do. Simplicity : The OSGi environment offers a service environment for everybody by removing much of the complexity and putting it into the hands of professionals. The environment can be remotely managed by a professional organization, if so desired.
13
13 Outline What is OSGi Technology Introduction Alliance Specifications Key Benefits OSGi Terminology OSGi Framework Service & Bundle Use Cases OSGi Implementation
14
14 OSGi Framework Services gateway Generic application framework Lightweight framework Simple component model Service registry Support for deployment
15
15 OSGi Platform Hardware Drivers e.g. Windows, Linux, VxWorks, QNX Operating System applicaion OSGi Framework System Services Multimedia BundlesHealth-Care Bundles e.g. J2ME, J2SE, J2EE Java Runtime Environment
16
16 OSGi Framework Hardware: the physical part of a computer. Operating System: a software program that manages the hardware and software resources of a computer. Java Runtime Environment: a software bundle from Sun Microsystems that allows a computer system to run a java application. Application: a subclass of computer software that employs the capabilities of a computer directly to a task that the user wishes to perform.
17
OSGi Framework The Framework is divided in a number of layers: Execution Environment Modules Life Cycle Management Service Registry. Additionally, there is a security system that is deeply intertwined with all the layers. 17
18
18 OSGi Framework Execution environment: the specification of the Java environment. Java 2 Configurations and Profiles. Modules: defines the class loading policies. The OSGi Framework is a powerful and strictly specified class loading model. It is based on top of Java but add modularization. Life Cycle Management: adds bundles that can be dynamically installed, started, stopped, updated, and uninstalled. Bundles rely on the module layer for class loading but add an API to manage the modules in run time.
19
19 OSGi Framework Service Registry: The service registry provides a cooperation model for bundles that takes the dynamics into account. The service registry provides a comprehensive model to share objects between bundles. A number of events are defined to handle the coming and going of services. Security is based on Java and the Java 2 security model.
20
20 OSGi Framework
21
21 Outline What is OSGi Technology Introduction Alliance Specifications Key Benefits OSGi Terminology OSGi Framework Service & Bundle Use Cases OSGi Implementation
22
22 Service & Bundle Services Provide applications Bundles (JAR file) Provide (export) and reuse (import) services via the framework Identify Java packages (classes) Implement specified interface (services) Register services with the Service Registry
23
23 Bundle Life Cycle
24
24 Bundle Acting Progress(1/3)
25
25 Bundle Acting Progress(2/3)
26
26 Bundle Acting Progress(3/3)
27
27 Outline What is OSGi Technology Introduction Alliance Specifications Key Benefits OSGi Terminology OSGi Framework Service & Bundle Use Cases OSGi Implementation
28
28 Typical Use Cases Internet Access Personal Communications Home Automation Home Security Home health care monitoring Entertainment Information management Automobiles
29
29 Typical Use Cases
30
30 Commercial Use Cases Nokia implements OSGi on 800 Ricoh Multi-functional Products (MFPs) laser printers BMW Research 3GT, Ertico GST Volvo Technology (VTEC) 3GT (Third Generation Telematics) GST (Global System for Telematics) CVIS (Cooperative Vehicle Infrastructure Systems) Philips iPronto
31
31 Outline What is OSGi Technology Introduction Alliance Specifications Key Benefits OSGi Terminology OSGi Framework Service & Bundle Use Cases OSGi Implementation
32
32 Framework Implementation IBM Lotus Expeditor ProSyst Software Knopflerfish OSGi Makewave (formerly Gatespace Telematics) Equinox OSGi (Eclipse project) Objectweb Oscar Apache Felix
33
Knopflerfish Installation (1) Software Environment JRE(Java Runtime Environment) Window XP Download Knopflerfish jar file http://www.knopflerfish.org/download.html Knopflerfish support OSGi R4 from 2.0.5 Download knopflerfish_osgi_.jar
34
Knopflerfish Installation (2) Install JRE Execute knopflerfish_osgi_.jar double-clicking on the distribution file use the command: java -jar knopflerfish_osgi_.jar Or just extract the JAR file
35
Startup Knopflerfish Change the directory to the installation directory and start Knopflerfish double-clicking on framework.jar use the command: java -jar framework.jar Eclipse plugin http://www.knopflerfish.o rg/eclipse_install.html Bundle Action Bundle State and Information Output Input
36
BUNDLE DEVELOPMENT 36
37
37 Bundle Activator(1/3) Activator Class (implements BundleActivator) start() This method implements what should the bundle do when it starts. The same as main() method in common Java program. stop() This method implements what should the bundle do when it is going to stop.
38
38 Bundle Activator(2/3) Simple implementation package ismp.smart.HelloOSGi; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { public void start(BundleContext context) throws Exception { System.out.println("HELLO!!"); } public void stop(BundleContext context) throws Exception { System.out.println("Byebye"); } package ismp.smart.HelloOSGi; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { public void start(BundleContext context) throws Exception { System.out.println("HELLO!!"); } public void stop(BundleContext context) throws Exception { System.out.println("Byebye"); }
39
39 Bundle Activator(3/3) MANIFEST file Manifest-Version: 1.0 Bundle-Vendor: ISMP Bundle-Version: 1.0.0 Bundle-Name: HelloOSGi Bundle-Activator: ismp.smart.HelloOSGi.Activator Bundle-Description: FirstBundle Import-Package: org.osgi.framework Bundle-SymbolicName: HelloOSGi Manifest-Version: 1.0 Bundle-Vendor: ISMP Bundle-Version: 1.0.0 Bundle-Name: HelloOSGi Bundle-Activator: ismp.smart.HelloOSGi.Activator Bundle-Description: FirstBundle Import-Package: org.osgi.framework Bundle-SymbolicName: HelloOSGi
40
MANIFEST header Header NameDescription Bundle-ActiovatorBundle’s Activator class Bundle-ClassPathBundle Class Path Bundle-ContactAddressBundle Developer’s E-mail Bundle-DescriptionBundle usage and function description Bundle-DocURLBundle Document Address Bundle-NameBundle Name. Display for user. Bundle-NativeCode Make it be able to use self-generated Native Code (JNI NativeCode) Bundle-UpdateLocationBundle Update Location Bundle-VendorVendor Name Bundle-VersionBundle Version Information Export-packageExport Package Export-ServiceExport Service Import-packageImport Package Import-ServiceImport Service 40
41
41 Service Export(1/4) Activator Class (implements BundleActivator) start() We have to implement a class and a service method for this class, and register this service in the start() method. BundleContext.registerService (java.lang.String class, java.lang.Object service, java.util.Dictionary properties) stop() Some services should be unregistered before the bundle stopped. ServiceRegistration.unregister()
42
Service Export(2/4) Service interface and implementation 42 package ismp.smart.helloOSGiServices; import java.util.Date; public interface FirstService { public String getFormattedDate(Date date); } package ismp.smart.helloOSGiServices; import java.util.Date; public interface FirstService { public String getFormattedDate(Date date); } package ismp.smart.helloOSGiServices.impl; import java.text.DateFormat; import java.util.Date; import ismp.smart.helloOSGiServices.FirstService; public class FirstServiceImpl implements FirstService { public String getFormattedDate(Date date) { return DateFormat.getDateInstance(DateFormat.SHORT).format (date); } package ismp.smart.helloOSGiServices.impl; import java.text.DateFormat; import java.util.Date; import ismp.smart.helloOSGiServices.FirstService; public class FirstServiceImpl implements FirstService { public String getFormattedDate(Date date) { return DateFormat.getDateInstance(DateFormat.SHORT).format (date); }
43
43 Service Export(3/4) Register Service package ismp.smart.helloOSGiServices.impl;... import ismp.smart.helloOSGiServices.FirstService; public class Activator implements BundleActivator { public static BundleContext bc = null; public void start(BundleContext bc) throws Exception {... Activator.bc = bc; FirstService service = new FirstServiceImpl(); ServiceRegistration registration = bc.registerService( FirstService.class.getName(), service, new Hashtable()); System.out.println("Service registered: FirstService"); }... } package ismp.smart.helloOSGiServices.impl;... import ismp.smart.helloOSGiServices.FirstService; public class Activator implements BundleActivator { public static BundleContext bc = null; public void start(BundleContext bc) throws Exception {... Activator.bc = bc; FirstService service = new FirstServiceImpl(); ServiceRegistration registration = bc.registerService( FirstService.class.getName(), service, new Hashtable()); System.out.println("Service registered: FirstService"); }... }
44
44 Service Export(4/4) Manifest file Manifest-Version: 1.0 Bundle-Vendor: ISMP Bundle-Version: 1.0.0 Bundle-Name: HelloOSGiServiceProvider Bundle-Activator: ismp.smart.helloOSGiServices.impl.Activator Bundle-Description: FirstBundleService Import-Package: org.osgi.framework Bundle-SymbolicName: HelloOSGiServiceProvider Export-Package: ismp.smart.helloOSGiServices Manifest-Version: 1.0 Bundle-Vendor: ISMP Bundle-Version: 1.0.0 Bundle-Name: HelloOSGiServiceProvider Bundle-Activator: ismp.smart.helloOSGiServices.impl.Activator Bundle-Description: FirstBundleService Import-Package: org.osgi.framework Bundle-SymbolicName: HelloOSGiServiceProvider Export-Package: ismp.smart.helloOSGiServices
45
45 Service Import(1/3) Dynamic binding services public void start(BundleContext bc) throws Exception { System.out.println("start " + getClass().getName()); Activator.bc = bc; String filter = "(objectclass=" + FirstService.class.getName() + ")"; bc.addServiceListener(this, filter); ServiceReference references[] = bc.getServiceReferences(null, filter); for (int i = 0; references != null && i < references.length; i++) { this.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED,references[i])); } public void start(BundleContext bc) throws Exception { System.out.println("start " + getClass().getName()); Activator.bc = bc; String filter = "(objectclass=" + FirstService.class.getName() + ")"; bc.addServiceListener(this, filter); ServiceReference references[] = bc.getServiceReferences(null, filter); for (int i = 0; references != null && i < references.length; i++) { this.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED,references[i])); }
46
Service Import(2/3) Must implemented method 46 public void serviceChanged(ServiceEvent event) { switch (event.getType()) { case ServiceEvent.REGISTERED: log("ServiceEvent.REGISTERED"); this.service = (FirstService)Activator.bc.getService( event.getServiceReference()); this.startUsingService(); break; case ServiceEvent.MODIFIED: log("ServiceEvent.MODIFIED received"); this.stopUsingService(); this.service = (FirstService) Activator.bc.getService( event.getServiceReference()); this.startUsingService(); break; case ServiceEvent.UNREGISTERING: log("ServiceEvent.UNREGISTERING"); this.stopUsingService(); break; } public void serviceChanged(ServiceEvent event) { switch (event.getType()) { case ServiceEvent.REGISTERED: log("ServiceEvent.REGISTERED"); this.service = (FirstService)Activator.bc.getService( event.getServiceReference()); this.startUsingService(); break; case ServiceEvent.MODIFIED: log("ServiceEvent.MODIFIED received"); this.stopUsingService(); this.service = (FirstService) Activator.bc.getService( event.getServiceReference()); this.startUsingService(); break; case ServiceEvent.UNREGISTERING: log("ServiceEvent.UNREGISTERING"); this.stopUsingService(); break; }
47
Service Import(3/3) Manifest file 47 Manifest-Version: 1.0 Bundle-Vendor: ISMP Bundle-Version: 1.0.0 Bundle-Name: HelloOSGiServiceClient Bundle-Activator: ismp.smart.helloOSGiServicesClient.impl.Activator Bundle-Description: FirstBundleServiceClient Import-Package: org.osgi.framework, ismp.smart.helloOSGiServicesClient Bundle-SymbolicName: HelloOSGiServiceClient Manifest-Version: 1.0 Bundle-Vendor: ISMP Bundle-Version: 1.0.0 Bundle-Name: HelloOSGiServiceClient Bundle-Activator: ismp.smart.helloOSGiServicesClient.impl.Activator Bundle-Description: FirstBundleServiceClient Import-Package: org.osgi.framework, ismp.smart.helloOSGiServicesClient Bundle-SymbolicName: HelloOSGiServiceClient
48
Export Jar Eclipse Export Install Bundle Drag and Drop or click “Bundle Action” buttons - [Open Bundle(s)] If all the dependencies are satisfied, the installed bundle will automatically start, or it will prompt error messages. Start Bundle Click “Bundle Action” buttons - [Start Bundle] Stop Bundle Click “Bundle Action” buttons - [Stop Bundle] Uninstall Bundle Click “Bundle Action” buttons - [Uninstall Bundle] 48
49
DEMO 49
50
Homework 50
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.