Your SlideShare is downloading. ×
0
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Os gi introduction made by Ly MInh Phuong-SOC team

728

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
728
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. OSGi Introduction Ly Minh Phuong – Social Team
  • 2. Objective <ul><li>OSGi architecture overview </li></ul><ul><ul><li>Bundles </li></ul></ul><ul><ul><li>Services </li></ul></ul><ul><ul><li>Lifecycle </li></ul></ul>Demo Q&A <ul><li>OSGi framework </li></ul><ul><ul><li>Motivation </li></ul></ul>
  • 3. Why OSGi? <ul><li>Java not support natively dynamic module system.(@2011) </li></ul><ul><li>JAR dependences management is missing. </li></ul><ul><li>No way to restrict using class in JAR file. </li></ul>
  • 4. Why OSGi? <ul><li>Java not support natively dynamic module system.(@2011) </li></ul>
  • 5. Why OSGi? <ul><li>JAR dependences management is missing. </li></ul><ul><ul><li>What happened when two jar file have duplicate packages and classes ? </li></ul></ul><ul><ul><li>What happened when your classes only work with a library which version < 2.3.0 ? </li></ul></ul><ul><ul><li>Can it be prevent in run time ? </li></ul></ul><ul><li>No way to restrict using class in JAR file. </li></ul><ul><ul><li>When writing a lib/component can we control what user can import or not ? </li></ul></ul>
  • 6. Why OSGi? <ul><li>Resolve in OSGi way. </li></ul>
  • 7. What is OSGi <ul><li>OSGi alliance </li></ul><ul><ul><li>Open Service Gateway initiative </li></ul></ul><ul><ul><ul><li>Founded 1999 </li></ul></ul></ul><ul><ul><ul><li>Specification first released in 2000 </li></ul></ul></ul><ul><ul><ul><li>Newest version of specification is 4.3 (April 2011) </li></ul></ul></ul><ul><ul><ul><li>Target: embedded, desktop, enterprise application. </li></ul></ul></ul><ul><ul><ul><li>Widely adopted: Eclipse Equinox, Apache Felix, Glassfish, Knopflerfish, ProSyst, Hitachi SuperJ Engine, … </li></ul></ul></ul>
  • 8. Basic architect
  • 9. Bundle <ul><li>Bundle </li></ul><ul><ul><li>Basic deployment entity ( app, component, library) </li></ul></ul><ul><ul><li>Version convention ( major.minor.micro.qualifier ) </li></ul></ul><ul><ul><li>Specify the dependence, export package, activator </li></ul></ul><ul><ul><li>Package like JAR file and added the bundle meta info </li></ul></ul>Bundle-ManifestVersion: 2 Bundle-Name: Greeting Client Bundle-SymbolicName: org.foo.hello.client Bundle-Version: 1.2.1.SNAPSHOT
  • 10. Bundle Lifecycle
  • 11. Bundle dependency resolution <ul><li>The framework prefer already resolved bundle </li></ul><ul><li>If both are resolved the framework prefer highest matching version. </li></ul><ul><li>If the version is equal it's prefer the older one. </li></ul>
  • 12. Bundle Activator <ul><li>Bundle Activator </li></ul><ul><ul><li>Define by Bundle-Activator header </li></ul></ul><ul><ul><li>Handle when bundle start/stop </li></ul></ul>public final class Activator implements BundleActivator{ public void start( BundleContext bc ) throws Exception{ .... } public void stop( BundleContext bc ) throws Exception{ .... } }
  • 13. Bundle Mainifest example Bundle-ManifestVersion: 2 Bundle-Name: Greeting Client Bundle-SymbolicName: org.foo.hello.client Bundle-Version: 1.2.1.SNAPSHOT Bundle-Activator : org.foo.hello.client.Activator Import-Package : org.foo.hello;version=&quot;[1.0,2.0)&quot; Export-Package : org.org.foo.hello.api;version=&quot;1.0&quot; Bundle-ClassPath : .,WEB-INF/classes,WEB-INF/lib/a.jar
  • 14. Service <ul><li>Service </li></ul><ul><ul><li>Bundle can register/unregister service using bundle activator. </li></ul></ul><ul><ul><li>One service name can have multi provider </li></ul></ul><ul><ul><li>Service can have properties to describe the service info </li></ul></ul>
  • 15. Registering a service Programmatically using Activator Dictionary properties = new Properties(); properties.setProperty(&quot;BookStorageType&quot;, &quot;MySQL&quot;); bundleContext.registerService(BookStorage.class.getName(), new BookStorageImpl(), properties );
  • 16. Consuming a service <ul><li>Programatically using bundleContext.getSerivce() </li></ul>ServiceReference bookStorageRef = bc.getServiceReference(BookStorage.class.getName()); if(bookStorageRef != null){ bookStorage = (BookStorage) bc.getService(bookStorageRef); System.out.println(&quot;Got BookStorage Service&quot;); } <ul><li>Use Service Listener </li></ul>Activator.java String filter = &quot;(&quot; + Constants.OBJECTCLASS + &quot;=&quot; + BookStorage.class.getName() + &quot;)&quot;; context.addServiceListener(new BookStorageListener(), filter); BookStorageListener.java class BookStorageListener implements ServiceListener { public void serviceChanged(ServiceEvent event) { .... } }
  • 17. Service consuming <ul><li>Use Service Tracker </li></ul>public class XyzServiceTracker extends ServiceTracker { public XyzServiceTracker(BundleContext context) { super(context, ServiceToTrack.class.getName(), null); ... } public Object addingService(ServiceReference reference) { ... } public void removedService(ServiceReference reference, Object service) { context.ungetService(reference); ... } }
  • 18. Problems about OSGi <ul><li>OSGi look great but tool and development process not widely public yet. </li></ul><ul><li>Not every lib is bundle. </li></ul><ul><li>Version management can be nightmare. </li></ul><ul><li>Runtime dynamic can result untested situation. </li></ul>
  • 19. DEMO
  • 20. Q&A

×