• Save
Osgi Democamp
Upcoming SlideShare
Loading in...5
×
 

Osgi Democamp

on

  • 2,444 views

Introduction to OSGi by Yanai Franchi

Introduction to OSGi by Yanai Franchi

Statistics

Views

Total Views
2,444
Views on SlideShare
2,406
Embed Views
38

Actions

Likes
9
Downloads
0
Comments
1

5 Embeds 38

http://www.tikalk.com 25
http://jisi.dreamblog.jp 6
http://www.slideshare.net 4
http://tikalk.tikalknowledge.com 2
http://66.249.89.132 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Osgi Democamp Osgi Democamp Presentation Transcript

    • Open Your Eyes To OSGi By : Yanai Franchi Chief Architect , Tikal Eclipse DemoCamps Galileo 2009/Tel Aviv
    • Agenda  Introduction – What is OSGi ? – What problems does it help us to solve ? – How does it work ?  OSGi programming model – Live Demo  OSGi in Enterprise Applications – Spring DM Copyright 2009 Tikal Knowledge, Ltd. | 2 |
    • OSG - what? Copyright 2009 Tikal Knowledge, Ltd. | 3 |
    • OSGi Acronym O = Open S = Services G = Gateway i = initiative Copyright 2009 Tikal Knowledge, Ltd. | 4 |
    • TM OSGi OSGi TM The Dynamic Module System For Java Copyright 2009 Tikal Knowledge, Ltd. | 5 |
    • Original OSGi Vision Copyright 2009 Tikal Knowledge, Ltd. | 6 |
    • Who's Doing It ?  Open source implementation » Equinox » Felix » Knoplerfish  Significant enterprise Java usage » Eclipse » IBM – WebSphere, Lotus » JonAS » BEA » Oracle » JBoss » SpringSource Copyright 2009 Tikal Knowledge, Ltd. | 7 |
    • Why Do We Need OSGi ? Copyright 2009 Tikal Knowledge, Ltd. | 8 |
    • The Humble JAR File Copyright 2009 Tikal Knowledge, Ltd. | 9 |
    • Typical Java Application Copyright 2009 Tikal Knowledge, Ltd. | 10 |
    • Copyright 2009 Tikal Knowledge, Ltd. | 11 |
    • Our Application Stack... Copyright 2009 Tikal Knowledge, Ltd. | 12 |
    • No Runtime Representation Copyright 2009 Tikal Knowledge, Ltd. | 13 |
    • Loading Classes... Copyright 2009 Tikal Knowledge, Ltd. | 14 |
    • ...The ClassLoader Found One Copyright 2009 Tikal Knowledge, Ltd. | 15 |
    • ...But I Need The Other Class :( Copyright 2009 Tikal Knowledge, Ltd. | 16 |
    • Copyright 2009 Tikal Knowledge, Ltd. | 17 |
    • Dependency Graph Copyright 2009 Tikal Knowledge, Ltd. | 18 |
    • Still Something Wrong  Classes can be tightly coupled  Even across module boundaries Copyright 2009 Tikal Knowledge, Ltd. | 19 |
    • Copyright 2009 Tikal Knowledge, Ltd. | 20 |
    • We Have a Problem... Copyright 2009 Tikal Knowledge, Ltd. | 21 |
    • ...A Big One... Copyright 2009 Tikal Knowledge, Ltd. | 22 |
    • ...It Crashed :( Copyright 2009 Tikal Knowledge, Ltd. | 23 |
    • Need to Decouple Copyright 2009 Tikal Knowledge, Ltd. | 24 |
    • Late Binding Copyright 2009 Tikal Knowledge, Ltd. | 25 |
    • Why Did Eclipse Adopt OSGi ? Copyright 2009 Tikal Knowledge, Ltd. | 26 |
    • Pre-OSGi Eclipse (<3.0) • Metadata in plugin.xml: • Meaningful Name, Vendor • Version • Dependencies • Private Internals • De-Coupling Framework (Extension Registry) Copyright 2009 Tikal Knowledge, Ltd. | 27 |
    • What Is Missing ??? Copyright 2009 Tikal Knowledge, Ltd. | 28 |
    • Copyright 2009 Tikal Knowledge, Ltd. | 29 |
    • Copyright 2009 Tikal Knowledge, Ltd. | 30 |
    • But in Eclipse... Copyright 2009 Tikal Knowledge, Ltd. | 31 |
    • A Little Open-Heart Surgery • Equinox project started February 2003 • Replace old Eclipse runtime with OSGi • Enhance OSGi standard • Eclipse 3.0 released June 2004 Copyright 2009 Tikal Knowledge, Ltd. | 32 |
    • OSGi Architectural Copyright 2009 Tikal Knowledge, Ltd. | 33 |
    • Bundle  By default a bundle is a black box » Completely protected » You can NOT see inside it • Not even by reflection • Or any other class loading trickery Copyright 2009 Tikal Knowledge, Ltd. | 34 |
    • How Does It Look Like ?  Its a jar file!  No complicated tools or sophisticated packaging required. META-INF/MANIFEST.MF Bundle-Name: Hello World Bundle-SymbolicName: com.tikal.osgi.sample.helloworld Bundle-Version: 2.1.0 Export-Package: com.tikal.osgi.sample Import-Package: com.tikal.osgi.weather ,org.osgi.framework Bundle-Activator: com.tikal.osgi.sample.HelloActivator Copyright 2009 Tikal Knowledge, Ltd. | 35 |
    • Bundle Visibility  Exposing Types can be done explicitly » A bundle can export one or more packages » Optionally with versioning information  Only exported packages are visibly outside of the exporting bundle. » Stops unintended coupling between bundles » Enable independent development » Faster development cycles Copyright 2009 Tikal Knowledge, Ltd. | 36 |
    • Bundle Visibility Cont. Service interface types exported with version information Export-Packages: a,b,c private packages “Passive” contribution Service Types added to type space implementation bundles see new version on locked away resolution after install/refresh Copyright 2009 Tikal Knowledge, Ltd. | 37 |
    • Bundle's Life Cycle– Dynamic ! Copyright 2009 Tikal Knowledge, Ltd. | 38 |
    • OSGi Wiring Copyright 2009 Tikal Knowledge, Ltd. | 39 |
    • OSGi Wiring Copyright 2009 Tikal Knowledge, Ltd. | 40 |
    • OSGi Wiring Copyright 2009 Tikal Knowledge, Ltd. | 41 |
    • Versioning MVC Service Repository ' Copyright 2009 Tikal Knowledge, Ltd. | 42 |
    • Versioning MVC Two versions of the same service type... at the same Service Service ' time! Repository ' Copyright 2009 Tikal Knowledge, Ltd. | 43 |
    • Versioning Copyright 2009 Tikal Knowledge, Ltd. | 44 |
    • Operational Control  See all bundles and their status » OSGi console » Web Console » JMX  Get information on wiring  Install new bundles  Activate/Deactivate bundles (and publish services)  Refresh bundles  Stop bundles  Uninstall bundles All without stop or restart the application Copyright 2009 Tikal Knowledge, Ltd. | 45 |
    • OSGi - Lessons Learned • Visibility • Versioning • Operational Control Copyright 2009 Tikal Knowledge, Ltd. | 46 |
    • OSGi Programming  All access to OSGi is through BundleContext  This is supplied to our BundleActivator Copyright 2009 Tikal Knowledge, Ltd. | 47 |
    • BundleActivator Bundle-Name: Hello World Bundle-SymbolicName: com.tikal.osgi.sample.helloworld Bundle-Activator: com.tikal.osgi.sample.HelloActivator public class HelloActivator implements BundleActivator { public void start(BundleContext context) throws Exception { System.out.println(“Hello, world!”); System.out.println(Arrays.asList(context.getBundles())); } public void stop(BundleContext context) throws Exception { System.out.println(“Goodbye, world!”); } } Copyright 2009 Tikal Knowledge, Ltd. | 48 |
    • Hello-World DEMO Copyright 2009 Tikal Knowledge, Ltd. | 49 |
    • Services in OSGi Copyright 2009 Tikal Knowledge, Ltd. | 50 |
    • SOA Architecture  The OSGi framework promotes a service-oriented interaction pattern among bundles Copyright 2009 Tikal Knowledge, Ltd. | 51 |
    • SOA For The JVM Published Services “Active” contribution Private Services published in implementation registry objects bundles see service changes immediately Copyright 2009 Tikal Knowledge, Ltd. | 52 |
    • SOA in OSGi Copyright 2009 Tikal Knowledge, Ltd. | 53 |
    • SOA in OSGi Copyright 2009 Tikal Knowledge, Ltd. | 54 |
    • SOA in OSGi Copyright 2009 Tikal Knowledge, Ltd. | 55 |
    • SOA in OSGi Copyright 2009 Tikal Knowledge, Ltd. | 56 |
    • SOA in OSGi Copyright 2009 Tikal Knowledge, Ltd. | 57 |
    • Example: Paint Program Copyright 2009 Tikal Knowledge, Ltd. | 58 |
    • Naive Class Diagram Copyright 2009 Tikal Knowledge, Ltd. | 59 |
    • Register Is Easy... Hashtable dict = new Hashtable(); dict.put(SimpleShape.NAME_PROPERTY, "Square"); dict.put(SimpleShape.ICON_PROPERTY, new ImageIcon(getClass().getResource("square.png"))); context.registerService(SimpleShape.class.getName(), new Square(),dict); Copyright 2009 Tikal Knowledge, Ltd. | 60 |
    • Consume Is ... Copyright 2009 Tikal Knowledge, Ltd. | 61 |
    • First Attempt ServiceReference ref = context.getServiceReference( SimpleShape.class.getName()); SimpleShape shape = (SimpleShape) context.getService(ref) shape.draw(); Copyright 2009 Tikal Knowledge, Ltd. | 62 |
    • Oops, “ref” can be Null ServiceReference ref = context.getServiceReference( SimpleShape.class.getName()); if(ref != null) { SimpleShape shape = (SimpleShape) context.getService(ref) shape.draw(); } Copyright 2009 Tikal Knowledge, Ltd. | 63 |
    • Oops, “shape” can be Null ServiceReference ref = context.getServiceReference( SimpleShape.class.getName()); if(ref != null) { SimpleShape shape = (SimpleShape) context.getService(ref); if(shape != null) shape.draw(); } Copyright 2009 Tikal Knowledge, Ltd. | 64 |
    • How ??? Copyright 2009 Tikal Knowledge, Ltd. | 65 |
    • Oops, Need to Clean Up ServiceReference ref = context.getServiceReference( SimpleShape.class.getName()); if(ref != null) { SimpleShape shape = (SimpleShape) context.getService(ref); if(shape != null){ try{ shape.draw(); }finally{ context.ungetService(ref); } } Copyright 2009 Tikal Knowledge, Ltd. | 66 |
    • Copyright 2009 Tikal Knowledge, Ltd. | 67 |
    • ServiceTracker  Shape Tracker goal – Use Inversion of Control principles to inject shapes into application » Created by the BundleActivator » Puts tracking logic in one place » Isolates application from OSGi API  User “Observer” design pattern to track services for clients. Copyright 2009 Tikal Knowledge, Ltd. | 68 |
    • Connecting The Dots Copyright 2009 Tikal Knowledge, Ltd. | 69 |
    • Connecting The Dots Copyright 2009 Tikal Knowledge, Ltd. | 70 |
    • Connecting The Dots Copyright 2009 Tikal Knowledge, Ltd. | 71 |
    • Shapes DEMO Copyright 2009 Tikal Knowledge, Ltd. | 72 |
    • Distributed OSGi... Its Here... Copyright 2009 Tikal Knowledge, Ltd. | 73 |
    • OSGi in ... Enterprise Applications Copyright 2009 Tikal Knowledge, Ltd. | 74 |
    • A Typical JEE Application D Web Application D Lib Lib Context D D Lib Lib D D Middle-tier Lib Context Lib Lib D Copyright 2009 Tikal Knowledge, Ltd. | 75 |
    • JEE Application Base on OSGi Each bundle is a segregated class space MVC MVC MVC Lib Lib Service Service Lib Domain Repository Repository Copyright 2009 Tikal Knowledge, Ltd. | 76 |
    • JEE Application on OSGi ?  How can we exploit OSGi » Without adding complexity ? » Retaining our programming model?  We want to treat bundles as beans » Instantiated, Configure, Assemble, Decorate » We want to easy way to publish/consume services • Dynamic management » Should we code this ourselves? » Preserve ability to test Copyright 2009 Tikal Knowledge, Ltd. | 77 |
    • Spring-DM Kernel  Integrates the simplicity and power of Spring... ...with the dynamic module system of OSGi – Use spring container to configure bundles – Make it easy to publish/subscribe services – Application can be coded with minimal OSGi code • Also easy test/integration-test POJO development on OSGi Copyright 2009 Tikal Knowledge, Ltd. | 78 |
    • Spring-DM Kernel Cont.  NO OSGi code & NO Spring code » No BundleActivator » No ServiceTracker » No Spring invasive code  A Spring application context based on OSGi bundle. » OsgiBundleApplicationContext  Enables UnitTest and Integration Test Copyright 2009 Tikal Knowledge, Ltd. | 79 |
    • Bring POJO to OSGi Services <bean name="bookDao" class="com....BookDaoImpl" /> <property name=”datasource” ref=”datasource”/> </bean> <osgi:service id="bookDaoOsgi" ref="bookDao" interface="com.tikal...BookDao" /> <bean name="bookService" class="com.tikal....BookServiceImpl"> <property name="bookDao"> <osgi:reference interface="com.tikal...BookDao" /> </property> </bean> Copyright 2009 Tikal Knowledge, Ltd. | 80 |
    • Spring dm Server Copyright 2009 Tikal Knowledge, Ltd. | 81 |
    • Copyright 2009 Tikal Knowledge, Ltd. | 82 |
    • Summary  OSGi is a dynamic module system for Java » Proven » Scalable (up and down)  OSGi Offer benefits in terms of » Modularity (visibility) » Versioning » Operational Control  Spring dm kernel/server combines the simplicity and power of Spring with sophistication of OSGi platform. Copyright 2009 Tikal Knowledge, Ltd. | 83 |
    • Q&A Copyright 2009 Tikal Knowledge, Ltd. | 84 |
    • Thank You yanai@tikalk.com Copyright 2009 Tikal Knowledge, Ltd. | 85 |