In Pieces Breaking down monolithic applications with Spring-DM and OSGi.

Slides:



Advertisements
Similar presentations
CTS2 DEVELOPMENT FRAMEWORK CTS2 Overview. Schedule What is it? Why a framework? What does this do for me? Plugins Implementations available now CTS2 Compliance.
Advertisements

Introduction to Maven 2.0 An open source build tool for Enterprise Java projects Mahen Goonewardene.
OpusCollege and Spring-DM. OSGi based web applications – three strategies OSGi container embedded in another container: OSGi Bridge Server (OBS)  e.g.
Introduce OSGi BlueDavy
Apache Struts Technology
CPSC 875 John D. McGregor Architecture evolution.
Component Models and Technologies Case Study: OSGI.
Java Web User Group Impala Framework Update Modular class loaders and OSGi Phil Zoio London December 2, 2008.
OSGi Remote Services with SCA using Apache Tuscany Raymond Feng
OSGi as a Framework for Building a Product Line: Experience and Best Practices Ruwan Linton & Afkham Azeez
Why OSGi matters for Enterprise Java Infrastructures
Apache Axis2 - OSGi Integration in WSO2 Carbon Platform
Next Generation Node (NGN) Technical Overview April 2007.
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
Eclipse Architecture Dwight Deugo Nesa Matic
Apache Axis: A Set of Java Tools for SOAP Web Services.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of Creating Eclipse plug-ins.
Views Dwight Deugo Nesa Matic
Apache Struts Technology A MVC Framework for Java Web Applications.
Spring Dynamic Modules. Startlocation: Documentation: /1.2.1/reference/html/
The Spring Framework: A brief introduction to Inversion of Control James Brundege
Intro to Spring CJUG - January What is Spring? “The Spring framework provides central transaction control of various objects.” This means that any.
Struts 2.0 an Overview ( )
Agenda Introduction to the Guidewire platform
Introduction to the Enterprise Library. Sounds familiar? Writing a component to encapsulate data access Building a component that allows you to log errors.
OSGi.
BoxSpring (draft) Justin Edelson VP, Applications & Platforms MTV Networks Digital.
Christopher Jeffers August 2012
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics NPRG044: OSGi framework Michal Malohlava & Pavel Parízek
Introduction to J2EE Architecture Portions by Kunal Mehta.
1 Apache. 2 Module - Apache ♦ Overview This module focuses on configuring and customizing Apache web server. Apache is a commonly used Hypertext Transfer.
SAMANVITHA RAMAYANAM 18 TH FEBRUARY 2010 CPE 691 LAYERED APPLICATION.
Review: OSGi – a component framework for Java Bundle OSGi Framework Bundle Java Runtime Environment (JRE) Operating System (OS) Hardware “Dynamic Modules.
Spring Framework. Spring Overview Spring is an open source layered Java/J2EE application framework Created by Rod Johnson Based on book “Expert one-on-one.
1 ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 1 Building Portlets with ColdFusion Pete Freitag Foundeo, Inc.
Comparing JavaBeans and OSGi Towards an Integration of Two Complementary Component Models HUMBERTO CERVANTES JEAN-MARIE FAVRE 09/02.
OSGi Enablement for Tuscany Raymond Feng. Overview.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
OSGi in action BlueDavy
Migrating Desktop The graphical framework for running grid applications Bartek Palak Poznan Supercomputing and Networking Center The.
1 Schema Registries Steven Hughes, Lou Reich, Dan Crichton NASA 21 October 2015.
OSGi Service Platform Open Service Gateway initiative.
Open Service Gateway Initiative (OSGi) Reporter : 林學灝 侯承育 1.
introducing the Java Data Processing Framework Paolo Ciccarese, PhD On behalf of the JDPF Team Pavia, December 11, 2007.
Sameera Jayasoma 18 th July, 2009 Senior Software Engineer Introduction to OSGi The Dynamic Module System for Java.
ICT Strategy Intelligent Highways: Endpoint Adapters.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
Katari Globant 2008 (update to 2010). Katari  Katari is a framework to use as a starting point to develop new web applications.  Incorporates architecture,
Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Maven, Eclipse and OSGi working together Carlos Sanchez March 17, 2008.
Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Introduction to business component technologies. Component definitions Szyperski: A software component is a unit of composition with contractually specified.
Impala A dynamic module framework for Java web development Phil Zoio Realsolve Solutions Devoxx 12 December, 2008.
Introduction to OSGi +ActorFrame Surya Bahadur Kathayat
Apache Struts Technology A MVC Framework for Java Web Applications.
Maven. Introduction Using Maven (I) – Installing the Maven plugin for Eclipse – Creating a Maven Project – Building the Project Understanding the POM.
From “Hello World” to Real World : Building web apps with Spring OSGi Craig Walls The Spring Experience 2007 December 12, 2007.
Joe Bohn Apache Aries and IBM Original slides created by Graham Charters for OSGi DevCon US 2010, March 22, 2010 with minor updates by Joe Bohn for BarCampRDU.
Graham Charters Apache Aries and IBM Apache Aries An Open Source project for Enterprise OSGi Applications.
J2EE Platform Overview (Application Architecture)
Play Framework: Introduction
Overall Architecture and Component Model
AVOIR -African virtual
Introduction to J2EE Architecture
Intro to Spring CJUG - January 2013.
ESIS Consulting LLC (C) ESIS Consulting LLC. All rights reserved
Plug-In Architecture Pattern
Presentation transcript:

