29
Hot Deployable Cocoon Blocks with OSGi Daniel Fagerström [email protected]

Cocoon OSGi CocoonGT2007

Embed Size (px)

DESCRIPTION

Talk given at CocoonGT2007.

Citation preview

Page 1: Cocoon OSGi CocoonGT2007

Hot Deployable Cocoon Blocks with OSGi

Daniel Fagerströ[email protected]

Page 2: Cocoon OSGi CocoonGT2007

Overview

●Why?●How?

– Bundelization– Component wiring– Runtime environment

●When?

Page 3: Cocoon OSGi CocoonGT2007

Why?

● OSGi is the standard plugin framework– Reuse bundles from other projects– Other projects can reuse Cocoon bundles

● Dynamically updateable bundles– 24/7– Convenient for customer installations– Faster development

● Classloader isolation– Possible to use multiple versions of the same library

Page 4: Cocoon OSGi CocoonGT2007

Deja vú?● Earlier attempts with OSGi● Focused on the Servlet Service FW● OSGi more mature for enterprise apps now

Page 5: Cocoon OSGi CocoonGT2007

Modularization in 2.2

● Packaging● Spring Beans everywhere● Servlet Service FW● Deployment in global classloader and global

Spring factory● No dynamics

Page 6: Cocoon OSGi CocoonGT2007

How?

Page 7: Cocoon OSGi CocoonGT2007

OSGi

● Felix – OSGi Framework● Maven Bundle - Plugin for packaging● Spring-OSGi – Component wiring● Services from Felix, Spring-OSGi, Equinox,

OPS4J

Page 8: Cocoon OSGi CocoonGT2007

What is a block?

• A packaged application (or part) containing:– Libraries and resources– Components– Sitemap functionality

• Configurable at deploy time• Might depend on other blocks• Isolated internals (only partly in 2.2)

Page 9: Cocoon OSGi CocoonGT2007

What is a Block?What is a Block?

Classes,resources

Components

Sitemap

Export packages

Import packages

Registered services

Used services

Page 10: Cocoon OSGi CocoonGT2007

Block Structure

myBlock/ META-INF/ manifest.mf # bundle manifest

cocoon/ spring/ components.xml # spring components

spring/ osgi-services.xml # spring-osgi – exports & imports

org/ apache/ cocoon/ ... # classes

COB-INF/ sitemap.xmap ... # resources

Page 11: Cocoon OSGi CocoonGT2007

Component Wiring● Using Spring-OSGi● One web application context per block● Exporting and importing beans as OSGi

services

Page 12: Cocoon OSGi CocoonGT2007

Spring-OSGi vs. Declarative Services

Spring-OSGi+ Spring- Not released yet

DS+ Standard+ Several Releases- More container dependencies in the code- More work to integrate with Spring

Page 13: Cocoon OSGi CocoonGT2007

Exporting a Bean

<!-- cocoon-xml-impl -->

<bean name="org.apache.cocoon.core.xml.SAXParser" class="org.apache.cocoon.core.xml.impl.JaxpSAXParser" scope="singleton"> <property name="validate" value="false"/></bean>

<osgi:service ref="org.apache.cocoon.core.xml.SAXParser" interface="org.apache.cocoon.core.xml.SAXParser"/>

Page 14: Cocoon OSGi CocoonGT2007

Importing a Bean

<!-- cocoon-pipeline-components -->

<osgi:reference id="org.apache.cocoon.core.xml.SAXParser" interface="org.apache.cocoon.core.xml.SAXParser"/>

<bean name="org.apache.cocoon.generation.Generator/file" class="org.apache.cocoon.generation.FileGenerator" scope="prototype"> <property name="parser" ref="org.apache.cocoon.core.xml.SAXParser"/></bean>

Page 15: Cocoon OSGi CocoonGT2007

Bean Map

● Whiteboard pattern

Page 16: Cocoon OSGi CocoonGT2007

Bean Map

<!-- cocoon-expression-language-impl -->

<osgi:service ref="org.apache.cocoon.el.ExpressionCompiler/js" interface="org.apache.cocoon.el.ExpressionCompiler"/>

<osgi:service ref="org.apache.cocoon.el.ExpressionCompiler/jexl" interface="org.apache.cocoon.el.ExpressionCompiler"/>

