Modular Java Applications with Spring, dm Server and OSGi

Similar documents
OSGi. Building LinkedIn's Next Generation Architecture with OSGI

Building LinkedIn's Next Generation Architecture with OSGI

OSGi on the Server. Martin Lippert (it-agile GmbH)

Patterns and Best Practices for dynamic OSGi Applications

Agenda. Why OSGi. What is OSGi. How OSGi Works. Apache projects related to OSGi Progress Software Corporation. All rights reserved.

Using Apache Felix: OSGi best practices. Marcel Offermans luminis

Introduction to OSGi. Marcel Offermans. luminis

Tuscany: Applying OSGi modularity after the fact

Patterns and Best Practices for Dynamic OSGi Applications

Christopher Frost Virgo Committer Martin Lippert Lead, Spring Development Tools SpringSource, a division of VMware 3rd November 2011

OSGi & Spring combined

Spring Dynamic Modules

Developing Java Applications with OSGi Capital District Java Developers Network. Michael P. Redlich March 20, 2008

OSGi in Action. RICHARD S. HALL KARL PAULS STUART McCULLOCH DAVID SAVAGE CREATING MODULAR APPLICATIONS IN JAVA MANNING. Greenwich (74 w. long.

Equinox OSGi: Pervasive Componentization

OSGi Best Practices. Emily

Learning Karaf Cellar

Breaking Apart the Monolith with Modularity and Microservices CON3127

ESB, OSGi, and the Cloud

Creating an application with the Virgo Web Server

Apache Felix. Richard S. Hall. A Standard Plugin Model for Apache. Atlanta, Georgia U.S.A. November 13th, 2007

1.2. Name(s) and address of Document Author(s)/Supplier: Sahoo: 1.3. Date of This Document: 12 July 2008

Modularity in Java. With OSGi. Alex Docklands.LJC January Copyright 2016 Alex Blewitt

Enterprise Development

Jigsaw and OSGi: What the Heck Happens Now?

WebSphere Application Server Support for OSGi Applications

Creating an application with dm Server

Copyright Oracle Corporation and VMware Inc, Enterprise Modules Project (Gemini) Proposal

OSGi in Action. Ada Diaconescu

OSGi Subsystems from theory to practice Glyn Normington. Eclipse Virgo Project Lead SpringSource/VMware

Liberate your components with OSGi services

Equinox Project Update

Creating an application with dm Server

OSGi in WebSphere : The Story so far

Java Modularity Support in OSGi R4. Richard S. Hall ApacheCon (San Diego) December 14 th, 2005

Carsten Ziegeler

OSGi. Building and Managing Pluggable Applications

Leverage Rational Application Developer v8 to develop OSGi application and test with Websphere Application Server v8

Camel User Guide. Apache ServiceMix Version 4.5.0

Service Discovery and Remote Services with the Eclipse Communication Framework

OSGi Cloud Ecosystems. David Bosschaert Principal Engineer, JBoss/Red Hat March 2013

7. Component Models. Distributed Systems Prof. Dr. Alexander Schill

Spring Interview Questions

Modular Java EE in the cloud

Using OSGi in Modular WebSphere Applications

Component-based Runtime Environment for Cloud Applications

Spring Framework 2.5: New and Notable. Ben Alex, Principal Software Engineer, SpringSource

2017, IBM Corporation Liberty z/os Good Practices. WebSphere Liberty z/os Applications and Application Deployment

Managing Installations and Provisioning of OSGi Applications. Carsten Ziegeler

SpringSource dm Server User Guide

OSGi and Equinox. Creating Highly Modular Java. Systems

Spring and OSGi. Martin Lippert akquinet agile GmbH Bernd Kolb Gerd Wütherich

OSGi In Action: Creating Modular Applications In Java By Richard Hall, Karl Pauls READ ONLINE

CS486: Tutorial on SOC, OSGi, and Knopflerfish. Ryan Babbitt (props to Dr. Hen-I Yang, CS415X) Feb. 3, 2011

NetBeans IDE Field Guide

OSGi Application Development using GlassFish Server. Version 1.0

Oracle 10g: Build J2EE Applications

SCA Java Runtime Overview

BEAWebLogic. Event Server. Creating WebLogic Event Server Applications

Extensibility, Componentization, and Infrastructure

Scripting Languages in OSGi. Thursday, November 8, 12

Fast Track to Spring 3 and Spring MVC / Web Flow

Apache Felix Shell. Apache Felix Shell. Overview. How the Shell Service Works. package org.apache.felix.shell;

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

Web Application Development Using JEE, Enterprise JavaBeans and JPA

Exam Questions 1Z0-895

Enterprise Java in 2012 and Beyond From Java EE 6 To Cloud Computing

Virgo Web Server User Guide

Platform SDK Deployment Guide. Platform SDK 8.1.2

Red Hat JBoss Fuse Service Works Integration Recipes, Best Practices & Cheat Codes

Java- EE Web Application Development with Enterprise JavaBeans and Web Services

SDN controller: Intent-based Northbound Interface realization for extended applications

IBM Rational Software

Microservices Beyond the Hype. SATURN San Diego May 3, 2016 Paulo Merson

IBM. IBM WebSphere Application Server Migration Toolkit. WebSphere Application Server. Version 9.0 Release

BUILDING MICROSERVICES ON AZURE. ~ Vaibhav

Web Application Development Using JEE, Enterprise JavaBeans and JPA

G l a r I m y Presentation on

WebSphere Application Server V8 New Features and a primer on WAS V8.5

Create your own Carbon Component. Sameera Jayasoma Technical Lead and Product Manager of WSO2 Carbon

CONFIGURING A SPRING DEVELOPMENT ENVIRONMENT

Comparing JavaBeans and OSGi

Distributed OSGi Services with the Eclipse Communication Framework. Jan S. Rellermeyer, ETH Zürich Markus Kuppe, Versant Inc.

JSR 277, 291 and OSGi, Oh My! - OSGi and Java Modularity

Com S/Geron 415X Gerontechnology in Smart Home Environments Lecture 9 Intro to Service Computing. Dr. Hen-I Yang ComS Dept., ISU

Spring Soup with OC4J and MBeans

IBM WebSphere Application Server 8. Java EE 6 Feature Packs

Java Architectures A New Hope. Eberhard Wolff

Demystifying OSGi bundles Excerpted from

Microservices with Apache Karaf and Apache CXF: practical experience. Andrei Shakirin, Talend

Is OSGi Modularity Always Worth It? Glyn Normington

WSO2 Platform Offerings for Developers

Bernhard Dorninger Software Competence Center Hagenberg. Experiences with OSGi in industrial applications

Tattletale. What is Tattletale? Enterprise archives JBoss Application Server 7 Putting it all together Roadmap

Under the Paul Fremantle, CTO, WSO2

Java Platform, Enterprise Edition 6 with Extensible GlassFish Application Server v3

JBoss Tattletale. Betraying all your project's naughty little secrets

GlassFish V3. Jerome Dochez. Sun Microsystems, Inc. hk2.dev.java.net, glassfish.dev.java.net. Session ID YOUR LOGO HERE

Nexus for Component Management. Nexus for Component Management

J2EE Interview Questions

Transcription:

Modular Java Applications with Spring, dm Server and OSGi Copyright 2005-2008 SpringSource. Copying, publishing or distributing without express written permission is prohibit

Topics in this session Introduction OSGi basics OSGi & Spring Enterprise OSGi Modularization Best Practices dm Server 2 Summary 2

Introduction OSGi: a dynamic module system for Java Modular: Bundles, JAR files with meta-data Strict visibility for types, based on packages Versioning of both packages and bundles Dynamic: Add, remove, start, stop bundles at runtime Use shared services to share objects, not just types 3

History of OSGi Open Specification managed by OSGi Alliance Founded in March 1999 Based on the realized need for light weight dynamic platform Initially targeted network and embedded devices Since 2006, server side adoption Member companies IBM, SpringSource, Motorolla, Oracle, Tibco etc... 4

Topics in this session Introduction OSGi basics OSGi & Spring Enterprise OSGi Modularization Best Practices Summary 5

Bundle MANIFEST.MF Bundles use JAR Manifest for meta-data Manifest-Version: 1.0 Bundle-Version: 1.0.0 Bundle-Name: My First Bundle Bundle-ManifestVersion: 2 Bundle-SymbolicName: my.first.bundle... By default, such a bundle is a black box Its types are invisible to other bundles It can't see any types besides its own 6

Inter-bundle Visibility: Exports To make types available to other bundles, export their packages Export-Package: my.first.bundle.api Can also version the package(s) Export-Package: my.first.bundle.api;version=1.0.0, my.first.bundle.util;version=1.2.3 7

Exporting Best Practices Best practice: separate interfaces from implementations Put in different packages Only export public API, hide internal details Expose implementations as services Best Practice: apply versions to your packages Allows multiple versions in the same runtime Clients can pick the version they need 8

Inter-bundle Visibility: Imports To access types from other bundles, import their packages Bundle-SymbolicName: some.client.bundle Import-Package: my.first.bundle.api Can also specify version range Import-Package: my.first.bundle.api;version="[1.0.0, 2.0.0)" Single version means 'at least' [] for inclusive, () for exclusive boundaries Best practice: pick good version range What versions will work? Too narrow or wide? 9

OSGi Visibility Adds true encapsulation and versioning to your applications Preserves modularity at runtime No longer restricted to a single, linear classpath Each bundle gets its own ClassLoader All managed by the OSGi container 10

OSGi Containers Provide the runtime for OSGi bundles Small core with additional services Typically very lightweight Well-known OSS implementations: Equinox Apache Felix Knopflerfish 11

OSGi Dynamics Bundles can be installed into container Have a managed lifecycle Installed (just present, missing dependencies) Resolved (stopped, all dependencies satisfied) Starting Started (services now also available) Stopping Uninstalled (gone after restart or refresh) 12

OSGi Lifecycle Bundles can receive callbacks when started or stopped public class MyActivator implements BundleActivator { public void start(bundlecontext context) throws Exception { //... } public void stop(bundlecontext context) throws Exception { // } } Register in manifest Bundle-Activator: some.client.bundle.myactivator 13

OSGi BundleContext BundleContext is API of OSGi runtime Work with bundles and services (un)install, start/stop bundles Register services and obtain references Register listeners to be notified of interesting events 14

DEMO Using plain OSGi bundles to share types and services Copyright 2005-2008 SpringSource. Copying, publishing or distributing without express written permission is prohibit

Topics in this session Introduction OSGi basics OSGi & Spring Enterprise OSGi Modularization Best Practices dm Server 2 Summary 16

OSGi & Spring OSGi provides nice runtime but lacks component model Spring provides component model but does not define the runtime Spring Dynamic Modules marries the two Use familiar Spring programming model in OSGi! 17

Spring Dynamic Modules (or Spring-DM for short) Removes most OSGi-dependencies from your code Best Practice: Proper Separation of Concerns Creates ApplicationContext per bundle Declarative service management And much more 18

Spring-DM Service Management Exposes Spring beans as services Full control over interface, properties, etc. Creates proxies for service references No more manual management of service dynamics! Saves lots of plumbing code in a typical Spring fashion 19

Spring-DM Configuration Spring config files go in META-INF/spring Will be picked up automatically osgi: namespace for service export/ref <bean id="myservice" class="some.bundle.internal.myserviceimpl"> <property name="servicedependency" ref="servicedependency"/> </bean> <!-- Creates dynamic proxy for OSGi service with given interface --> <osgi:reference id="servicedependency" interface="other.bundle.servicedependency"/> <!-- Exposes our Spring bean as OSGi service under its interfaces --> <osgi:service ref="myservice" interface="some.bundle.myservice"/> 20

Spring-DM Configuration Best Practice: Separate normal Spring config files from Spring-DM config files Test or even reuse of modules without OSGi Esp. if ids of beans backing services are the same as <osgi:reference> ids Bundle A, file module-context.xml: <bean id="myservice" class="samples.internal.myserviceimpl"/> Bundle A, file osgi-context.xml: <osgi:service ref="myservice" interface="samples.myservice"/> Bundle B, file module-context.xml: <bean id="myclient" class="..."> <constructor-arg ref="myservice"/> </bean> Bundle B, file osgi-context.xml: <osgi:reference id="myservice" interface="samples.myservice"/> 21

DEMO Using Spring Dynamic Modules to share types and services Copyright 2005-2008 SpringSource. Copying, publishing or distributing without express written permission is prohibit

Topics in this session Introduction OSGi basics OSGi & Spring Enterprise OSGi Modularization Best Practices dm Server 2 Summary 23

Enterprise OSGi OSGi features are appealing to Enterprise Java developers as well True modules instead of monolithic deployments True dynamics that don't require constant restarts Most applications servers already use OSGi internally 24

Enterprise OSGi Issues Pure OSGi doesn't mix with Enterprise Java very well Incompatible classloading models OSGi has hardly any web support Bunch of bundles is not a good deployment model Enterprise Libraries not available as bundles New products and standards are emerging to address this 25

Enterprise OSGi Products SpringSource dm Server Pioneered OSGi in an Enterprise Java setting Web Support, Thread Context Classloader mgmt, PAR deployment format, Bundle provisioning,... Paremus Service Fabric SCA Support Advanced clustering / cloud capabilities Various Open Source Projects Apache Aries OPS4J PAX has several relevant projects 26

Enterprise OSGi Standards Enterprise Expert Group produces new specifications RFC 66: Web Support (RI: dm Server 2.0) RFC 112: Bundle Repository RFC 119: Distributed OSGi RFC 124: Blueprints (RI: Spring-DM 2.0) RFC 139: JMX interface for OSGi RFC 142: JNDI integration At the same time, much innovation is happening 27

Enterprise OSGi Best Practice: Enterprise OSGi is harder than you think, don't build your own platform Getting e.g. JPA libraries to work reliably is very challenging Think about runtime management as well Check your options and choose for yourself based on your requirements Obviously we prefer dm Server 28

DEMO Developing a multi-bundle web application with SpringSource dm Server Copyright 2005-2008 SpringSource. Copying, publishing or distributing without express written permission is prohibit

Topics in this session Introduction OSGi basics OSGi & Spring Enterprise OSGi Modularization Best Practices dm Server 2 Summary 30

Best Practices So much for the tech talk, but how do you apply this? Some best practices were given already Here follows some more high-level advice on how to design your modules 31

How To Modularize How to split up your application in bundles is not an easy question to answer Question is really how to partition and what granularity to use 32

Partitioning Into Bundles Partitioning can be done in different ways: Vertical: functional partitioning For example orders, warehouse, billing and CRM Horizontal: technical partitioning Web, services, repositories, infrastructure A combination of the two 33

Vertical Partitioning Bundles represent functional modules Preferred approach for big enough applications Single module assignable to a team of developers Encapsulates internals like repositories OrderRepository only needed in 'order' module Minimizes module's surface area Only needs to expose its business interfaces Might not work well for small applications Might not need partitioning in the first place 34

Horizontal Partitioning Bundles represent architectural layers Natural approach to many developers Tend to think of layers as modules already Allows for replacing layers easily For testing or during early development Deploy stubbed repository bundle without changing services module Typically means more maintenance Use cases spread across multiple bundles So changes often span bundle boundaries 35

Web Modules Web Resources like JSPs cannot be split across multiple bundles in dm Server 1.0 Not for single ServletContext / HttpSession at least Must use single WAR / web module Even when using vertical partitioning! dm Server 2.0 will offer slices support Allowing for truly modular web applications 36

Infrastructure Bundles Most applications use shared infrastructure across functional, vertical slices Same DataSource, transaction manager, JMS ConnectionFactory, etc. Creating infrastructure bundle(s) makes sense Even when using vertical partitioning: there's no JNDI registry with globally defined resources! Simply expose resources as OSGi services By application developers or operations team 37

Bundle Granularity (1) How much stuff goes in one bundle Use same rules as for object orientation Bundles need to have a clear responsibility High cohesion within a bundle Loose coupling between bundles Works well with vertical partitioning Horizontal tends to increase dependencies between bundles 38

Bundle Granularity (2) Easy to make modules too fine-grained Often seen in samples and labs To show how OSGi works Doesn't necessarily represent best practice! Better to extract extra bundle later if desired Typically shouldn't create bundle if non- OSGi application wouldn't have dedicated jar for the same code 39

Topics in this session Introduction OSGi basics OSGi & Spring Enterprise OSGi Modularization Best Practices dm Server 2 Summary 40

See dm Server 2 Presentation Copyright 2005-2008 SpringSource. Copying, publishing or distributing without express written permission is prohibit

Topics in this session Introduction OSGi basics OSGi & Spring Enterprise OSGi Modularization Best Practices dm Server 2 Summary 42

Summary OSGi brings true modularity and dynamics to your applications Many potential benefits, but not always easy to gain these Enterprise OSGi is an upcoming area of great interest to many developers New products and standards new emerging 43