Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Introduction to OSGi

An introduction to OSGi, the advanced modularization framework for Java.
by

Niclas Hedhman

on 23 October 2011

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Introduction to OSGi

OSGi
The advanced modularization framework for Java
Introduction
Bundles and Lifecycle
Service Layer
Module Layer
Classloading
Tying it altogether
Summary
What is OSGi?
The OSGi technology is a set of specifications that define a dynamic component system for Java. These specifications enable a development model where applications are (dynamically) composed of many different (reusable) components. The OSGi specifications enable components to hide their implementations from other components while communicating through services, which are objects that are specifically shared between components. This surprisingly simple model has far reaching effects for almost any aspect of the software development process.
Specifications - OSGi Alliance

Framework Implementations
* Apache Felix
* Eclipse Equinox
* Knopflerfish
* Commercial

Eco-System
* Mix-n-match Interoperability
* Large number of Bundles
* Collaboration & Competition
Hard Concepts
Coupling
Cohesion
Integration
More Problems
Granularity
Open Source Proliferation
Explosion of Dependencies
Incompatibilities between versions
Solution = OSGi
Encapsulation
Explicitly Versioned Dependencies
Well Specified Coupling
Component Re-use
"JAR Hell" reduced (not solved)
Services
Life Cycle
Modules
Bundles
Execution
Environment
Security
installed
resolved
started
stopped
uninstalled
Capabilities/Requirements
Import Package
Export Package

Dynamic Classloader
Profiles (CDC, Java SE,...)
Java Version
JDK Packages present
Ordinary JARs
Extended Manifest
Can contain JARs
May specify Bundle Activator
Standard Java Security
Fully Integrated in Module Layer
All system & framework services

Full sandboxing possible
Well-defined Service Model
In-JVM part of Core specification
Dynamic Services
Co-operative model
Applications
Single or Groups of Bundles
Independently deployed
Managed, Modular, Dynamic
Interoperable
Future-proof
Compendium
Services Specified for interop

Standard, Residential, Enterprise,
(Mobile, Vehicle)

