Spring Dynamic Modules

23
Spring Dynamic Modules OSGi meets the Spring Framework Filippo Diotalevi <fi[email protected] > Spring Framework Italian Meeting, Cagliari, September 12th 2009

description

Spring Dynamic Modules: OSGi meets the Spring FrameworkIntroductive presentation about Spring DM and OSGi presented at the Spring Framework Italian Group in Cagliari, September 2009

Transcript of Spring Dynamic Modules

Page 1: Spring Dynamic Modules

Spring Dynamic ModulesOSGi meets the Spring Framework

Filippo Diotalevi <[email protected]>

Spring Framework Italian Meeting, Cagliari, September 12th 2009

Page 2: Spring Dynamic Modules

About

OSGi and Java Enterprise consultant

Java User Group Milano founder and coordinator

Apache Felix committer

http://www.diotalevi.com [email protected]

Page 4: Spring Dynamic Modules

Summary

OSGi

Spring Dynamic Modules for OSGi

What’s next

Page 5: Spring Dynamic Modules

OSGi

A dynamic module system for Java

(Demo)

Page 6: Spring Dynamic Modules

Module System

Clear boundaries

Dependencies

Metadata

Lifecycle

Page 7: Spring Dynamic Modules

Lifecycle of bundle

Page 8: Spring Dynamic Modules

Service System

Service Oriented Architecture in the JVM

Page 9: Spring Dynamic Modules

Service System

Bundle Provider Bundle Consumer

Service Registry

RegisterService

RetrieveService

Page 10: Spring Dynamic Modules

What’s an OSGi Application?

A collection of bundles interacting via Service interfaces

Bundles developed and installed independently

Bundle and services can appear and disappear

Page 11: Spring Dynamic Modules

What’s behind the demo

Bundle Host

Provide the Frame and

define the Shape interface

Service Registry

Listen forand

retrieveShapes

Bundle Triangle

Provide the Triangle

implementation

Bundle Circle

Provide the Circle

implementation

RegisterTriangle

RegisterCircle

Page 12: Spring Dynamic Modules

Why Spring DM?

OSGi in NOT about user interfaces

OSGi is about building modular and service oriented applications

Enterprise applications need modularity and SOA

Page 13: Spring Dynamic Modules

Spring Dynamic Modules

Part of the Spring open source portfolio

Formerly known as Spring-OSGi

Works with every OSGi container

Allows you to implement Spring applicationson top of any OSGi framework

Page 14: Spring Dynamic Modules

Spring DM idea

Java Virtual Machine

OSGi Container

Spring + Spring DM

Application Context

Application Context

Application Context

Spring Bean

Exported Service

Imported Service

Bundle ABundle B

Bundle C

Page 15: Spring Dynamic Modules

Bundles & Spring

One application context per bundle

When a bundle is started, its application contextis discovered and instantiated

Bundles can export Spring beans as OSGi services

Bundles can import OSGi services

Page 16: Spring Dynamic Modules

Beans as OSGi Services

<beans> <bean name="customerService" class="demo.customerservice.impl.CustomerServiceImpl"/>

<osgi:service id="customerServiceOsgi" ref="customerService" interface="demo.customerservice.CustomerService"/>

</beans>

Page 17: Spring Dynamic Modules

Importing OSGi services

<beans>

<osgi:reference id="customerServiceOsgi" interface="demo.osgi.customerservice.CustomerService"/>

<bean id="orderService" class="demo.osgi.orderservice.internal.OrderServiceImpl"> <property name="customerService"> <reflocal="customerServiceOsgi"/> </property> </bean>

</beans>

Page 18: Spring Dynamic Modules

Bigger pictureApplication Context

Customer

Service

Service

Registry

Expose

Customer

Service

Application Context

Retrieve

Customer

Service

Customer

Service

Proxy

Order

Service use

Page 19: Spring Dynamic Modules

Result

(Almost) no dependencies on OSGi APIs

Everything is a POJO (Spring philosophy)

Improved application modularity

Page 20: Spring Dynamic Modules

Going forward

Enterprise OSGi support in Spring DMFull support for Web Applications

and Java EE components

Integration with OSGi Remote-ServicesInter-JVM services

Standardization: OSGi Blueprint Service

Page 21: Spring Dynamic Modules

Questions?