structuring software systems with osgi - ulf fildebrandt

29
COPYRIGHT © 2008-2011 OSGi Alliance. All Rights Reserved Structuring Software Systems with OSGi Ulf Fildebrandt SAP AG 22.09.2011 OSGi Alliance Marketing © 2008-2010 . All Rights Reserved Page 1

Upload: mfrancis

Post on 25-Jan-2015

2.007 views

Category:

Technology


0 download

DESCRIPTION

OSGi is providing a module system, but during implementation in projects it becomes difficult to really use the benefits of an OSGi runtime. Without follow the principles an OSGi system can evolve to a tightly-coupled system like in the past. Some principles and guidelines have to be followed to achieve a good architecture of a software system: - interface/implementation separation for bundles - visibility usage of bundles (import/export) - extensibility for services (and special focus on declarative services) - layering of bundles and using declarative service for layer communication - mocking of layers to achieve maturity of the implementation - interface evolution of bundles to achieve extensibility The presentation will show the changes by refactoring a small web application. The application starts as a tightly coupled system and will be improved by applying the architecture principles. So, in the presentation a lot of coding will be shown, until a good structure of the application is achieved. The guidelines are based on experiences in different projects and are used as best practices in new projects.

TRANSCRIPT

Page 1: Structuring software systems with OSGi - Ulf Fildebrandt

COPYRIGHT © 2008-2011 OSGi Alliance. All Rights Reserved

Structuring Software Systems with

OSGi

Ulf Fildebrandt

SAP AG

22.09.2011

OSGi Alliance Marketing © 2008-2010 .

All Rights Reserved

Page 1

Page 2: Structuring software systems with OSGi - Ulf Fildebrandt

OSGi Alliance Community Event 2011© 2008-2011. All Rights Reserved Page 2

Agenda

• OSGi: basic structure and declaration

• Interface Usage

• Layers

• Services and Layers

• Versioning

• Testing

• Assemblies

Page 3: Structuring software systems with OSGi - Ulf Fildebrandt

OSGi Alliance Community Event 2011© 2008-2011. All Rights Reserved Page 3

Agenda

• OSGi: basic structure and declaration

• Interface Usage

• Layers

• Services and Layers

• Versioning

• Testing

• Assemblies

Page 4: Structuring software systems with OSGi - Ulf Fildebrandt

Principles of Modularity

• Decoupling • Logic has to be decoupled, otherwise the structure evolves into a monolithic

block („architecture erosion“)

• Simplicity • Design the concepts as simple as possible, otherwise the system solves non-

existing requirements

• Extensibility • Decoupling implies that frameworks are open for logic

• Extensibility for logic is not the exception, but rather the common principle for

all frameworks

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 4

Page 5: Structuring software systems with OSGi - Ulf Fildebrandt

OSGi basics

• Bundles are the atomic entities for structuring

(containing binaries)

• Services are the communication means between

bundles

• Exported packages are the public interface of bundles

• Imported packages define the usages of bundles

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 5

Page 6: Structuring software systems with OSGi - Ulf Fildebrandt

Example

• Web application to analyze data

• OSGi bundles, services, and exported

packages are used to structure the application

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 6

Page 7: Structuring software systems with OSGi - Ulf Fildebrandt

Structure of Application

• Fulfills the business requirements, but no modularity

(decoupling, extensibility)

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 7

Servlet

Data

Source 1

Data

Source 2

Page 8: Structuring software systems with OSGi - Ulf Fildebrandt

Structure Of Application

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 8

Servlet

Data Aggregate

Data Source 1 Data Source 2

Data

Aggregator 1

Data

Aggregator 2

Data Aggregator

Interface

Data Source

Interface

Page 9: Structuring software systems with OSGi - Ulf Fildebrandt

OSGi Alliance Community Event 2011© 2008-2011. All Rights Reserved Page 9

Agenda

• OSGi: basic structure and declaration

• Interface Usage

• Layers

• Services and Layers

• Versioning

• Testing

• Assemblies

Page 10: Structuring software systems with OSGi - Ulf Fildebrandt

Interface Usage

• Implementation should only use interfaces Services

in OSGi

• Services are difficult to implement in OSGi fulfilling all

lifecycle requirements (Service Tracker, Service

Listener) „boilerplate coding“

• Frameworks: Declarative Services (DS) is part of the

OSGi specification, Blueprint, etc. • DS are meant to declare the dependencies of services and service usage

• DS is a mechanism to bring dependency injection into OSGi

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 10

Page 11: Structuring software systems with OSGi - Ulf Fildebrandt

Structure Of Application

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 11

Servlet

Data Aggregate

Data Source 1 Data Source 2

Data

Aggregator 1

Data

Aggregator 2

Data Aggregator

Interface

