SlideShare ist ein Scribd-Unternehmen logo
1 von 32
GETTING MODULARWITH OSGI
Agenda
â€ș How to make my Java more modular
â€ș Discover and exploit OSGI
â€ș Tools, tools, tools

â€ș Output
About me
Who: Andrii Krokhmalnyi
Domain: Java/Java EE
Company: EPAM Systems
Experience in OSGI: about 2 years
Modular design
â€ș Separates functionality into distinct isolated sections (modules)
â€ș Defines a standard interface for modules
â€ș Adds ability to replace modules transparently for users of the system
â€ș Improves scalability and robustness of the system
â€ș Makes functional parts of the system reusable and easily updatable
â€ș 
But adds some extent of complexity in overall system orchestration
Modularity in Java: Service Provider Interface
META-INF/services/com.foo.logging.LogRenderer
com.foo.logging.impl.ConsoleLogRenderer
com.foo.service.MyService.java
public static void main(String[] args) {
ServiceLoader<LogRenderer> renderers =
ServiceLoader.load(LogRenderer.class);
for (LogRenderer renderer : renderers) {
...
}
Modularity in Java: OSGI
MANIFEST.MF
META-INF/MANIFEST.MF
Manifest-Version: 1.0
Bundle-SymbolicName: foo-service
Bundle-Activator: com.foo.service.Activator
Export-Package: com.foo.dao,com.foo.domain,com.foo.service
Import-Package: com.foo.logging;version="[2.0,3)"
image from http://wallpapersus.com/
Project Jigsaw
src/main/java/com/foo/service/module-info.java
module foo-service @ 1.2 {
requires jdk.base;
requires optional jdk.jaxp;
exports com.foo.bar;
permits foo-ui;
permits foo-console;
class com.foo.service.Main;
view dao {
exports com.foo.dao;
}
}
image from http://wallpapersgroup.net/
History & versioning
OSGI specification (version 4.3)
Framework Specification
FrameworkAPI
Start LevelAPI
Remote
Services
Bundle
WiringAPI
Additional
Services
Specifications
Security Layer
Module Layer
Life Cycle Layer
Service Layer
Core :: Container and bundles
image from http://www.osgi.org
OSGI Container
Class Loader #1
Bundle #1
Class Loader #2
Bundle #2
Class Loader #N
Bundle #N
(modules)
a regular jar archive with tweaked manifest
Core :: Bundles life-cycle
Core :: MANIFEST.MF headers
foo-service.jar/META-INF/MANIFEST.MF
...
Bundle-ManifestVersion: 2
Bundle-SymbolicName: com.foo.service
Bundle-Name: Foo Service
Bundle-Description: Foo Service Module
Bundle-Version: 1.0
Bundle-Activator: com.foo.service.BundleActivator
Require-Bundle: com.foo.logging
Export-Package: com.foo.domain,com.foo.dao,com.foo.service;uses:=“org.apache.log4j”
Import-Package: com.foo.logging;version=“[1.0,2)”,org.apache.log4j;version=“[2.0,3)”
DynamicImport-Package: *
...
Core :: MANIFEST.MF and Maven
pom.xml
<build><plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-Activator>com.foo.service.BundleActivator</Bundle-Activator>
<Export-Package>com.foo.service</Export-Package>
<Import-Package>
com.foo.domain,
com.foo.dao,
*
</Import-Package>
<DynamicImport-Package>*</DynamicImport-Package>
<Require-Bundle>org.apache.commons.io</Require-Bundle>
</instructions>
</configuration>
</plugin>
</plugins></build>
OSGI Services :: Service producer
ServiceProducerBundleActivator.java
public class ServiceProducerBundleActivator implements BundleActivator {
private ServiceRegistration registration;
public void start(BundleContext context) throws Exception {
registration = context.registerService(CustomService.class.getName(),
new CustomServiceImpl(), null);
}
public void stop(BundleContext context) throws Exception {
registration.unregister();
}
}
OSGI Services :: Service consumer
ServiceConsumerBundleActivator.java
public class ServiceConsumerBundleActivator implements BundleActivator {
public void start(BundleContext context) throws Exception {
ServiceReference ref =
context.getServiceReference(CustomService.class.getName());
CustomService customService = (CustomService) context.getService(ref);
customService.customMethod();
...
}
}
OSGI Services :: Spring version
/META-INF/spring/spring-osgi.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="..."
xmlns:osgi="http://www.springframework.org/schema/osgi" xsi:schemaLocation="...">
<osgi:service ref="customService" interface="com.foo.service.CustomService"/>
</beans>
Producer
/META-INF/spring/spring-osgi.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="..."
xmlns:osgi="http://www.springframework.org/schema/osgi" xsi:schemaLocation="...">
<osgi:reference id="customService" interface="com.foo.service.CustomService"/>
</beans>
Consumer
WhereWAR becomesWAB
foo-web.war/META-INF/MANIFEST.MF
...
Bundle-ManifestVersion: 2
Bundle-SymbolicName: com.foo.web
Bundle-Version: 1.0
Bundle-Activator: com.foo.web.BundleActivator
Web-ContextPath: mainapp/foo
Webapp-Context: mainapp/foo
Bundle-ClassPath: WEB-INF/classes,.
Import-Package: com.foo.service;version=“[1.0,2)”,
com.foo.logging;version=“[1.0,2)”;resolution:="optional"
...
Compendium services
Compendium
OSGI Services
Preferences UserAdmin Monitor Admin
Log HTTP
DeviceAccess
Configuration
Admin

 and many more
OSGI and unit testing
Spring
DM
MockBundle
MockBundleContext
MockServiceRegistrationMockServiceReference
MockBundleActivator
OSGI and integration testing
CustomServiceIntegrationTest.java
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class CustomServiceIntegrationTest {
@Inject
CustomService customService;
@Configuration
public Option[] config() {
return options(mavenBundle("com.foo", "foo-service", "1.0"), junitBundles());
}
}
BND
image from http://freemarket.kiev.ua/
Compiled
classes
Instruction
file
OSGI
bundle
OSGI containers/frameworks
Apache Felix
36%
Equinox
37%
SpringSource
dm Server
8%
Knopflerfish
8%
Concierge
8%
ProSyst
3%
OSGI CONTAINERS POPULARITY
(BYVOTES AT STACKOVERFLOW.COM)
Overview of Apache Felix
Apache License 2.0
OSGI R4.2 compatible
Provides a web console
Provides a Maven plugin
Active development
Proved solution
Good documentation
Overview of Apache Karaf
Apache License 2.0
Supports both Felix and Equinox
Lightweight and extensible
Interactive shell console
Hot deployment
Native OS integration
Extra management tools
Active development
OSGI in real world
Positives
Negatives
Getting modular with OSGI

Weitere Àhnliche Inhalte

Was ist angesagt? (9)

XOOPS 2.5.x Operations Guide
XOOPS 2.5.x Operations GuideXOOPS 2.5.x Operations Guide
XOOPS 2.5.x Operations Guide
 
Linux Desktop Automation
Linux Desktop AutomationLinux Desktop Automation
Linux Desktop Automation
 
Cocoon Blocks ApacheCon US 2005
Cocoon Blocks ApacheCon US 2005Cocoon Blocks ApacheCon US 2005
Cocoon Blocks ApacheCon US 2005
 
Linux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungLinux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesung
 
What's New in LuaRocks - Lua Workshop 2014 - Hisham Muhammad
What's New in LuaRocks - Lua Workshop 2014 - Hisham MuhammadWhat's New in LuaRocks - Lua Workshop 2014 - Hisham Muhammad
What's New in LuaRocks - Lua Workshop 2014 - Hisham Muhammad
 
Jsp Tutorial
Jsp TutorialJsp Tutorial
Jsp Tutorial
 
Using microsoft odbc and oracle gateway
Using microsoft odbc and oracle gatewayUsing microsoft odbc and oracle gateway
Using microsoft odbc and oracle gateway
 
Fosscon2013
Fosscon2013Fosscon2013
Fosscon2013
 
As7 web services - JUG Milan April 2012
As7 web services - JUG Milan April 2012As7 web services - JUG Milan April 2012
As7 web services - JUG Milan April 2012
 

Andere mochten auch (7)

OSGi Community Event 2010 - Modular Applications on a Data Grid - A Case Stud...
OSGi Community Event 2010 - Modular Applications on a Data Grid - A Case Stud...OSGi Community Event 2010 - Modular Applications on a Data Grid - A Case Stud...
OSGi Community Event 2010 - Modular Applications on a Data Grid - A Case Stud...
 
ĐžŃŃĐ»Đ”ĐŽĐŸĐČĐ°ĐœĐžĐ” ĐșĐŸŃ€ĐżĐŸŃ€Đ°Ń‚ĐžĐČĐœĐŸĐč ĐșŃƒĐ»ŃŒŃ‚ŃƒŃ€Ń‹ ĐșĐŸĐŒĐżĐ°ĐœĐžĐž бОлаĐčĐœ
ĐžŃŃĐ»Đ”ĐŽĐŸĐČĐ°ĐœĐžĐ” ĐșĐŸŃ€ĐżĐŸŃ€Đ°Ń‚ĐžĐČĐœĐŸĐč ĐșŃƒĐ»ŃŒŃ‚ŃƒŃ€Ń‹ ĐșĐŸĐŒĐżĐ°ĐœĐžĐž бОлаĐčĐœĐžŃŃĐ»Đ”ĐŽĐŸĐČĐ°ĐœĐžĐ” ĐșĐŸŃ€ĐżĐŸŃ€Đ°Ń‚ĐžĐČĐœĐŸĐč ĐșŃƒĐ»ŃŒŃ‚ŃƒŃ€Ń‹ ĐșĐŸĐŒĐżĐ°ĐœĐžĐž бОлаĐčĐœ
ĐžŃŃĐ»Đ”ĐŽĐŸĐČĐ°ĐœĐžĐ” ĐșĐŸŃ€ĐżĐŸŃ€Đ°Ń‚ĐžĐČĐœĐŸĐč ĐșŃƒĐ»ŃŒŃ‚ŃƒŃ€Ń‹ ĐșĐŸĐŒĐżĐ°ĐœĐžĐž бОлаĐčĐœ
 
ĐżŃ€ĐŸĐ”Đșт
ĐżŃ€ĐŸĐ”ĐșŃ‚ĐżŃ€ĐŸĐ”Đșт
ĐżŃ€ĐŸĐ”Đșт
 
Kui Mina Oleksin Matemaatikaopetaja
Kui Mina Oleksin MatemaatikaopetajaKui Mina Oleksin Matemaatikaopetaja
Kui Mina Oleksin Matemaatikaopetaja
 
De Veer Activitat2
De Veer Activitat2De Veer Activitat2
De Veer Activitat2
 
new acorn website
new acorn websitenew acorn website
new acorn website
 
OSGi & Java EE in GlassFish
OSGi & Java EE in GlassFishOSGi & Java EE in GlassFish
OSGi & Java EE in GlassFish
 

Ähnlich wie Getting modular with OSGI

Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC teamOs gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
Thuy_Dang
 
Travelling Light for the Long Haul - Ian Robinson
Travelling Light for the Long Haul -  Ian RobinsonTravelling Light for the Long Haul -  Ian Robinson
Travelling Light for the Long Haul - Ian Robinson
mfrancis
 
Travelling light for the long haul
Travelling light for the long haulTravelling light for the long haul
Travelling light for the long haul
Ian Robinson
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Martin Toshev
 
Better Enterprise Integration With the WSO2 ESB 4.5.1
Better Enterprise Integration With the WSO2 ESB 4.5.1Better Enterprise Integration With the WSO2 ESB 4.5.1
Better Enterprise Integration With the WSO2 ESB 4.5.1
WSO2
 
Managing Your Runtime With P2
Managing Your Runtime With P2Managing Your Runtime With P2
Managing Your Runtime With P2
Pascal Rapicault
 
Java Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily JiangJava Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily Jiang
JAX London
 
How to build a custom stack with WSO2 carbon
How to build a custom stack with WSO2 carbon How to build a custom stack with WSO2 carbon
How to build a custom stack with WSO2 carbon
WSO2
 
How to build a custom stack with wso2 carbon
How to build a custom stack with wso2 carbonHow to build a custom stack with wso2 carbon
How to build a custom stack with wso2 carbon
Shameera Rathnayaka
 
Osgi Webinar
Osgi WebinarOsgi Webinar
Osgi Webinar
WSO2
 
Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)
njbartlett
 

