OSGi Service Platform Open Service Gateway initiative.

49
OSGi Service Platform Open Service Gateway initiative

Transcript of OSGi Service Platform Open Service Gateway initiative.

OSGi Service Platform

Open Service Gateway initiative

Core Product

RBC

CIBC

ING

SYMCOR KINKOS...

... ...

Core Product 2.0

Core Product V 1.2

Core Product v1.0

RBC

CIBC IN

G

SYMCOR KINKOS...

... ...

Topics to cover

● Introduction

● Programming Model

Fundamentals Collaboration

● Eclipse Equinox

● Market Interests

What is OSGi?

● A specification of a component based service oriented platform

● A Java Framework for developing Service Applications that requires:

Reliability Large scale distribution Wide range of devices Collaborative development

● Created by collaboration of industry leaders (OSGi Alliance).

Industry Driven

● Home automation vendors (2000 - 2002)

● Automotive Infotainment and Telematics vendors (2002 - 2004)

● Mobile device vendors (2004 - now)

● Many other vertical markets (now)

Ever wonder...Eclipse IDE

QuantumPlugin

MylarPlugin

CommonsCollections

2.1.1

CommonsCollections

3.2

?

Original Motivations

● Binary software portability

Low reusability of software components● Software engineering is HARD

Software is complex Collaboration helps

● Deployment is error prone

Deployment scripts are often too complicated and unreliable Too much drama!!!

Fundamentals

Layering

Services

Life-cycle

Module (bundle)

Execution Environment

Applications

Security

Bundle

DictionaryService.jar (Bundle)

src

META-INF

lib

*.class

*.dll, *.so, etc...

*.jar

MANIFEST.MF

*.java

Bundles

● Packaging of Java library/service/application for deployment ( a jar file )

● Registers zero or more services

● Services (Java interfaces) may be implemented by multiple bundles