In Pieces Breaking down monolithic applications with Spring-DM and OSGi

Blog: Twitter: Twitter: hab Agenda The problem: Lack of modularity OSGi Basics OSGi without Spring-DM Introducing Spring-DM Spring-DM and the web Blueprint Services So what? Moving to OSGi

The Problem

Blog: Twitter: Twitter: hab Modularity is... High cohesion Modules are focused in purpose Low coupling Modules have minimal/no direct dependency on each other Not a new idea... “A well-defined segmentation of the project effort ensures system modularity. Each task forms a separate, distinct program module. At implementation time each module and its inputs and outputs are well-defined, there is no confusion in the intended interface with other system modules. At checkout time the integrity of the module is tested independently; there are few scheduling problems in synchronizing the completion of several tasks before checkout can begin. Finally, the system is maintained in modular fashion; system errors and deficiencies can be traced to specific system modules, thus limiting the scope of detailed error searching.” Designing Systems Programs, Richard Gauthier and Stephen Pont, 1970.

Blog: Twitter: Twitter: hab Modularity promotes... Testability Comprehensibility Flexibility Reusability Plugability

Blog: Twitter: Twitter: hab Modularity in Java? Java lacks some essential features to support modular development Classes encapsulate data and functionality They’re too fine-grained for practical modularity Packages only contain classes They’re only an organizational mechanism JAR files only contain packages/classes Their boundaries dissolve when placed on the classpath

Blog: Twitter: Twitter: hab A false sense of modularity

Blog: Twitter: Twitter: hab JAR Hell

Blog: Twitter: Twitter: hab The solution...OSGi Modular framework for the OSGi platform Classpath++ POJO-oriented Dynamic Runtime Modules can be installed, started, stopped, updated, and uninstalled...in a live program Ends JAR Hell Multiple versions of a class can reside in OSGi simultaneously

Blog: Twitter: Twitter: hab You think you’re modular? Then why do you deploy your web applications as a single large WAR file?

Blog: Twitter: Twitter: hab Yeah, but... Isn’t OSGi hard?

OSGi Basics

Blog: Twitter: Twitter: hab Bundles Just JAR files Contain special metadata in MANIFEST.MF All content is private by default May export packages to be imported by other bundles May publish services May be versioned

Blog: Twitter: Twitter: hab Fragments Just JAR files, like bundles, but... Must be hosted by another bundle Physically separate, logically united Used to add content (classes, resources, etc) to a hosting bundle

Blog: Twitter: Twitter: hab Bundle Lifecycle

