Osgi Overview
Total Page:16
File Type:pdf, Size:1020Kb
OSGi Overview [email protected] [email protected] Apache Servicemix Commiter/PMC member Apache Cxf Commiter/PMC member Apache Karaf Commiter/PMC member Apache Felix Commiter Agenda . Why OSGi . What is OSGi . How OSGi Works . Apache projects related to OSGi 2 © 2009 Progress Software Corporation. All rights reserved. Why OSGi . modularity . more strict access control . classloader issues without OSGi . dynamic 3 © 2009 Progress Software Corporation. All rights reserved. Modularity 4 © 2009 Progress Software Corporation. All rights reserved. Java’s modularity limitations . poor code visibility control . error-prone classpath concept . rigid deployment and management support 5 © 2009 Progress Software Corporation. All rights reserved. poor code visibility control package mypackage.greeter; public interface Greeter { public void sayHi(String name); } package mypackage.greeter.impl; public class GreeterImpl implements Greeter { public void sayHi(String name) { System.out.println(“Hello ” + name); } } 6 © 2009 Progress Software Corporation. All rights reserved. Error-prone claspath concept 7 © 2009 Progress Software Corporation. All rights reserved. Rigid deployment and management support . can we hot replace a jar from classpath . can we hot redeploy a component from container . what’s the underlying classloader issue 8 © 2009 Progress Software Corporation. All rights reserved. How can OSGi help . early detection vs exception during runtime . great plugin component support 9 © 2009 Progress Software Corporation. All rights reserved. What is OSGi . Open Services Gateway Initivative . OSGi Alliance . SOA in JVM . Modularity layer for JAVA platform 10 © 2009 Progress Software Corporation. All rights reserved. How OSGi Works 11 © 2009 Progress Software Corporation. All rights reserved. Module Bundle . The term bundle is what OSGi uses to refer its specific realization of the module concept . What’s the definition of bundle? A physical unit of modularity in the form of a JAR file containing code, resources, and metadata, where the boundary of the JAR file also servers as the encapsulation boundary for logically modularity at execution time. What’s the differenec between bundle jar and normal jar? . How to create a bundle jar? . How to OSGi-fied a normal jar? 12 © 2009 Progress Software Corporation. All rights reserved. Define bundles with metadata . Human-readable information . Bundle identification . Code visibility 13 © 2009 Progress Software Corporation. All rights reserved. Human-readable information Bundle-Name: ServiceMix :: CXF Binding Component Bundle-Description: A CXF Binding Component Bundle-DocURL: http://www.apache.org/ Bundle-Category: JBI Component, Binding Component Bundle-Vendor: The Apache Software Foundation ... 14 © 2009 Progress Software Corporation. All rights reserved. Bundle identification Bundle-SymbolicName: servicemix-cxf-bc Bundle-Version: 2010.02.0.SNAPSHOT Bundle-ManifestVersion: 2 15 © 2009 Progress Software Corporation. All rights reserved. Code Visibility Bundle-Classpath: .,images/,embeded.jar Export-Package: ... Import-Package: ... 16 © 2009 Progress Software Corporation. All rights reserved. Class Search Order . If the class is from a package starting with “java.” . If the class is from a package imported by the bundle. The bundle class path is searched for the class. 17 © 2009 Progress Software Corporation. All rights reserved. Lifecycle 18 © 2009 Progress Software Corporation. All rights reserved. update/uninstall bundles . self-contained bundle . two steps operation 19 © 2009 Progress Software Corporation. All rights reserved. service 20 © 2009 Progress Software Corporation. All rights reserved. ServiceListener 21 © 2009 Progress Software Corporation. All rights reserved. ServiceTracker . dynamic way to use a service . multiple implementation services provider come/go on the fly . find some service which already be there before your bundle start 22 © 2009 Progress Software Corporation. All rights reserved. How to access OSGi Service . directly from bundleContext . reactively with service listener . indirectly using a ServiceTracker 23 © 2009 Progress Software Corporation. All rights reserved. framework services . core services • package admin service • start level service • url handlers service • permission admin serivce . compendium services • http service • event admin service • configuration admin service • user admin service 24 © 2009 Progress Software Corporation. All rights reserved. Best Practice in OSGi world . should my application depend on certain bundle start sequence . should I heavily use bundle-classpath in manifest . should I put multiple class copys in different bundles(even use private package) 25 © 2009 Progress Software Corporation. All rights reserved. Real OSGi Example . SPI discovery in JVM . Why it doesn’t work in OSGi Container . How to resolve this problem 26 © 2009 Progress Software Corporation. All rights reserved. Old days SPI way . Service Provider Interface . Implementation provider jar on classpath . FactoryProvider From API jar . Provider-Configuration File in implementaion provider jar (META-INF/services/javax.xml.soap.SOAPFactory) 27 © 2009 Progress Software Corporation. All rights reserved. Now for OSGi . Dynamic for multiple provider . API bundle shouldn’t bind to a specific impl . Doesn’t make sense to import impl package for API bundle . META-INF/services isn’t visible for API bundle 28 © 2009 Progress Software Corporation. All rights reserved. How SPI still works in OSGi . OSGILocator . BundleActivator 29 © 2009 Progress Software Corporation. All rights reserved. Apache projects related to OSGi . Apache Felix . Apache Karaf . Apache Servicemix . Apache aries . ... 30 © 2009 Progress Software Corporation. All rights reserved. Relationship between Felix/Karaf/Servicemix/Aries . Felix is the OSGi core runtime . Aries is OSGi 4.2 EE implematation . Karaf provides a distribution based on Felix with several key features out-of-box . Karaf start from Apache Servicemix Kernal . Servicemix4 is a set of sub-projects such as components/mavan-plugins/specs/bundles/nmr/ features, but all based on Karaf 31 © 2009 Progress Software Corporation. All rights reserved. Q&A . Thanks 32 © 2009 Progress Software Corporation. All rights reserved..