● Search for services registered via a (LDAP-based query language.

● Fragment bundles are like attachments to a bundle-host.

● Manifest contains important information about its bundle.

Manifest-Version: 1.0

Bundle-ManifestVersion: 2

Bundle-Name: DictonaryService Plug-in

Bundle-SymbolicName: DictonaryService

Bundle-Version: 1.0.0

Bundle-Activator: ca.intelliware.osgi.bundle.dictionary.Activator

Bundle-Localization: plugin

Import-Package: org.osgi.framework;version="1.3.0"

Export-Package: ca.intelliware.osgi.bundle.dictionary.service

Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0, OSGi/Minimum-1.1

MANIFEST.MF Sample

package ca.intelliware.osgi.bundle.dictionary;

import org.osgi.framework.BundleActivator;import org.osgi.framework.BundleContext;...import ca.intelliware.osgi.bundle.dictionary.service.DictionaryService;

public class Activator implements BundleActivator {

public void start(BundleContext context) throws Exception {Properties properties = new Properties();properties.put("Language", "English");

context.registerService(DictionaryService.class.getName(), new DictionaryServiceImpl(), properties);

}

public void stop(BundleContext context) throws Exception {}

}

<<BundleActivator>>

Registering a Servicepackage ca.intelliware.osgi.bundle.dictionary;

import org.osgi.framework.BundleActivator;import org.osgi.framework.BundleContext;import org.osgi.framework.ServiceRegistration;...import ca.intelliware.osgi.bundle.dictionary.service.DictionaryService;

public class Activator implements BundleActivator {

public void start(BundleContext context) throws Exception {Properties properties = new Properties();properties.put("Language", "English");

ServiceRegistration registration =

context.registerService(DictionaryService.class.getName(), new DictionaryServiceImpl(), properties);

}

public void stop(BundleContext context) throws Exception {}

}

Locating and using a Servicepublic class ClientActivator implements BundleActivator {

public void start(BundleContext context) throws Exception {

ServiceReference[] serviceReferences = context.getServiceReferences(DictionaryService.class.getName(),

"(Language=*)");...

ServiceReference firstServiceReference = serviceReferences[0];

DictionaryService service = (DictionaryService)context.getService(firstServiceReference);

if (service.checkWord(word)) {System.out.println(word + " was correct.");

} else {System.out.println(word + " was incorrect.");

}

context.ungetService(firstServiceReference);}

}

...

Listening to ServiceEventpublic class ServiceListenerActivator implements BundleActivator, ServiceListener {

public void start(BundleContext context) throws Exception {context.addServiceListener(this);

}

public void stop(BundleContext context) throws Exception {context.removeServiceListener(this);

}

public void serviceChanged(ServiceEvent event) {

int eventType = event.getType();String serviceName =

((String[])event.getServiceReference().getProperty("objectClass"))[0];

switch (eventType) {case ServiceEvent.MODIFIED:

System.out.println("service: " + serviceName + "has been modified.");

case ServiceEvent.REGISTERED:System.out.println("service: " + serviceName + "has been

registered.");case ServiceEvent.UNREGISTERING:

System.out.println("service: " + serviceName + "has been unregistered.");

default:break;

}}

}

Service Layer

● SOA Service Oriented Architecture Clarification:

OSGi Services != Web Services

OSGi Services are in-VM services

● Service Model

Services are POJO's in a bundle

Its interface is exported and registered in a Service Registry.

Discover and gets notified about services based on their interfaces and properties

Different bundles can register different implementations of the same interface.

● The OSGi Alliance provides many standardized services

Device Manager, Declarative Services, Event Admin, HTTP Service, Log Service, Metatype Service, Preferences Service, User Admin, Wire Admin, etc...

Life-cycle

Service

Execution

module

Demo

Life Cycle Layer

● Controlled by the System Bundle

● Provides an API for managing bundles

Install Resolve Start Stop Refresh Update Uninstall

Module

Life-cycle

Service

Execution

Life of a Bundle

Installed

Uninstalled

Resolved

Stopping

Starting

Active

Bundle

● Bundle started by an object of BundleActivator Type

● Manifest Header refer to this class

● BundleActivator Interface has 2 methods: start() and stop()

● BundleActivator gets a BundleContext provides access to the framework

● Framework provides Start Level Service to control start/stop of groups of applications

Traditional Class loading

User-DefinedClassLoader

User-DefinedClassLoader

SystemClassLoader

ExtensionClassLoader

Single Parent Delegation Model

BootstrapClassLoader

classpath

jre/ext

java.lang.*

Class loading OSGi StyleDelegation Model

BundleClassLoader

BundleClassLoader

BundleClassLoader

BundleClassLoader

ParentSystem

ClassLoader

SystemBundle

ClassLoader

importer Exporter

Bundle Space

Boot Classpath(java.lang.*)

Framework Classpath

Module Layer

● Applications and libraries are packaged in bundles (jar file)

● A classloader is assigned to each bundle for loading its classes and resources.

● Modularized Classloading

Traditional Single Parent Delegation Classloading model is inflexible

● Versioning

Raw Java cannot handle multiple versions of the same package

Life cycle

Module

Service

Execution

Manifest-Version: 1.0

Bundle-ManifestVersion: 2

Bundle-Name: DictonaryService Plug-in

Bundle-SymbolicName: DictonaryService

Bundle-Version: 1.0.0

Bundle-Activator: ca.intelliware.osgi.bundle.dictionary.Activator

Bundle-Localization: plugin

Import-Package: org.osgi.framework;version="1.3.0"

Export-Package: ca.intelliware.osgi.bundle.dictionary.service

Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0, OSGi/Minimum-1.1

MANIFEST.MF Sample

Execution Environments

● CDC-1.0/Foundation-1.0 Equals to J2ME Foundation Profile

● OSGi/Minimum-1.1 OSGi EE that is a minimal set that allows the implementation of an OSGi

Framework.

● JRE-1.1, J2SE-1.2, J2SE-1.3, J2SE-1.4● PersonalJava-1.1, PersonalJava-1.2● CDC-1.0/PersonalBasis-1.0

J2ME Personal Basis Profile

● CDC-1.0/PersonalJava-1.0 J2ME Personal Java Profile

Life-cycle

Execution

Service

Module

Programming Model

Object Oriented Model

● One of the challenges is managing dependencies, if we are not careful our objects can get quite tangled.

Object Oriented Model

● Coupling severely limits reuse.

Using a generic object can drag in a large number of other objects.

● Flexibility must be built by programmer

Plugin architectures

Service Oriented Architecture

● Separation of interface and implementation● Allows swapping in alternative implementation● Dynamically discover and bind object implementations● Components are not coupled with implementation

ClientComponent

ImplementationComponent

Service Contract

...

...

Framework

● Allows applications to share a single JVM

● Dynamic classloading

Dependencies are “wired” at runtime Compares to static classpaths

● Declarative Security

Java Security Model● Declarative bundle dependency

Coordinated via manifest headers● Independent life-cycle management of applications and

services on a single JVM instance.

Framework and Bundles

● The framework at bundle installation time:

Security check the bundle Reads the bundle's manifest Installs code and resources Resolve dependencies

● The framework at bundle runtime:

Calls the bundle's Activator to start the bundle Manages classpath Handles service dependencies Calls the bundle's Activator to stop the bundle

Layering – Bigger Picture

Courtesy of Michael Grammling

Collaborate or else...

Manifest-Version: 1.0

Bundle-ManifestVersion: 2

Bundle-Name: DictonaryService Plug-in

Bundle-SymbolicName: DictonaryService

Bundle-Version: 1.0.0

Bundle-Activator: ca.intelliware.osgi.bundle.dictionary.Activator

Bundle-Localization: plugin

Import-Package: org.osgi.framework;version="1.3.0"

Export-Package: ca.intelliware.osgi.bundle.dictionary.service

Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0, OSGi/Minimum-1.1

MANIFEST.MF Sample

Component Interaction

● Bundles collaborate through:

Service objects Package sharing

● Bundle Registry allows bundles to find and track service objects

● Framework manages the collaboration

Dependencies

● OSGi framework is a network of class loaders (one class loader per bundle).

● Complicated dependencies are “resolved” by the framework behind the scene.

CommonsCollections

Xerces

JavaMail

CommonsCollections-1.0

Xerces

Commons Collections CommonsCollections-2.0

version=1.0

version=2.0

Bundle

Exported package

imported package

Wire

Constraint

Equinox

What is Equinox

● Eclipse Project

Complete implementation of OSGi R4● Provides the base for Eclipse plug-in Architecture

Since Eclipse 3.0● Eclipse 3.2 provides additional services

Device Manager, HTTP Service, Log Service, Preferences Service, ...

● Eclipse Plug-in Development Environment (PDE) provides a environment for developing OSGi bundles.

Other OSGi implementations● ProSyst

● Knopflerfish

● Gatespace Telematics – KnopflerfishPro

● Eclipse - Equinox

● Objectweb - Oscar

● Apache - Felix

● Concierge

● Oxygen

● osxa

Bundle Repositories

● OSGi Alliance

http://bundles.osgi.org/Main/Repository● Oscar OBR

http://oscar-osgi.sourceforge.net● Knopflerfish bundle repository

http://www.knopflerfish.org/repo/index.html

Market Interests

OSGi +

●OSGi + BMW = iDrive (In-car Infotainment system)

●OSGi + Siemens VDO = RIO (In-car Infotainment system)

●OSGi + Websphere = Websphere Application Server (WAS) 6.1

●OSGi + JOnAS = JOnAS5

●OSGi + Spring = ?

... A much more comprehensive list of Markets and Solutions can be found at http://osgi.org/markets

My thoughts on OSGi

● Evolved WAY beyond the embedded markets● Version management● Encourages decoupling and collaboration● Encourages reuse● Think Product not Project● Important role technologies

OSGi + Portugese Chicken = Lunch & Learn

FIN

Questions?