Blog: Twitter: Twitter: hab OSGi Manifest Defines the content of a bundle Manifest-Version: 1.0 Built-By: wallsc Created-By: Apache Maven Bundle Plugin Bundle-Activator: com.osgiknowhow.hello.consumer.internal.HelloConsumerActivator Import-Package: com.osgiknowhow.hello.service;version="1.0.0.SNAPSHOT", org.osgi.framework,org.osgi.util.tracker Bnd-LastModified: Bundle-Version: SNAPSHOT Ignore-Package: com.osgiknowhow.hello.consumer.internal Bundle-Name: com.osgiknowhow.hello.consumer Bundle-Description: Generated using Pax-Construct Build-Jdk: 1.5.0_16 Private-Package: com.osgiknowhow.hello.consumer.internal Bundle-ManifestVersion: 2 Bundle-SymbolicName: com.osgiknowhow.hello.consumer Tool: Bnd Don’t ever write this file yourself Generate it

Blog: Twitter: Twitter: hab Activators Perform some functionality when a bundle is started and stopped Typically used to publish and/or consume services Should be quick...or else they’ll hold up the starting/stopping of a bundle

Blog: Twitter: Twitter: hab Versioning Bundles and packages can be versioned Can even be versioned independent from each other Multiple versions can be available simultaneously Packages can be imported by specifying a specific version, a version range, or no version at all (implying an infinite version range)

Blog: Twitter: Twitter: hab Services Bundle functionality encapsulated behind services Bundles can publish/consume services Identified by their interface(s) and optional parameters Publish programatically using bundle context Consume programatically using bundle context and service tracker Can be published/consumed declaratively Declarative Services, iPOJO, Spring-DM

OSGi without Spring-DM