Ähnlich wie Getting modular with OSGI (20)

Modular Architectures using Micro Services
Modular Architectures using Micro ServicesModular Architectures using Micro Services
Modular Architectures using Micro Services
 
Os gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC teamOs gi introduction made by Ly MInh Phuong-SOC team
Os gi introduction made by Ly MInh Phuong-SOC team
 
Frankenstein's IDE: NetBeans and OSGi
Frankenstein's IDE: NetBeans and OSGiFrankenstein's IDE: NetBeans and OSGi
Frankenstein's IDE: NetBeans and OSGi
 
Travelling Light for the Long Haul - Ian Robinson
Travelling Light for the Long Haul -  Ian RobinsonTravelling Light for the Long Haul -  Ian Robinson
Travelling Light for the Long Haul - Ian Robinson
 
Travelling light for the long haul
Travelling light for the long haulTravelling light for the long haul
Travelling light for the long haul
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
 
Better Enterprise Integration With the WSO2 ESB 4.5.1
Better Enterprise Integration With the WSO2 ESB 4.5.1Better Enterprise Integration With the WSO2 ESB 4.5.1
Better Enterprise Integration With the WSO2 ESB 4.5.1
 
Managing Your Runtime With P2
Managing Your Runtime With P2Managing Your Runtime With P2
Managing Your Runtime With P2
 