Data Source

Interface

IDataAggregate

IDataSource

IDataItem

IDataAggregator

IDataSourceService

Page 12: Structuring software systems with OSGi - Ulf Fildebrandt

OSGi Alliance Community Event 2011© 2008-2011. All Rights Reserved Page 12

Agenda

• OSGi: basic structure and declaration

• Interface Usage

• Layers

• Services and Layers

• Versioning

• Testing

• Assemblies

Page 13: Structuring software systems with OSGi - Ulf Fildebrandt

Layers

• In architecture, layers are used to structure the software

• Entities within a layer can only have dependencies to

lower layers

• Bundles in OSGi belong to one layer only

• In reality more coarse grained frameworks are used • Feature (P2, Eclipse)

• Application (Aries)

• OSGi sub system specification

• For simplicity in these examples only bundles are used

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 13

Page 14: Structuring software systems with OSGi - Ulf Fildebrandt

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 14 Data Source Interface

Data Aggregator Interface

Data Provider

Aggregator

Aggregate

UI Servlet

Data Aggregate

Data Source 1 Data Source 2

Data Aggregator 1

Data Aggregator 2

Data Aggregator Interface

Data Source Interface

Page 15: Structuring software systems with OSGi - Ulf Fildebrandt

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 15

Class

Structure

• Classes fit

to bundle

structure

Page 16: Structuring software systems with OSGi - Ulf Fildebrandt

OSGi Alliance Community Event 2011© 2008-2011. All Rights Reserved Page 16

Agenda

• OSGi: basic structure and declaration

• Interface Usage

• Layers

• Services and Layers

• Versioning

• Testing

• Assemblies

Page 17: Structuring software systems with OSGi - Ulf Fildebrandt

Interface of a Layer

• Layers should have a clear interface

• API (Application Programming Interface) • is defining the publicly available functionality

• is an interface

• is implemented as service in OSGi

• Example: IDataAggregate, IDataSourceService

• SPI (Service Provider Interface) • is defining the extension point

• is implemented as service in OSGi in a separate bundle

• Example: IDataSource, IDataAggregator

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 17

Page 18: Structuring software systems with OSGi - Ulf Fildebrandt

OSGi Alliance Community Event 2011© 2008-2011. All Rights Reserved Page 18

Agenda

• OSGi: basic structure and declaration

• Interface Usage

• Layers

• Services and Layers

• Versioning

• Testing

• Assemblies

Page 19: Structuring software systems with OSGi - Ulf Fildebrandt

Versioning in OSGi

• Bundles and exported packages are versioned

• Usage of versioning is different for implementation, API,

SPI • Implementation: can be replaced easily, because interface is not changed

• API: can be evolved in a compatible way, but implementation has to be

adapted, too

• SPI: evolution is difficult, because if interfaces are extended, then the old

implementations are not valid any more

• Java evolution: Ix Ix2, e.g. IDataAggregator IDataAggregator2 in the

same package

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 19

Page 20: Structuring software systems with OSGi - Ulf Fildebrandt

OSGi Alliance Community Event 2011© 2008-2011. All Rights Reserved Page 20

Agenda

• OSGi: basic structure and declaration

• Interface Usage

• Layers

• Services and Layers

• Versioning

• Testing

• Assemblies

Page 21: Structuring software systems with OSGi - Ulf Fildebrandt

Testing

• Layers have to be separately testable • Mock objects (Easy Mock)

• Example: DataAggregate layer

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 21

Page 22: Structuring software systems with OSGi - Ulf Fildebrandt

OSGi Alliance Community Event 2011© 2008-2011. All Rights Reserved Page 22

Agenda

• OSGi: basic structure and declaration

• Interface Usage

• Layers

• Services and Layers

• Versioning

• Testing

• Assemblies

Page 23: Structuring software systems with OSGi - Ulf Fildebrandt

Multiple assemblies

• Bundles assembled into multiple assemblies (e.g.

products)

• An assembly contains bundles from different layers • A layer does not have to be used completely

• Examples: • Other access layer (REST)

• Configuration data aggregator

• DSL data aggregator

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 23

Page 24: Structuring software systems with OSGi - Ulf Fildebrandt
Page 25: Structuring software systems with OSGi - Ulf Fildebrandt
Page 26: Structuring software systems with OSGi - Ulf Fildebrandt
Page 27: Structuring software systems with OSGi - Ulf Fildebrandt
Page 28: Structuring software systems with OSGi - Ulf Fildebrandt
Page 29: Structuring software systems with OSGi - Ulf Fildebrandt

Summary

• Module and service concepts should be used to

structure software

• Bundles expose clear interfaces

• Communications works by using services (minimum

requirement between layers)

• Layers are testable separately

• Different assemblies should be possible

OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 29