Wide Range of Usecases
`
Today's Agenda
Code!!!
Bundle Activator
Registering a Service
Depend on a Service
Manifest
Communities
Eclipse
Apache
Pax
Others
The IDE is OSGi!
(but with extensions)

Eclipse Rich Client Platform

Virgo (formerly in Spring)
Many/most projects are OSGi-fied

Felix, Karaf, Aries, ServiceMix,
CXF-Distributed OSGi, Geronimo,
James
Runner - Simplifies running frameworks

Exam - Integration Test Kit

Logging - Implements Logging APIs and
provide pluggable back end.

Web - OSGi Http Service + standard WAR
deployment

Tinybundles - Deploy ordinary JARs
Spring Framework - OSGi from 2.5

BND tool - management of Import/Export

Websphere, Glassfish, Weblogic, Jonas

BMW

Medical and other Equipment
package org.hedhman.niclas.foo;

import org.osgi.framework.BundleActivator;

public class MyActivator
implements BundleActivator {

public void start() throws Exception {

}

public void stop() throws Exception {

}
}
Bundle-Activator: org.hedhman.niclas.foo.MyActivator
Import-Package: org.osgi.framework
Manifest Entries
public class MyServiceTracker
extends ServiceTracker, MyUsage {

private MyUsage service;

public MyServiceTracker(BundleContext context) {
super( context, MyUsage.class.getName(), null );
}

@Override
public Object addingService( ServiceReference ref ) {
// Service looking for is available
this.service = context.getService( ref );
return this.service;
}

@Override
public void removedService( ServiceReference ref, Object service ) {
bundleContext.ungetService( ref );
this.service = null;
}
:
}

private ServiceRegistration registration;

public void start( BundleContext context ) throws Exception {

MyService service = new MyService();
Properties props = new Properties();
props.put( ... );
String objectClass = MyService.class.getName();
registration = context.registerService( objectClass, service, props );

}

public void stop( BundleContext context ) throws Exception {

registration.unregister();

}
Specifying Service
* Classname direcly, e.g. Foo.class.getName()

* LDAP expression, e.g. &(location=shanghai)(floor=17)

* Filter implementation, e.g

public class FooFilter
implements org.osgi.framework.Filter {

// 6(!) methods to implement
}
Run It!
hedmni> pax-run.sh --platform=felix scan-dir:bundles

Pax Runner (1.6.1) from OPS4J - http://www.ops4j.org
----------------------------------------------------

-> Using config [classpath:META-INF/runner.properties]
-> Using only arguments from command line
-> Preparing framework [Felix 3.0.6]
-> Downloading bundles...
-> Felix 3.0.6 : 402676 bytes @ [ 25kBps ]
-> Apache Felix Gogo Command (0.6.1) : 45464 bytes @ [ 18kBps ]
-> Apache Felix Gogo Runtime (0.6.1) : 63071 bytes @ [ 21kBps ]
-> Apache Felix Gogo Shell (0.6.1) : 48763 bytes @ [ 14kBps ]
-> Using execution environment [J2SE-1.6]
-> Runner has successfully finished his job!

____________________________
Welcome to Apache Felix Gogo

g!
g! lb
START LEVEL 6
ID|State |Level|Name
0 |Active | 0|System Bundle (3.0.6)
1 |Active | 1|Apache Felix Gogo Command (0.6.1)
2 |Active | 1|Apache Felix Gogo Runtime (0.6.1)
3 |Active | 1|Apache Felix Gogo Shell (0.6.1)
g!
hedmni>pax-run.sh --profiles=web


Pax Runner (1.6.1) from OPS4J - http://www.ops4j.org
----------------------------------------------------

-> Using config [classpath:META-INF/runner.properties]
-> Using only arguments from command line
-> Scan bundles from [scan-composite:mvn:org.ops4j.pax.runner.profiles/web//composite]
-> Scan bundles from [scan-composite:mvn:org.ops4j.pax.runner.profiles/log//composite]
-> Scan bundles from [scan-bundle:mvn:org.apache.felix/org.apache.felix.configadmin/1.2.8]
-> Scan bundles from [scan-bundle:mvn:org.ops4j.pax.logging/pax-logging-api/1.6.1]
-> Scan bundles from [scan-bundle:mvn:org.ops4j.pax.logging/pax-logging-service/1.6.1]
-> Scan bundles from [scan-bundle:mvn:org.ops4j.pax.web/pax-web-jetty-bundle/1.0.2]
-> Scan bundles from [scan-bundle:mvn:org.ops4j.pax.web/pax-web-spi/1.0.2]
-> Provision bundle [mvn:org.apache.felix/org.apache.felix.configadmin/1.2.8, at default start level, bundle will be started]
-> Provision bundle [mvn:org.ops4j.pax.logging/pax-logging-api/1.6.1, at default start level, bundle will be started]
-> Provision bundle [mvn:org.ops4j.pax.logging/pax-logging-service/1.6.1, at default start level, bundle will be started]
-> Provision bundle [mvn:org.ops4j.pax.web/pax-web-jetty-bundle/1.0.2, at default start level, bundle will be started]
-> Provision bundle [mvn:org.ops4j.pax.web/pax-web-spi/1.0.2, at default start level, bundle will be started]
-> Preparing framework [Felix 3.0.6]
-> Downloading bundles...
-> mvn:org.apache.felix/org.apache.felix.configadmin/1.2.8 : 94688 bytes @ [ 198kBps ]
-> mvn:org.ops4j.pax.logging/pax-logging-api/1.6.1 : 94913 bytes @ [ 221kBps ]
-> mvn:org.ops4j.pax.logging/pax-logging-service/1.6.1 : 541711 bytes @ [ 207kBps ]
-> mvn:org.ops4j.pax.web/pax-web-jetty-bundle/1.0.2 : 2366473 bytes @ [ 171kBps ]
-> mvn:org.ops4j.pax.web/pax-web-spi/1.0.2 : 44811 bytes @ [ 181kBps ]
-> Using execution environment [J2SE-1.6]
-> Runner has successfully finished his job!

org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator] : Enabling SLF4J API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator] : Enabling Jakarta Commons Logging API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator] : Enabling Log4J API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator] : Enabling Avalon Logger API support.
org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.logging.internal.Activator] : Enabling JULI Logger API support.
[FelixDispatchQueue] DEBUG org.ops4j.pax.logging.pax-logging-service - BundleEvent STARTED
____________________________
Welcome to Apache Felix Gogo

g! lb
START LEVEL 6
ID|State |Level|Name
0 |Active | 0|System Bundle (3.0.6)
1 |Active | 5|Apache Felix Configuration Admin Service (1.2.8)
2 |Active | 5|OPS4J Pax Logging - API (1.6.1)
3 |Active | 5|OPS4J Pax Logging - Service (1.6.1)
4 |Active | 5|OPS4J Pax Web - Jetty Bundle (1.0.2)
5 |Active | 5|OPS4J Pax Web - Service SPI (1.0.2)
6 |Active | 1|Apache Felix Gogo Command (0.6.1)
7 |Active | 1|Apache Felix Gogo Runtime (0.6.1)
8 |Active | 1|Apache Felix Gogo Shell (0.6.1)
g!
Q & A
Manifest-Version: 1.0
Export-Package: org.ops4j.pax.logging.spi;provider=paxlogging;version=
"1.6.1"
Built-By: gnodet
Tool: Bnd-0.0.357
Bundle-Name: OPS4J Pax Logging - Service
Created-By: Apache Maven Bundle Plugin
Bundle-Vendor: OPS4J - Open Participation Software for Java
Build-Jdk: 1.6.0_22
Bundle-Version: 1.6.1
Bnd-LastModified: 1298446880527
Bundle-Activator: org.ops4j.pax.logging.service.internal.Activator
Bundle-ManifestVersion: 2
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.html
Bundle-Description: Pax Logging Service is a Log4J driven service that
supports Jakarta Commons Logging, Log4J, Avalon Logging, SLF4J an
d Pax Logging clients. Note that all this clients must use the Pax Lo
gging Client library in the proper way. See documentation for deta
ils.
Bundle-DocURL: http://www.ops4j.org/projects/pax/logging/pax-logging-s
ervice
Bundle-SymbolicName: org.ops4j.pax.logging.pax-logging-service
Import-Package: com.ibm.uvm.tools;resolution:=optional,com.sun.jdmk.co
mm;resolution:=optional,javax.jmdns;resolution:=optional,javax.jms;re
solution:=optional,javax.mail;resolution:=optional,javax.mail.interne
t;resolution:=optional,javax.management;resolution:=optional,javax.na
ming;resolution:=optional,javax.swing;resolution:=optional,javax.swin
g.border;resolution:=optional,javax.swing.event;resolution:=optional,
javax.swing.table;resolution:=optional,javax.swing.text;resolution:=o
ptional,javax.swing.tree;resolution:=optional,javax.xml.parsers,org.a
pache.avalon.framework.logger;version="4.3",org.apache.commons.loggin
g;version="1.1",org.apache.juli.logging;version="1.0",org.knopflerfis
h.service.log;provider=paxlogging;version="[1.1.0,2.0.0)",org.ops4j.p
ax.logging;version="[0.9.5,2.0.0)",org.ops4j.pax.logging.avalon;versi
on="1.6",org.ops4j.pax.logging.slf4j;version="1.6",org.ops4j.pax.logg
ing.spi;provider=paxlogging;version="1.6",org.osgi.framework;version=
"[1.0.0,2.0.0)",org.osgi.service.cm;version="[1.0.0,2.0.0)",org.osgi.
service.event;resolution:=optional;version="[1.0.0,2.0.0)",org.osgi.s
ervice.log;version="[1.3.0,2.0.0)",org.osgi.util.tracker;version="[1.
3.0,2.0.0)",org.slf4j;version="1.6",org.w3c.dom,org.xml.sax,org.xml.s
ax.helpers
Embed-Dependency: log4j;inline=true
Classes
Manifest
JARs
Resources
Bundle
Apache Felix
Compliant OSGi 4.3 Framework

Implementation of Compendium Specs

Additional useful components
Config Admin
Dependency Manager
Event Admin
File Install
Gogo
Http Service
iPOJO
Log
Maven Bundle Plugin
Maven SCR Plugin
Metatype
OSGi Bundle Repository
Preferences
Remote Shell
UPnP
Web Console
Subprojects
Downstream
Apache Karaf
Apache Aries
Apache ServiceMix
Apache Sling
Apache Geronimo 3 (beta)

ObjectWeb Jonas
EasyBeans
Module Fusion
Oracle Glassfish
Netbeans
Spring Roo
Project Fuji in Open ESB
SIP Communicator
This presentation was hardcoded in Java!!
Just kidding!!
http://www.prezi.com/jvgu71vhlug5


http://google.com/search?q="introduction+to+osgi"+Niclas
Niclas Hedhman
Live & Work in Malaysia - 1986-2009, 2014
Previously in Shanghai - 2010-2014

Apache Contributor - 1997
Apache Committer - 2002
Apache Member - 2007

OPS4J / Pax - 2005
Qi4j - 2007 (Now Apache Zest)

JSR-78 - 2000
JSR-291 - 2006
Full transcript