SlideShare a Scribd company logo
OSGi Introduction Ly Minh Phuong – Social Team
Objective OSGi architecture overview Bundles Services Lifecycle Demo Q&A OSGi framework Motivation
Why OSGi? Java not support natively dynamic module system.(@2011) JAR dependences management is missing. No way to restrict using class in JAR file.
Why OSGi? Java not support natively dynamic module system.(@2011)
Why OSGi? JAR dependences management is missing. What happened when two jar file have duplicate packages and classes ? What happened when your classes only work with a library which version < 2.3.0 ? Can it be prevent in run time ? No way to restrict using class in JAR file. When writing a lib/component can we control what user can import or not ?
Why OSGi? Resolve in OSGi way.
What is OSGi OSGi alliance Open Service Gateway initiative Founded 1999 Specification first released in 2000 Newest version of specification is 4.3 (April 2011) Target: embedded, desktop, enterprise application. Widely adopted: Eclipse Equinox, Apache Felix, Glassfish, Knopflerfish, ProSyst, Hitachi SuperJ Engine, …
Basic architect
Bundle Bundle Basic deployment entity ( app, component, library) Version convention ( major.minor.micro.qualifier ) Specify the dependence, export package, activator Package like JAR file and added the bundle meta info Bundle-ManifestVersion: 2 Bundle-Name: Greeting Client Bundle-SymbolicName: org.foo.hello.client Bundle-Version: 1.2.1.SNAPSHOT
Bundle Lifecycle
Bundle dependency resolution  The framework prefer already resolved bundle If both are resolved the framework prefer highest matching version. If the version is equal it's prefer the older one.
Bundle Activator Bundle Activator Define by Bundle-Activator header Handle when bundle start/stop public final class Activator implements BundleActivator{ public void start( BundleContext bc ) throws Exception{ .... } public void stop( BundleContext bc ) throws Exception{ .... } }
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
Service Service Bundle can register/unregister service  using bundle activator. One service name can have multi provider Service can have properties to describe  the service info
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 );
Consuming a service  Programatically using bundleContext.getSerivce() ServiceReference bookStorageRef =  bc.getServiceReference(BookStorage.class.getName()); if(bookStorageRef != null){ bookStorage = (BookStorage) bc.getService(bookStorageRef); System.out.println(&quot;Got BookStorage Service&quot;); } Use Service Listener 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) { .... } }
Service consuming Use Service Tracker 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); ... } }
Problems about OSGi OSGi look great but tool and development process not widely public yet. Not every lib is bundle. Version management can be nightmare. Runtime dynamic can result untested situation.
DEMO
Q&A

More Related Content

PPT
Osgi Webinar
PPTX
Mulesoftmeetup4th july
PDF
OSGi-enabled Java EE Applications using GlassFish
PPTX
Introduction to-osgi
PDF
Distributed OSGi Demo Eclipsecon 2009
PPT
NNUG Certification Presentation
PDF
OSGi Blueprint Services
PDF
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
Osgi Webinar
Mulesoftmeetup4th july
OSGi-enabled Java EE Applications using GlassFish
Introduction to-osgi
Distributed OSGi Demo Eclipsecon 2009
NNUG Certification Presentation
OSGi Blueprint Services
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development

What's hot (16)

