apache aries · apache aries where web apps meet osgi by alasdair nottingham [email protected]...

15
Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham [email protected] Software Engineer, IBM 1 Monday, 30 November 2009

Upload: others

Post on 08-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

Apache Aries Where Web Apps meet OSGi

by Alasdair [email protected] Engineer, IBM

1Monday, 30 November 2009

Page 2: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

What is OSGi?• The dynamic module system for Java

• Packages are the unit of modularity

• Collected together in bundles

• Connect using services

Services

Life Cycle

Module

Execution Environment

Security

Hardware / OS

Bundles

2Monday, 30 November 2009

Page 3: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

Bundles

Bundle A Bundle BImport Export

3Monday, 30 November 2009

Page 4: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

Class LoadingSystem loader

Extension loader

App 1 loader App 2 loader

WebApp1 loader Bundle A Bundle B

Bundle C1 Bundle C2

System loader

Extension loader

Import-Package:org.blah.util;

version=[1.0.2,2.0.0]

Export-Package:org.blah.util;version=1.5.0

Export-Package:org,blah.util;version=2.0.0

Traditional

OSGi

4Monday, 30 November 2009

Page 5: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

Dynamics• Bundle life cycle

• Services

Bundle A

Bundle C

Bundle BRegisterUse

Listen

5Monday, 30 November 2009

Page 6: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

Enterprise OSGi?• Java SE and EE technologies are not OSGi

aware

• OSGi Enterprise Expert Group (EEG) defining standards for integrating

JEE Glue OSGi

ApacheAries

JNDI

JPA

Servlet

6Monday, 30 November 2009

Page 7: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

Apache Aries

• Recent Apache incubator project

• OSGi as an application model

• Blueprint container (standardised Spring DM)

• JNDI integration

• ...more to come

7Monday, 30 November 2009

Page 8: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

Blueprint

8Monday, 30 November 2009

Page 9: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

Hello World!

Hello World ServiceHello World Client

9Monday, 30 November 2009

Page 10: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <bean id="helloservice" class="org.apache.aries.blueprint.helloworldserver.HelloWorldServiceImpl" init-method="startUp"> </bean> <service ref="helloservice" interface="org.apache.aries.blueprint.helloworldapi.HelloWorldService" /></blueprint>

HW service bundle

public class HelloWorldServiceImpl implements HelloWorldService { public void hello() { System.out.println("======>>> A message from the server: Hello World!"); } public void startUp() { System.out.println("======>>> Starting HelloWorld Server"); }}

Hello World Service

10Monday, 30 November 2009

Page 11: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

HW client bundle

public class HelloWorldClient {

private HelloWorldService helloWorldService = null;

public void setHelloWorldService(HelloWorldService hws) { helloWorldService = hws; }

public void startUp() { System.out.println("========>>>>Client HelloWorld: Execute hello() from Hello World service"); helloWorldService.hello(); System.out.println("========>>>>Client HelloWorld: ... done!"); }}

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <reference id="helloservice" interface="org.apache.aries.blueprint.helloworldapi.HelloWorldService" />

<bean id="helloclient" class="org.apache.aries.blueprint.helloworldclient.HelloWorldClient" init-method="startUp"> <property name="helloWorldService" ref="helloservice" /> </bean></blueprint>

Hello World Client

11Monday, 30 November 2009

Page 12: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

JNDI

• How to use JNDI in OSGi

• How to access the service registry from JNDI:

• osgi:service/<interface name>/<filter>

• osgi:serviceList/<interface name>/<filter>

12Monday, 30 November 2009

Page 13: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

Web + JNDI + Blueprint

Blueprint BundleWeb Bundle

13Monday, 30 November 2009

Page 14: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

Servlet

public class HelloWorldServlet extends HttpServlet {

@Resource(mappedName=”osgi:service/org.apache.aries.blueprint.helloworldapi.HelloWorldServlet”) private HelloWorldService helloWorldService = null;

public void doGet(HttpServletRequest request, HttpServletResponse response) { System.out.println("========>>>>Client HelloWorld: Execute hello() from Hello World service"); helloWorldService.hello(); System.out.println("========>>>>Client HelloWorld: ... done!"); }}

14Monday, 30 November 2009

Page 15: Apache Aries · Apache Aries Where Web Apps meet OSGi by Alasdair Nottingham not@apache.org Software Engineer, IBM Monday, 30 November 2009 1

Thanks for your attention!

• OSGi Alliance - http://www.osgi.org/

• OSGi Implementations

• http://www.eclipse.org/equinox/

• http://felix.apache.org/

• Apache Aries - http://incubator.apache.org/aries/

• Apache Aries Blog - http://blogs.apache.org/aries/

• Further reading

• http://www.ibm.com/developerworks/opensource/library/os-osgiblueprint/index.html

• OSGi in Action - http://neilbartlett.name/blog/osgibook/

15Monday, 30 November 2009