<osgi:service ref="org.apache.cocoon.el.ExpressionCompiler/jxpath" interface="org.apache.cocoon.el.ExpressionCompiler"/>

<osgi:service ref="org.apache.cocoon.el.ExpressionCompiler/default" interface="org.apache.cocoon.el.ExpressionCompiler"/>

Page 17: Cocoon OSGi CocoonGT2007

Bean Map

<!-- cocoon-expression-language-impl -->

<bean id="org.apache.cocoon.el.ExpressionFactory" class="org.apache.cocoon.el.impl.DefaultExpressionFactory"> <property name="expressionCompilers"> <cosgi:map interface="org.apache.cocoon.el.ExpressionCompiler"/> </property></bean>

<osgi:service ref="org.apache.cocoon.el.ExpressionFactory" interface="org.apache.cocoon.el.ExpressionFactory"/>

Page 18: Cocoon OSGi CocoonGT2007

Service Events● Fine grained control of addition and removal of

services

Page 19: Cocoon OSGi CocoonGT2007

Service Events

<!-- cocoon-servlet-service-demo1 -->

<osgi:service ref="org.apache.cocoon.servletservice.demo1.servlet" interface="javax.servlet.Servlet"> <osgi:service-properties> <prop key="mountPath">/test1</prop> </osgi:service-properties></osgi:service>

<!-- cocoon-servlet-service-demo2 -->

<osgi:service ref="org.apache.cocoon.servletservice.demo2.servlet" interface="javax.servlet.Servlet"> <osgi:service-properties> <prop key="mountPath">/test2</prop> </osgi:service-properties></osgi:service>

Page 20: Cocoon OSGi CocoonGT2007

Service Events

<!-- cocoon-servlet-service-impl -->

<osgi:reference id="httpService" interface="org.osgi.service.http.HttpService"/>

<osgi:collection id="servletService" interface="javax.servlet.Servlet"> <osgi:listener bind-method="setServlet" unbind-method="unsetServlet" ref="servletListener"/></osgi:collection>

<bean id="servletListener" class="org.apache.cocoon.servletservice.osgi.Activator"> <property name="httpService" ref="httpService"/></bean>

Page 21: Cocoon OSGi CocoonGT2007

Tunnelling a Prototype● No correspondence to prototype scope in OSGi● Export a factory bean instead

Page 22: Cocoon OSGi CocoonGT2007

Tunnelling a Prototype

<!-- cocoon-pipeline-components -->

<bean name="org.apache.cocoon.generation.Generator/file" class="org.apache.cocoon.generation.FileGenerator" scope="prototype"> <property name="parser" ref="org.apache.cocoon.core.xml.SAXParser"/></bean>

<cosgi:service ref="org.apache.cocoon.generation.Generator/file" interface="org.apache.cocoon.generation.Generator" factory-export="true"/>

Page 23: Cocoon OSGi CocoonGT2007

Tunnelling a Prototype

<!-- cocoon-core-main-sample -->

<cosgi:reference name="org.apache.cocoon.generation.Generator/file" interface="org.apache.cocoon.generation.Generator" factory-export="true"/>

Page 24: Cocoon OSGi CocoonGT2007

Service Manager?● A sitemap may need many beans● Many service imports● Let the bundle local Spring context fall back to

the OSGi service registry?– Will that work with declarative wiring?

Page 25: Cocoon OSGi CocoonGT2007

Cocoon-OSGi Architecture● Http Service● Servlet container embedding?● Other services?

– Config– Log– ...

Page 26: Cocoon OSGi CocoonGT2007

Cocoon-OSGi Architecture

HttpService

Dispatcher

Blocks

/editor

/

Page 27: Cocoon OSGi CocoonGT2007

Deployment architecture

Cocoon platform

Blocks

Blocks repository (Maven 2)

Blocks discovery

(OBR)

Deployment service

Page 28: Cocoon OSGi CocoonGT2007

When?● One man show this far● Can live together with ”ordinary” Cocoon● Spring-OSGi expected to release 1.0.0 in

December● http://svn.apache.org/repos/asf/cocoon/whiteboard/osgi/

Page 29: Cocoon OSGi CocoonGT2007

Conclusion● Standard plugin● Classloader isolation● Hot deployable blocks