PDF
Introduction to OSGi (Tokyo JUG)
ODP
Frankenstein's IDE: NetBeans and OSGi
PPTX
Java Modularity with OSGi
PPTX
Servicemix4.5.0
PPT
IJTC ServiceMix 4
PDF
Distributed Services - OSGi 4.2 and possible future enhancements
PDF
From Distributed to Pervasive OSGi
ODP
Java Tech & Tools | OSGi Best Practices | Emily Jiang
PDF
JSP and struts programming
PDF
java servlet and servlet programming
PDF
JEE Programming - 01 Introduction
PDF
Integration & DSL
PPTX
Apache tomcat
PDF
Swift server-side-let swift2016
PDF
Faster & Greater Messaging System HornetQ zzz
PDF
Sling IDE Tooling @ adaptTo 2013
Introduction to OSGi (Tokyo JUG)
Frankenstein's IDE: NetBeans and OSGi
Java Modularity with OSGi
Servicemix4.5.0
IJTC ServiceMix 4
Distributed Services - OSGi 4.2 and possible future enhancements
From Distributed to Pervasive OSGi
Java Tech & Tools | OSGi Best Practices | Emily Jiang
JSP and struts programming
java servlet and servlet programming
JEE Programming - 01 Introduction
Integration & DSL
Apache tomcat
Swift server-side-let swift2016
Faster & Greater Messaging System HornetQ zzz
Sling IDE Tooling @ adaptTo 2013
Ad

Viewers also liked (11)

PPTX
Comunicacion no verbal
PPT
Web accessibility developers by Bao AN - eXo SEA
PDF
สรุปการอบรมหลักสูตรการพัฒนาทักษะการให้บริการที่ดี
PDF
สรุปการอบรมหลักสูตรการพัฒนาทักษะการให้บริการที่ดี
PPT
Xss.e xopresentation from eXo SEA
PDF
5 to año
PPT
eXo Presentation: Bonita by Nguyen Anh Vu
PPTX
Les transports en commun à Londres : L'Oyster Card
DOCX
MEET-BIS Vietnam TOR_ ES_2013
PPT
Mcf presentation by Hai NGUYEN-Portal team
PPT
Chromattic usage in eXo Social
Comunicacion no verbal
Web accessibility developers by Bao AN - eXo SEA
สรุปการอบรมหลักสูตรการพัฒนาทักษะการให้บริการที่ดี
สรุปการอบรมหลักสูตรการพัฒนาทักษะการให้บริการที่ดี
Xss.e xopresentation from eXo SEA
5 to año
eXo Presentation: Bonita by Nguyen Anh Vu
Les transports en commun à Londres : L'Oyster Card
MEET-BIS Vietnam TOR_ ES_2013
Mcf presentation by Hai NGUYEN-Portal team
Chromattic usage in eXo Social
Ad

Similar to Os gi introduction made by Ly MInh Phuong-SOC team (20)

KEY
OSGi in 5 minutes
PDF
Open Services Gateway Initiative (OSGI)
PPTX
Introduction to OSGi
PPTX
OSGi Training for Carbon Developers
PDF
OSGi bootcamp - part 1
PPT
Managing Change
PPTX
Getting modular with OSGI
PDF
Best Practices for Enterprise OSGi Applications - Emily Jiang
PDF
Modular Architectures using Micro Services
PDF
OSGi tech session
PDF
Eclipse_Building_Blocks
PPT
OSGi Overview TomTom DevDay May 2009
PPT
OSGi Enablement For Apache Tuscany
PPTX
PDF
Gwt and JSR 269's Pluggable Annotation Processing API
PDF
Moved to https://slidr.io/azzazzel/leveraging-osgi-to-create-extensible-plugi...
KEY
Beyond OSGi Software Architecture
PPT
Part 8 - Enforcing modularity of JasForge using OSGI and Futures Evolutions
PDF
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi in 5 minutes
Open Services Gateway Initiative (OSGI)
Introduction to OSGi
OSGi Training for Carbon Developers
OSGi bootcamp - part 1
Managing Change
Getting modular with OSGI
Best Practices for Enterprise OSGi Applications - Emily Jiang
Modular Architectures using Micro Services
OSGi tech session
Eclipse_Building_Blocks
OSGi Overview TomTom DevDay May 2009
OSGi Enablement For Apache Tuscany
Gwt and JSR 269's Pluggable Annotation Processing API
Moved to https://slidr.io/azzazzel/leveraging-osgi-to-create-extensible-plugi...
Beyond OSGi Software Architecture
Part 8 - Enforcing modularity of JasForge using OSGI and Futures Evolutions
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...

