Modularity 
patterns 
with OSGi
Paul Bakker 
@pbakker
Agenda 
μServices architecture 
Whiteboard pattern 
Reusable and configurable 
services 
Extender pattern 
Real world example
Classes https://www.flickr.com/photos/crdot/
https://www.flickr.com/photos/128326674@N06/ 
Modules 
http://www.carpartsireland.ie/uploads/Reardriftspoiler144cm003.jpg
Module 
Service contract 
Implementation 
classes
Hide 
implementation 
details
Make imports and 
exports explicit 
Export only public interfaces 
Import public interfaces 
provided by others Export-Package: 
example.api;version=“1.0.0" 
Import-Package: 
some.otherapi;version=“[1.0,2)"
OSGi Service Registry 
Service 
Registry 
Bundle registering a 
service 
Bundle using a 
service 
Publish 
MyInterface 
Lookup 
MyInterface
Demo
Components only communicate 
using service APIs 
Implementation should 
be replaceable! 
A simple example 
Results 
REST 
Results 
Storage 
Stats 
REST 
Stats 
Aggregator 
Tracks 
REST 
Tracks 
Storage 
Services may use 
multiple other services
Demo
Always 
be 
prepared 
for 
dynamics
Services must 
contain their own 
data 
Results 
Storage 
Tracks 
Storage
Examples 
MongoDB 
Each service owns a 
collection 
Relational 
Each service owns a 
set of tables 
Results 
Storage 
Tracks 
Storage 
... 
... 
Ta b l e A 
... 
... 
Ta b le B 
... 
... 
Ta b l e C 
... 
... 
Ta b le D 
... 
... 
Ta b le F 
... 
... 
Ta bl e E 
... 
... 
Ta b le G
Whiteboard 
Pattern
Plugin 
Registry 
Plugin Plugin Plugin 
Whiteboard 
Use multiple services 
with the same inter face
Demo
Real life examples 
Amdatu REST 
Apache Felix HTTP Whiteboard 
Amdatu Scheduling 
Amdatu Bootstrap plugins 
Apache Felix Gogo commands
Configuration
What if 
all services 
do the same thing 
with different config?
Managed 
Service 
Factory 
Config 
Config 
Config 
Component 
Component 
Component 
Managed Service Factor y
Extender 
Pattern
Real life examples 
Providing static web resources 
Amdatu JPA (weaving) 
Templates in Amdatu 
Bootstrap 
What if 
my bundles don’t 
really “do” anything?
Resource 
bundle A 
Resource 
bundle B 
Extender 
Component 
Component 
Component 
Extender pattern
Demo
Do NOT overuse 
Adding extenders is like 
adding a DSL: 
Powerful and confusing.
Bootstrap 
Core 
Amdatu 
Plugin 
Dependency 
Manager 
Plugin 
Project 
Plugin 
Workspace 
Plugin 
Baselining 
Plugin 
Bootstrap 
Web backend 
Bootstrap 
Shell 
Template 
Extender 
Project 
templates 
Workspace 
templates 
Bootstrap 
Web UI 
bnd 
Plugin Whiteboard 
... 
Plugin 
R eal world 
example 
Bootstrap
Wrap up 
A modular architecture gives us: 
Maintainability 
Extensibility 
Freedom to change
But what if I want 
Spring 
EJB 
…? 
Just don’t… You really don’t need to.
Eclipse OSGi plugin 
http://bndtools.org/ 
Open source 
OSGi components 
http://www.amdatu.org/ 
Amdatu 
That’s us 
http://luminis-technologies. 
com 
Paul Bakker 
paul.bakker@luminis.eu 
@pbakker

Moduarlity patterns with OSGi