moduarlity patterns with osgi

32
Modularity patterns with OSGi

Upload: paul-bakker

Post on 17-Jul-2015

1.700 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Moduarlity patterns with OSGi

Modularity

patterns

with OSGi

Page 2: Moduarlity patterns with OSGi

Paul Bakker@pbakker

Page 3: Moduarlity patterns with OSGi

Agenda µServices architecture Whiteboard pattern Reusable and configurable services Extender pattern Real world example

Page 4: Moduarlity patterns with OSGi

Classeshttps://www.flickr.com/photos/crdot/

Page 5: Moduarlity patterns with OSGi

Modules

https://www.flickr.com/photos/128326674@N06/

http://www.carpartsireland.ie/uploads/Reardriftspoiler144cm003.jpg

Page 6: Moduarlity patterns with OSGi

Service contract

Module

Implementation classes

Page 7: Moduarlity patterns with OSGi

Hide implementation

details

Page 8: Moduarlity patterns with OSGi

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)"

Page 9: Moduarlity patterns with OSGi
Page 10: Moduarlity patterns with OSGi

ServiceRegistry

Bundle registering a service

Bundle using a service

PublishMyInterface

LookupMyInterface

OSGi Service Registry

Page 11: Moduarlity patterns with OSGi

Demo

Page 12: Moduarlity patterns with OSGi

Components only communicate using service APIs

Implementation should be replaceable!

A simple example

ResultsREST

ResultsStorage

StatsAggregator

StatsREST

TracksREST

TracksStorage

Services may use multiple other services

Page 13: Moduarlity patterns with OSGi

Demo

Page 14: Moduarlity patterns with OSGi

Always  be  prepared  for  dynamics

Page 15: Moduarlity patterns with OSGi

Services must

contain their own data

ResultsStorage

TracksStorage

ResultsStorage

TracksStorage

Page 16: Moduarlity patterns with OSGi

Examples

MongoDB Each service owns a

collection

Relational

Each service owns a

set of tables

ResultsStorage

TracksStorage

...

...

Table A

...

...

Table B

...

...

Table C......

Table D

...

...

Table F

...

...

Table E

...

...

Table G

Page 17: Moduarlity patterns with OSGi

Whiteboard

Pattern

Page 18: Moduarlity patterns with OSGi

PluginRegistry

Plugin Plugin Plugin

Whiteboard

Use multiple services with the same interface

Page 19: Moduarlity patterns with OSGi

Demo

Page 20: Moduarlity patterns with OSGi

Real life examples

Amdatu REST Apache Felix HTTP Whiteboard Amdatu Scheduling Amdatu Bootstrap plugins Apache Felix Gogo commands

Page 21: Moduarlity patterns with OSGi

Configuration

Page 22: Moduarlity patterns with OSGi

What if

all services

do the same thing

with different config?

Page 23: Moduarlity patterns with OSGi

ManagedServiceFactory

Config

Config

Config

Component

Component

Component

Managed Service Factory

Page 24: Moduarlity patterns with OSGi

Extender  Pattern

Page 25: Moduarlity patterns with OSGi

Real life examples

Providing static web resources Amdatu JPA (weaving) Templates in Amdatu Bootstrap

What if

my bundles don’t

really “do” anything?

Page 26: Moduarlity patterns with OSGi

Resourcebundle A

Resourcebundle B

Extender

Component

Component

Component

Extender pattern

Page 27: Moduarlity patterns with OSGi

Demo

Page 28: Moduarlity patterns with OSGi

Do NOT overuse

Adding extenders is like adding a DSL: Powerful and confusing.

Page 29: Moduarlity patterns with OSGi

BootstrapCore

AmdatuPlugin

Dependency Manager

Plugin

ProjectPlugin

WorkspacePlugin

BaseliningPlugin

BootstrapWeb backend

BootstrapShell

TemplateExtender

Projecttemplates

Workspacetemplates

BootstrapWeb UI

bnd

Plugin Whiteboard

...Plugin

Real world

example

Bootstrap

Page 30: Moduarlity patterns with OSGi

A modular architecture gives us:

Maintainability

Extensibility

Freedom to change

Wrap up

Page 31: Moduarlity patterns with OSGi

But what if I want

Spring

EJB

…?

Just don’t… You really don’t need to.

Page 32: Moduarlity patterns with OSGi

Eclipse OSGi plugin http://bndtools.org/

That’s us http://luminis-technologies.com

Open source OSGi components

http://www.amdatu.org/

Amdatu

Paul Bakker [email protected] @pbakker