More from Thuy_Dang (7)

PPT
Scala - By Luu Thanh Thuy CWI team from eXo Platform SEA
PPT
Shell scripting - By Vu Duy Tu from eXo Platform SEA
PPT
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
PPT
Secure & authentication By Lai HIEU - eXo SEA
PPT
SEO presentation By Dang HA - ECM team
PPT
Lotus Collaboration by Le Thanh Quang in CT
PPT
Regular expression made by To Minh Hoang - Portal team
Scala - By Luu Thanh Thuy CWI team from eXo Platform SEA
Shell scripting - By Vu Duy Tu from eXo Platform SEA
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
Secure & authentication By Lai HIEU - eXo SEA
SEO presentation By Dang HA - ECM team
Lotus Collaboration by Le Thanh Quang in CT
Regular expression made by To Minh Hoang - Portal team

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
A Presentation on Artificial Intelligence
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Tartificialntelligence_presentation.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
The Rise and Fall of 3GPP – Time for a Sabbatical?
A Presentation on Artificial Intelligence
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
20250228 LYD VKU AI Blended-Learning.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Per capita expenditure prediction using model stacking based on satellite ima...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Big Data Technologies - Introduction.pptx
Unlocking AI with Model Context Protocol (MCP)
Mobile App Security Testing_ A Comprehensive Guide.pdf
Electronic commerce courselecture one. Pdf
Assigned Numbers - 2025 - Bluetooth® Document
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Tartificialntelligence_presentation.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Os gi introduction made by Ly MInh Phuong-SOC team

  • 1. OSGi Introduction Ly Minh Phuong – Social Team
  • 2. Objective OSGi architecture overview Bundles Services Lifecycle Demo Q&A OSGi framework Motivation
  • 3. Why OSGi? Java not support natively dynamic module system.(@2011) JAR dependences management is missing. No way to restrict using class in JAR file.
  • 4. Why OSGi? Java not support natively dynamic module system.(@2011)
  • 5. Why OSGi? JAR dependences management is missing. What happened when two jar file have duplicate packages and classes ? What happened when your classes only work with a library which version < 2.3.0 ? Can it be prevent in run time ? No way to restrict using class in JAR file. When writing a lib/component can we control what user can import or not ?
  • 6. Why OSGi? Resolve in OSGi way.
  • 7. What is OSGi OSGi alliance Open Service Gateway initiative Founded 1999 Specification first released in 2000 Newest version of specification is 4.3 (April 2011) Target: embedded, desktop, enterprise application. Widely adopted: Eclipse Equinox, Apache Felix, Glassfish, Knopflerfish, ProSyst, Hitachi SuperJ Engine, …
  • 9. Bundle Bundle Basic deployment entity ( app, component, library) Version convention ( major.minor.micro.qualifier ) Specify the dependence, export package, activator Package like JAR file and added the bundle meta info Bundle-ManifestVersion: 2 Bundle-Name: Greeting Client Bundle-SymbolicName: org.foo.hello.client Bundle-Version: 1.2.1.SNAPSHOT
  • 11. Bundle dependency resolution The framework prefer already resolved bundle If both are resolved the framework prefer highest matching version. If the version is equal it's prefer the older one.
  • 12. Bundle Activator Bundle Activator Define by Bundle-Activator header Handle when bundle start/stop 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 Service Bundle can register/unregister service using bundle activator. One service name can have multi provider Service can have properties to describe the service info
  • 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 Programatically using bundleContext.getSerivce() ServiceReference bookStorageRef = bc.getServiceReference(BookStorage.class.getName()); if(bookStorageRef != null){ bookStorage = (BookStorage) bc.getService(bookStorageRef); System.out.println(&quot;Got BookStorage Service&quot;); } Use Service Listener 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 Use Service Tracker 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 OSGi look great but tool and development process not widely public yet. Not every lib is bundle. Version management can be nightmare. Runtime dynamic can result untested situation.
  • 19. DEMO
  • 20. Q&A