SlideShare a Scribd company logo
Dependencies, 
dependencies, 
dependencies 
Marcel Offermans 
TECHNOLOGIES
Marcel Offermans 
• Fellow and Software Architect at 
Luminis Technologies 
marcel.offermans@luminis.nl 
! 
•Member and Committer at 
Apache Software Foundation 
marrs@apache.org
Agenda 
• Introduction 
• Basic Concepts 
• Dependencies 
• Design Patterns 
• Custom Dependencies 
• Add-ons 
• Wrap-up 
Software distribution: 
copy both zip archives from the 
memory stick
Introduction
Framework 
Service 
Life$cycle 
Module 
Security 
OSGi$framework 
Bundle Bundle Bundle 
Java$Virtual$Machine
Service Dependencies 
• framework: ServiceListener 
– notification whenever there is a change 
in the service registry 
– but: only changes that occur while you 
are listening 
• utility: ServiceTracker 
– solves the listening issue 
– adds ability to customize services
Problem 
• using the framework supplied 
tooling, you are dealing with 
dependencies at a very low level 
• a lot of boiler plate code is needed 
to implement real world scenarios 
• there are very few design patterns 
that deal with composing an 
application based on services
Declaring your dependencies 
• Service Binder 
• Dependency Manager 
• Declarative Services 
• iPOJO 
• Blueprint 
• ...many more
Dependency Manager 
• Subproject of Apache Felix 
• Nearing a 3.0 release 
• Some interesting new features 
...I’m not unbiased, being it’s author
Basic Concepts
Basic Concepts 
• Component: class that implements 
certain behaviour (a POJO) 
• Dependency: something our 
component needs or wants (ie. a 
service) 
• Service: OSGi service interface(s) 
under which our component is 
registered
Declarative API 
• Declarative ≠ XML 
• Using a Java API has many 
advantages: 
– less error prone because of syntax and 
compile time checking 
– refactoring support, completion 
– very readable through fluid API 
– everything in one place, no magic
On the memory stick: 
! 
a) an Eclipse update site for BndTools 
b) a set of Eclipse projects 
Example code 
• Projects 
– Download: http://www.xs4all.nl/~mfo/projects.zip 
• Uses Eclipse + BndTools 
– Homepage: http://njbartlett.name/bndtools.html 
– Update Site: http://bndtools-updates.s3.amazonaws.com 
• Based on a snapshot release of the 
upcoming Dependency Manager 3.0 
• During the presentation, we will 
switch between slides and Eclipse to 
show running examples
Using the Dependency Manager 
Import-Package = org.apache.felix.dm;version="[3.0,4)" 
public class Activator extends DependencyActivatorBase { 
public void init(BundleContext context, DependencyManager manager) throws Exception { 
manager.add(createComponent() 
.setImplementation(new HelloWorld()) 
); 
} 
! 
public void destroy(BundleContext context, DependencyManager manager) throws Exception { 
} 
}
Basic Use Cases 
• Declare a component 
HelloWorld helloWorld = new HelloWorld(); 
manager.add(createComponent() 
! 
! 
! 
• Declare it lazily 
.setImplementation(helloWorld) 
); 
manager.add(createComponent() 
.setImplementation(HelloWorld.class) 
);
Component Life Cycle 
•methods of the component 
public static class HelloWorldLifeCycle { 
! 
! 
! 
• setCallbacks(“init”, “start”, ...) 
setCallbacks(inst, “init”, “start”, ...) 
private void init() { System.out.println("init"); } 
private void start() { System.out.println("start"); } 
private void stop() { System.out.println("stop"); } 
private void destroy() { System.out.println("destroy"); } 
} 
– to invoke the methods on ‘inst’ 
• ComponentStateListener 
– if you want to listen from the outside
Declaring as a service 
• setInterface(...) 
– allows you to declare multiple services 
– allows you to specify service properties 
manager.add(createComponent() 
.setInterface(LogService.class.getName(), 
new Properties() {{ put(Constants.SERVICE_RANKING, 20); }}) 
.setImplementation(MyLogService.class)
Declaring Dependencies 
• Adding a dependency 
manager.add(createComponent() 
! 
! 
! 
• Injects dependency 
.setImplementation(HelloWorldLogger.class) 
.add(createServiceDependency() 
.setService(LogService.class) 
) 
); 
– uses null object pattern 
– injects other “OSGi” instances 
• setCallbacks(...) 
setCallbacks(inst, ...)
Dependencies
Dependencies 
• Different types: 
– Service Dependencies 
– Configuration Dependencies 
– Bundle Dependencies 
– Resource Dependencies
Configuration Dependencies 
• Based on Configuration Admin 
– designed for required dependencies 
– service.pid to identify the configuration 
– allows you to only accept *valid* 
configurations 
•update() throws ConfigurationException
Bundle Dependencies 
• Depend on a bundle: 
– in certain states 
– with certain manifest entries 
• Bundle instance can be injected
Resource Dependencies 
• Resources are modeled as URLs 
• Are provided by a repository 
– another bundle 
– an Eclipse workspace 
– some external source 
• Filter on host, port, protocol, path 
and URL
Design Patterns
Design Patterns 
•Moving up a level in abstraction 
• OSGi is too low level to expose to 
everybody, but it is a great platform 
to build on 
• Patterns provide a common 
language and describe solutions in 
context
Overview of Design Patterns 
•Whiteboard Pattern 
• Null Object Pattern 
• “Singleton” Service 
• Aspect Service 
• Adapter Service 
• Resource Adapter Service
Whiteboard Pattern 
“don’t call us... 
we’ll call you”
Null Object Pattern 
• An object that implements a certain 
interface, can be safely invoked and 
does nothing
“Singleton” Service 
• Publishes a component as a service 
• Ties its life cycle to that of its 
dependencies 
Document 
Repository 
get() 
getVersions() 
get(version) 
store(Document) 
Singleton 
Storage 
requires
Aspect Service 
•Works at the service level 
• “intercepts” certain services 
• can be chained based on rankings 
• completely dynamic 
Repository Cache 
get() 
getVersions() 
get(version) 
store(Document) 
Aspect 
Repository 
get() 
getVersions() 
get(version) 
store(Document) 
intercepts
Adapter Service 
•Works on existing services 
• Adapts them, publishes a different 
service for each existing one 
Repository Cache 
Manageable 
getCacheHits() 
setSize() 
setTTL() 
flush() 
Adapter 
Repository Cache 
get() 
getVersions() 
get(version) 
store(Document) 
adapts
Resource Adapter Service 
• Adapts resources (instead of 
services) 
• Allows you to expose the behavior 
of certain resources instead of their 
“inner guts” 
Audio Track 
play() 
pause() 
stop() 
Resource 
Adapter 
MP3 
File 
adapts
Custom 
Dependencies
Custom Dependencies 
• Dependency Manager is extensible 
with custom dependencies: 
– depend on time of day 
– depend on some custom instance / 
condition (start level, app state)
Add-ons
Add-ons 
• Shell (Felix, Equinox, Gogo) 
• Annotation based (Java 5 required) 
• Legacy support (2.x API adapter)
Wrap-up
Wrap-up 
• Points to take away: 
– do not expose every developer to the 
OSGi API 
– build higher level abstractions, use 
design patterns 
– consider the dependency manager, it is 
very flexible
More about OSGi 
• ApacheCon 2010 North America 
November 1-5, Atlanta 
– OSGi tutorial 
– full day OSGi track 
•Masterclass on OSGi 
October 12-15, Girona 
– Neil Bartlett and Peter Kriens

More Related Content

KEY
Play Support in Cloud Foundry
PDF
Cloud Foundry Open Tour India 2012 , Keynote
PDF
Service discovery in mesos miguel, Angel Guillen
PPTX
Moving From Actions & Behaviors to Microservices
PPTX
No Docker? No Problem: Automating installation and config with Ansible
PPTX
Powershell For Developers
PDF
Microservice With Spring Boot and Spring Cloud
PPTX
Building Micro-Services with Scala
Play Support in Cloud Foundry
Cloud Foundry Open Tour India 2012 , Keynote
Service discovery in mesos miguel, Angel Guillen
Moving From Actions & Behaviors to Microservices
No Docker? No Problem: Automating installation and config with Ansible
Powershell For Developers
Microservice With Spring Boot and Spring Cloud
Building Micro-Services with Scala

What's hot (20)

PPTX
ASP.NET Core 1.0
PDF
5 steps to take setting up a streamlined container pipeline
PPTX
Owin and katana
PPT
Sebastien goasguen cloud stack the next year
PPTX
OWIN and Katana Project - Not Only IIS - NoIIS
PDF
Introduction to Systems Management with SaltStack
PDF
Oracle SOA suite and Coherence dehydration
PPTX
Extending Alfresco Digital Workspace with Docusign
PDF
ContainerDays NYC 2015: "Container Orchestration Compared: Kubernetes and Doc...
PPTX
Introduction to OWIN
PPTX
Upgrading to Alfresco 6
PDF
Productivity Acceleration Tools for SOA Testers
PPT
Exploring Openstack Swift(Object Storage) and Swiftstack
PPTX
Netflix0SS Services on Docker
PPT
Sebastien goasguen cloud stack and docker
PPTX
OpenStack Introduction
PPTX
Deploying a secured Flink cluster on Kubernetes
PDF
Alfresco Transform Service DevCon 2019
 
PPTX
Laravel introduction
PPTX
Microservices with docker swarm and consul
ASP.NET Core 1.0
5 steps to take setting up a streamlined container pipeline
Owin and katana
Sebastien goasguen cloud stack the next year
OWIN and Katana Project - Not Only IIS - NoIIS
Introduction to Systems Management with SaltStack
Oracle SOA suite and Coherence dehydration
Extending Alfresco Digital Workspace with Docusign
ContainerDays NYC 2015: "Container Orchestration Compared: Kubernetes and Doc...
Introduction to OWIN
Upgrading to Alfresco 6
Productivity Acceleration Tools for SOA Testers
Exploring Openstack Swift(Object Storage) and Swiftstack
Netflix0SS Services on Docker
Sebastien goasguen cloud stack and docker
OpenStack Introduction
Deploying a secured Flink cluster on Kubernetes
Alfresco Transform Service DevCon 2019
 
Laravel introduction
Microservices with docker swarm and consul
Ad

Viewers also liked (8)

ODP
Itt1 sd uml and oo
PPT
JavaYDL15
PDF
OO & UML
PDF
Wrapper classes
PPT
OO Development 3 - Models And UML
PPT
System software
PPT
M02 Uml Overview
PDF
8 abstract classes and interfaces
Itt1 sd uml and oo
JavaYDL15
OO & UML
Wrapper classes
OO Development 3 - Models And UML
System software
M02 Uml Overview
8 abstract classes and interfaces
Ad

Similar to Dependencies, dependencies, dependencies (20)

PDF
OSGi Community Event 2010 - Dependencies, dependencies, dependencies
PDF
10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
PPTX
Spring MVC framework
PDF
Automatically Managing Service Dependencies in an OSGi Environment - Marcel O...
PDF
The Ultimate Dependency Manager Shootout (QCon NY 2014)
KEY
Beyond OSGi Software Architecture
PPTX
Spring Basics
PPT
Enabling modularization through OSGi and SpringDM
PDF
Introduction to OSGi (Tokyo JUG)
PDF
OSGi bootcamp - part 2
PDF
iPOJO - The Simple Life - Richard Hall, Visiting Assistant Professor at Tufts...
PPTX
Enterprise Spring Building Scalable Applications
PPT
Developing modular Java applications
PDF
The Basic Concept Of IOC
PPTX
Java Modularity with OSGi
PPT
Spring - a framework written by developers
PDF
Dynamic and modular Web Applications with Equinox and Vaadin
PPT
Service oriented component model
PDF
Monoliths are so 2001 – What you need is Modularity
PDF
Real World Dependency Injection - PFCongres 2010
OSGi Community Event 2010 - Dependencies, dependencies, dependencies
10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
Spring MVC framework
Automatically Managing Service Dependencies in an OSGi Environment - Marcel O...
The Ultimate Dependency Manager Shootout (QCon NY 2014)
Beyond OSGi Software Architecture
Spring Basics
Enabling modularization through OSGi and SpringDM
Introduction to OSGi (Tokyo JUG)
OSGi bootcamp - part 2
iPOJO - The Simple Life - Richard Hall, Visiting Assistant Professor at Tufts...
Enterprise Spring Building Scalable Applications
Developing modular Java applications
The Basic Concept Of IOC
Java Modularity with OSGi
Spring - a framework written by developers
Dynamic and modular Web Applications with Equinox and Vaadin
Service oriented component model
Monoliths are so 2001 – What you need is Modularity
Real World Dependency Injection - PFCongres 2010

More from Marcel Offermans (7)

PDF
De leukste Bug
PDF
Building Secure OSGi Applications
PDF
OSGi on Google Android using Apache Felix
PDF
Component-based ontwikkelen met OSGi: van embedded tot enterprise
PDF
Modular Architectures using Micro Services
PDF
Felix HTTP - Paving the road to the future
PDF
Dynamic Deployment With Apache Felix
De leukste Bug
Building Secure OSGi Applications
OSGi on Google Android using Apache Felix
Component-based ontwikkelen met OSGi: van embedded tot enterprise
Modular Architectures using Micro Services
Felix HTTP - Paving the road to the future
Dynamic Deployment With Apache Felix

Recently uploaded (20)

PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
medical staffing services at VALiNTRY
PDF
AI in Product Development-omnex systems
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Digital Strategies for Manufacturing Companies
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
VVF-Customer-Presentation2025-Ver1.9.pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Adobe Illustrator 28.6 Crack My Vision of Vector Design
2025 Textile ERP Trends: SAP, Odoo & Oracle
Wondershare Filmora 15 Crack With Activation Key [2025
How to Choose the Right IT Partner for Your Business in Malaysia
How to Migrate SBCGlobal Email to Yahoo Easily
medical staffing services at VALiNTRY
AI in Product Development-omnex systems
How Creative Agencies Leverage Project Management Software.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Digital Strategies for Manufacturing Companies
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Online Work Permit System for Fast Permit Processing
Understanding Forklifts - TECH EHS Solution
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...

Dependencies, dependencies, dependencies

  • 1. Dependencies, dependencies, dependencies Marcel Offermans TECHNOLOGIES
  • 2. Marcel Offermans • Fellow and Software Architect at Luminis Technologies marcel.offermans@luminis.nl ! •Member and Committer at Apache Software Foundation marrs@apache.org
  • 3. Agenda • Introduction • Basic Concepts • Dependencies • Design Patterns • Custom Dependencies • Add-ons • Wrap-up Software distribution: copy both zip archives from the memory stick
  • 5. Framework Service Life$cycle Module Security OSGi$framework Bundle Bundle Bundle Java$Virtual$Machine
  • 6. Service Dependencies • framework: ServiceListener – notification whenever there is a change in the service registry – but: only changes that occur while you are listening • utility: ServiceTracker – solves the listening issue – adds ability to customize services
  • 7. Problem • using the framework supplied tooling, you are dealing with dependencies at a very low level • a lot of boiler plate code is needed to implement real world scenarios • there are very few design patterns that deal with composing an application based on services
  • 8. Declaring your dependencies • Service Binder • Dependency Manager • Declarative Services • iPOJO • Blueprint • ...many more
  • 9. Dependency Manager • Subproject of Apache Felix • Nearing a 3.0 release • Some interesting new features ...I’m not unbiased, being it’s author
  • 11. Basic Concepts • Component: class that implements certain behaviour (a POJO) • Dependency: something our component needs or wants (ie. a service) • Service: OSGi service interface(s) under which our component is registered
  • 12. Declarative API • Declarative ≠ XML • Using a Java API has many advantages: – less error prone because of syntax and compile time checking – refactoring support, completion – very readable through fluid API – everything in one place, no magic
  • 13. On the memory stick: ! a) an Eclipse update site for BndTools b) a set of Eclipse projects Example code • Projects – Download: http://www.xs4all.nl/~mfo/projects.zip • Uses Eclipse + BndTools – Homepage: http://njbartlett.name/bndtools.html – Update Site: http://bndtools-updates.s3.amazonaws.com • Based on a snapshot release of the upcoming Dependency Manager 3.0 • During the presentation, we will switch between slides and Eclipse to show running examples
  • 14. Using the Dependency Manager Import-Package = org.apache.felix.dm;version="[3.0,4)" public class Activator extends DependencyActivatorBase { public void init(BundleContext context, DependencyManager manager) throws Exception { manager.add(createComponent() .setImplementation(new HelloWorld()) ); } ! public void destroy(BundleContext context, DependencyManager manager) throws Exception { } }
  • 15. Basic Use Cases • Declare a component HelloWorld helloWorld = new HelloWorld(); manager.add(createComponent() ! ! ! • Declare it lazily .setImplementation(helloWorld) ); manager.add(createComponent() .setImplementation(HelloWorld.class) );
  • 16. Component Life Cycle •methods of the component public static class HelloWorldLifeCycle { ! ! ! • setCallbacks(“init”, “start”, ...) setCallbacks(inst, “init”, “start”, ...) private void init() { System.out.println("init"); } private void start() { System.out.println("start"); } private void stop() { System.out.println("stop"); } private void destroy() { System.out.println("destroy"); } } – to invoke the methods on ‘inst’ • ComponentStateListener – if you want to listen from the outside
  • 17. Declaring as a service • setInterface(...) – allows you to declare multiple services – allows you to specify service properties manager.add(createComponent() .setInterface(LogService.class.getName(), new Properties() {{ put(Constants.SERVICE_RANKING, 20); }}) .setImplementation(MyLogService.class)
  • 18. Declaring Dependencies • Adding a dependency manager.add(createComponent() ! ! ! • Injects dependency .setImplementation(HelloWorldLogger.class) .add(createServiceDependency() .setService(LogService.class) ) ); – uses null object pattern – injects other “OSGi” instances • setCallbacks(...) setCallbacks(inst, ...)
  • 20. Dependencies • Different types: – Service Dependencies – Configuration Dependencies – Bundle Dependencies – Resource Dependencies
  • 21. Configuration Dependencies • Based on Configuration Admin – designed for required dependencies – service.pid to identify the configuration – allows you to only accept *valid* configurations •update() throws ConfigurationException
  • 22. Bundle Dependencies • Depend on a bundle: – in certain states – with certain manifest entries • Bundle instance can be injected
  • 23. Resource Dependencies • Resources are modeled as URLs • Are provided by a repository – another bundle – an Eclipse workspace – some external source • Filter on host, port, protocol, path and URL
  • 25. Design Patterns •Moving up a level in abstraction • OSGi is too low level to expose to everybody, but it is a great platform to build on • Patterns provide a common language and describe solutions in context
  • 26. Overview of Design Patterns •Whiteboard Pattern • Null Object Pattern • “Singleton” Service • Aspect Service • Adapter Service • Resource Adapter Service
  • 27. Whiteboard Pattern “don’t call us... we’ll call you”
  • 28. Null Object Pattern • An object that implements a certain interface, can be safely invoked and does nothing
  • 29. “Singleton” Service • Publishes a component as a service • Ties its life cycle to that of its dependencies Document Repository get() getVersions() get(version) store(Document) Singleton Storage requires
  • 30. Aspect Service •Works at the service level • “intercepts” certain services • can be chained based on rankings • completely dynamic Repository Cache get() getVersions() get(version) store(Document) Aspect Repository get() getVersions() get(version) store(Document) intercepts
  • 31. Adapter Service •Works on existing services • Adapts them, publishes a different service for each existing one Repository Cache Manageable getCacheHits() setSize() setTTL() flush() Adapter Repository Cache get() getVersions() get(version) store(Document) adapts
  • 32. Resource Adapter Service • Adapts resources (instead of services) • Allows you to expose the behavior of certain resources instead of their “inner guts” Audio Track play() pause() stop() Resource Adapter MP3 File adapts
  • 34. Custom Dependencies • Dependency Manager is extensible with custom dependencies: – depend on time of day – depend on some custom instance / condition (start level, app state)
  • 36. Add-ons • Shell (Felix, Equinox, Gogo) • Annotation based (Java 5 required) • Legacy support (2.x API adapter)
  • 38. Wrap-up • Points to take away: – do not expose every developer to the OSGi API – build higher level abstractions, use design patterns – consider the dependency manager, it is very flexible
  • 39. More about OSGi • ApacheCon 2010 North America November 1-5, Atlanta – OSGi tutorial – full day OSGi track •Masterclass on OSGi October 12-15, Girona – Neil Bartlett and Peter Kriens