Java Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily JiangJava Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily Jiang
 
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
 
How to build a custom stack with WSO2 carbon
How to build a custom stack with WSO2 carbon How to build a custom stack with WSO2 carbon
How to build a custom stack with WSO2 carbon
 
How to build a custom stack with wso2 carbon
How to build a custom stack with wso2 carbonHow to build a custom stack with wso2 carbon
How to build a custom stack with wso2 carbon
 
Osgi Webinar
Osgi WebinarOsgi Webinar
Osgi Webinar
 
Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)
 
L0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-inL0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-in
 
Enterprise service bus part 2
Enterprise service bus part 2Enterprise service bus part 2
Enterprise service bus part 2
 
Mageguru - magento custom module development
Mageguru -  magento custom module development Mageguru -  magento custom module development
Mageguru - magento custom module development
 
IJTC ServiceMix 4
IJTC   ServiceMix 4IJTC   ServiceMix 4
IJTC ServiceMix 4
 
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai..."Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
 
What's new in p2 (2009)?
What's new in p2 (2009)?What's new in p2 (2009)?
What's new in p2 (2009)?
 

KĂŒrzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

KĂŒrzlich hochgeladen (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Getting modular with OSGI

  • 2. Agenda â€ș How to make my Java more modular â€ș Discover and exploit OSGI â€ș Tools, tools, tools
 â€ș Output
  • 3. About me Who: Andrii Krokhmalnyi Domain: Java/Java EE Company: EPAM Systems Experience in OSGI: about 2 years
  • 4.
  • 5. Modular design â€ș Separates functionality into distinct isolated sections (modules) â€ș Defines a standard interface for modules â€ș Adds ability to replace modules transparently for users of the system â€ș Improves scalability and robustness of the system â€ș Makes functional parts of the system reusable and easily updatable â€ș 
But adds some extent of complexity in overall system orchestration
  • 6. Modularity in Java: Service Provider Interface META-INF/services/com.foo.logging.LogRenderer com.foo.logging.impl.ConsoleLogRenderer com.foo.service.MyService.java public static void main(String[] args) { ServiceLoader<LogRenderer> renderers = ServiceLoader.load(LogRenderer.class); for (LogRenderer renderer : renderers) { ... }
  • 7. Modularity in Java: OSGI MANIFEST.MF META-INF/MANIFEST.MF Manifest-Version: 1.0 Bundle-SymbolicName: foo-service Bundle-Activator: com.foo.service.Activator Export-Package: com.foo.dao,com.foo.domain,com.foo.service Import-Package: com.foo.logging;version="[2.0,3)" image from http://wallpapersus.com/
  • 8. Project Jigsaw src/main/java/com/foo/service/module-info.java module foo-service @ 1.2 { requires jdk.base; requires optional jdk.jaxp; exports com.foo.bar; permits foo-ui; permits foo-console; class com.foo.service.Main; view dao { exports com.foo.dao; } } image from http://wallpapersgroup.net/
  • 9.
  • 11. OSGI specification (version 4.3) Framework Specification FrameworkAPI Start LevelAPI Remote Services Bundle WiringAPI Additional Services Specifications Security Layer Module Layer Life Cycle Layer Service Layer
  • 12. Core :: Container and bundles image from http://www.osgi.org OSGI Container Class Loader #1 Bundle #1 Class Loader #2 Bundle #2 Class Loader #N Bundle #N (modules) a regular jar archive with tweaked manifest
  • 13. Core :: Bundles life-cycle
  • 14. Core :: MANIFEST.MF headers foo-service.jar/META-INF/MANIFEST.MF ... Bundle-ManifestVersion: 2 Bundle-SymbolicName: com.foo.service Bundle-Name: Foo Service Bundle-Description: Foo Service Module Bundle-Version: 1.0 Bundle-Activator: com.foo.service.BundleActivator Require-Bundle: com.foo.logging Export-Package: com.foo.domain,com.foo.dao,com.foo.service;uses:=“org.apache.log4j” Import-Package: com.foo.logging;version=“[1.0,2)”,org.apache.log4j;version=“[2.0,3)” DynamicImport-Package: * ...
  • 15. Core :: MANIFEST.MF and Maven pom.xml <build><plugins> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <configuration> <instructions> <Bundle-Activator>com.foo.service.BundleActivator</Bundle-Activator> <Export-Package>com.foo.service</Export-Package> <Import-Package> com.foo.domain, com.foo.dao, * </Import-Package> <DynamicImport-Package>*</DynamicImport-Package> <Require-Bundle>org.apache.commons.io</Require-Bundle> </instructions> </configuration> </plugin> </plugins></build>
  • 16. OSGI Services :: Service producer ServiceProducerBundleActivator.java public class ServiceProducerBundleActivator implements BundleActivator { private ServiceRegistration registration; public void start(BundleContext context) throws Exception { registration = context.registerService(CustomService.class.getName(), new CustomServiceImpl(), null); } public void stop(BundleContext context) throws Exception { registration.unregister(); } }
  • 17. OSGI Services :: Service consumer ServiceConsumerBundleActivator.java public class ServiceConsumerBundleActivator implements BundleActivator { public void start(BundleContext context) throws Exception { ServiceReference ref = context.getServiceReference(CustomService.class.getName()); CustomService customService = (CustomService) context.getService(ref); customService.customMethod(); ... } }
  • 18. OSGI Services :: Spring version /META-INF/spring/spring-osgi.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="..." xmlns:osgi="http://www.springframework.org/schema/osgi" xsi:schemaLocation="..."> <osgi:service ref="customService" interface="com.foo.service.CustomService"/> </beans> Producer /META-INF/spring/spring-osgi.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="..." xmlns:osgi="http://www.springframework.org/schema/osgi" xsi:schemaLocation="..."> <osgi:reference id="customService" interface="com.foo.service.CustomService"/> </beans> Consumer
  • 19. WhereWAR becomesWAB foo-web.war/META-INF/MANIFEST.MF ... Bundle-ManifestVersion: 2 Bundle-SymbolicName: com.foo.web Bundle-Version: 1.0 Bundle-Activator: com.foo.web.BundleActivator Web-ContextPath: mainapp/foo Webapp-Context: mainapp/foo Bundle-ClassPath: WEB-INF/classes,. Import-Package: com.foo.service;version=“[1.0,2)”, com.foo.logging;version=“[1.0,2)”;resolution:="optional" ...
  • 20. Compendium services Compendium OSGI Services Preferences UserAdmin Monitor Admin Log HTTP DeviceAccess Configuration Admin 
 and many more
  • 21. OSGI and unit testing Spring DM MockBundle MockBundleContext MockServiceRegistrationMockServiceReference MockBundleActivator
  • 22. OSGI and integration testing CustomServiceIntegrationTest.java @RunWith(PaxExam.class) @ExamReactorStrategy(PerMethod.class) public class CustomServiceIntegrationTest { @Inject CustomService customService; @Configuration public Option[] config() { return options(mavenBundle("com.foo", "foo-service", "1.0"), junitBundles()); } }
  • 23.
  • 25. OSGI containers/frameworks Apache Felix 36% Equinox 37% SpringSource dm Server 8% Knopflerfish 8% Concierge 8% ProSyst 3% OSGI CONTAINERS POPULARITY (BYVOTES AT STACKOVERFLOW.COM)
  • 26. Overview of Apache Felix Apache License 2.0 OSGI R4.2 compatible Provides a web console Provides a Maven plugin Active development Proved solution Good documentation
  • 27. Overview of Apache Karaf Apache License 2.0 Supports both Felix and Equinox Lightweight and extensible Interactive shell console Hot deployment Native OS integration Extra management tools Active development
  • 28. OSGI in real world
  • 29.

Hinweis der Redaktion

  1. permits = friendly modules list (current module is accessible only for those)class = entry class
  2. Framework API:org.osgi.framework packageBundle Wiring API: for wiring bundles (requirements and capabilities), classes BundleRevision, BundleWiring, FrameworkWiringStart Level API:describes how to enable a management agent to control the relative starting and stopping order of bundles in an OSGi Service Platform (setting start level, in Karafosgi:bundle-level, osgi:start-level).Remote Services: setup of remote access for the services
  3. Class loading: “uses” marks packages that exported API use (method signatures, parent classes), so the framework can check if those don’t conflict with imported packagesif java.* =&gt; parentif in Import-Package =&gt; exportersearch in Require-Bundlesearch in Bundle-ClassPathif in DynamicImport-Package =&gt; wiring
  4. Web-ContextPath: OSGI 4.2 specWebapp-Context: PAX Web specific
  5. Device Access specification supports the coordination of automatic detection and attachment ofexisting devices on an OSGi Service Platform, facilitates hot-plugging and -unplugging of newdevices, and downloads and installs device drivers on demand.Preferences = system or user-specific data storageUser Admin = authentication/authorizationMonitor Admin = status variables get/set/reset from administrative bundles
  6. Management tools: configuration (property files), logging, security, etc