Blog: Twitter: Twitter: hab Publishing services Done from an activator, via the bundle context: public final class HelloServiceActivator implements BundleActivator { public void start( BundleContext bc ) throws Exception { Dictionary props = new Properties(); bc.registerService(HelloService.class.getName(), new HelloServiceImpl(), props ); } public void stop( BundleContext bc ) throws Exception { }

Blog: Twitter: Twitter: hab Consuming services Done through an activator, via the bundle context and service activator: public final class HelloConsumerActivator implements BundleActivator { private ServiceTracker serviceTracker; public void start( BundleContext bc ) throws Exception { serviceTracker = new ServiceTracker(bc, HelloService.class.getName(), null); serviceTracker.open(); HelloService service = (HelloService) serviceTracker.waitForService(10000);... }... }

Blog: Twitter: Twitter: hab Yeah, but... We had to write an activator class We had to import org.osgi.* We had to work with the OSGi API directly There’s a lot of boilerplate code

Blog: Twitter: Twitter: hab Wouldn’t it be great if......we could eliminate the boilerplate?...we could declare services for publication and consumption?

Introducing Spring- DM

Blog: Twitter: Twitter: hab What Spring-DM offers... Declarative service model for OSGi The full facilities of the Spring framework Simplified OSGi web development with easy Spring MVC integration OSGi API...optional

Blog: Twitter: Twitter: hab Not the only game in town OSGi Declarative Services Apache Felix iPOJO DynamicJava’s ServiceBindingUtils Peaberry

Blog: Twitter: Twitter: hab The Spring-DM Extender “Allows other bundles to extend the functionality in a specific domain” Watches for bundles to be installed in OSGi Creates a Spring application context for Spring- enabled bundles By default, looks in META-INF/spring/*.xml Can be configured with Spring-Context: header Publishes Spring context as a service Can be disabled with “;public-context:=false”

Blog: Twitter: Twitter: hab Spring-DM Extender

Blog: Twitter: Twitter: hab Adding Spring-DM Your code typically doesn’t depend on Spring- DM Only need the Spring-DM extender bundle and a few Spring bundles Add them all with Pax Construct: % pax-import-bundle -g org.springframework.osgi \ ? -a spring-osgi-extender -v \ ? -- -DimportTransitive -DwidenScope

Blog: Twitter: Twitter: hab Spring-DM context xml Best kept separate from non-OSGi XML Supports OSGi-free testing of beans Best used as default namespace <beans:beans xmlns=" xmlns:beans=" xmlns:xsi=" xmlns:xsi=" xsi:schemaLocation="

Blog: Twitter: Twitter: hab Registering services Simplest form: Publish under multiple interfaces: com.osgiknowhow.beans.HelloService com.osgiknowhow.beans.GoodbyeService With service properties

Blog: Twitter: Twitter: hab Consuming services Simplest form: <reference id="helloBean" interface="com.osgiknowhow.beans.HelloService" /> Optional service reference: <reference id="helloBean" interface="com.osgiknowhow.beans.HelloService" cardinality="0..1" /> Specifying a filter: <reference id="helloBean" interface="com.osgiknowhow.beans.HelloService" filter="(mode=testing)" />

Spring-DM and the web

Blog: Twitter: Twitter: hab Web Bundles Just WAR files With an OSGi manifest Should be thin...no/few JARs in WEB-INF/lib And Bundle-ClassPath: header Bundle-ClassPath:.,WEB-INF/classes,WEB-INF/lib/hello.jar

Blog: Twitter: Twitter: hab Web Extenders Pax Web Extender Parses web.xml fileweb.xml Automatically registers servlets/filters/etc with HttpService Spring-DM Web Extender Doesn’t parse web.xml fileweb.xml Hands web bundle over to Tomcat/Jetty to deploy

Blog: Twitter: Twitter: hab A tale of two Spring contexts Spring-DM extender will create a web context for the web bundle Spring MVC will create another web context for the DispatcherServlet The controllers in the Spring MVC context won’t be able to see the service references in the DM- created context Unless...

Blog: Twitter: Twitter: hab OsgiBundleXmlWebApplicationContext contextClass org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContextweb.context.support.OsgiBundleXmlWebApplicationContext contextConfigLocation /WEB-INF/dude-osgi.xml org.springframework.web.context.ContextLoaderListener web.context.ContextLoaderListener dude org.springframework.web.servlet.DispatcherServlet web.servlet.DispatcherServlet contextClass org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContextweb.context.support.OsgiBundleXmlWebApplicationContext

Blog: Twitter: Twitter: hab You’ll need a few more bundles You’ll need the Spring-DM web extender and Spring MVC Using Pax Construct: pax-import-bundle -g org.springframework.osgi -a spring-osgi-web-extender -v pax-import-bundle -g org.springframework.osgi -a spring-osgi-web -v pax-import-bundle -g org.springframework -a spring-web -v 2.5.6

Blueprint Services

Blog: Twitter: Twitter: hab OSGi 4.2’s Blueprints AKA RFC-124: A component model for OSGi Suspiciously similar to Spring-DM Spring-DM is the reference implementation Also available outside of Spring

Blog: Twitter: Twitter: hab Blueprint Example <blueprint xmlns=" xmlns:ext=" default-activation="lazy"> <bean id="numberService" class="com.habuma.numbers.internal.NumberToEnglishServiceImpl" /> <service ref="numberService" interface="com.habuma.numbers.NumberToEnglishService" />

So what? What did OSGi buy us?

Blog: Twitter: Twitter: hab Each module can be... Developed independently Tested independently Understood independently Updated independently Swapped out for alternate implementations

Moving to OSGi Or...what do I do with this WAR file I already have?

Blog: Twitter: Twitter: hab Strategy 1. Convert full app into one large bundle a. Embed JARs (Use Bundle-ClassPath) b. Add Bundle-SymbolicName 2. Peel off dependencies one-by-one a. Start with 3rd party libraries b. Pull out proprietary modules

Blog: Twitter: Twitter: hab Converting Big Apps

Blog: Twitter: Twitter: hab Dealing with Legacy JARs BND Pax Construct: pax-wrap-jar or pax-embed-jar Find them in a bundle repository OBR SpringSource Enterprise Bundle Repository