Seite 1
CS5233Components – Models and Engineering(Komponententechnologien) Master of Science (Informatik)
OSGI - Introduction
Prof. Dr. Th. Letschert
Seite 2
OSGI – what, why and who
What OSGi stands for
once: OSGi : Open Service Gateway Initiative
now: OSGi is a name for a Dynamic Module System for Java
Slides on OSGi are based on
– OSGi Alliance: OSGi Service Platform Core Specification OSGi 2009
– J. McAffer, P. Vanderlei, S. Archer: OSGi and Equinox, Addison-Wesley 2010
– Wütherich/Hartmann/Kolb/Lübken, Die OSGI Service Platform – Dpunkt Verlag, 2008
Seite 3
OSGI – what, why and who
What OSGi is:
OSGi is about building systems from components
OSGi - Componentswork together in a systemcan be managed (installed / removed)
… at runtime
Seite 4
OSGI – what, why and who
What OSGi is:
OSGi is a component framework for Java
OSGi-componentsare called bundlesare units of resourcescan be installedhave managed mutual dependenciesare independent units can export services and run processesrun in an OSGi-container
Seite 5
OSGI – what, why and who
What OSGi is:
OSGi is a (a set of) specification(s)
by the OSGi-Alliance (founded 1999)with wide adoption outside the alliance
developed in expert groupsCore platform (CPEG)
Vehicle (VEG) OSGi in vehicles
Mobile (MEG) OSGi in mobile devices
Enterprise (EEG) OSGi in enterprise solutions
Residential (REG) OSGi in home automation
structured into 2 documentsCore Specification : frameworkService Compendium : standard services
actual version 4.1
Alcatel-Lucent Aplix Corporation
Deutsche Telekom
Ericsson Mobile Platforms AB Hitachi, Ltd.
IBM Corporation LinkedIn
Makewave
Mitsubishi Electric Corporation NEC Corporation
NTT
Oracle Corporation Paremus, Ltd.
Progress Software ProSyst Software GmbH
Qualcomm
Red Hat SAP AG
Siemens AG Siemens Enterprise Communications
Software AG
Sonatype Inc. SpringSource (a Division of VMware)
Sun Microsystems, Inc.
Telcordia Technologies, Inc. TIBCO Software Inc.
Westell Inc.
http://www.osgi.org
Seite 6
OSGI – what, why and who
Where OSGi came from
Requirement for a component model for devices
Installable Software services Software deployment and management Security
Originally aimed at home automation Set top boxes, DSL-Modems, ··· building equipment and
appliances
Used in several areas for years automotive mobile devices
Adopted by Eclipse for Eclipse 3.0
Currently widespread useOSGi Scenario: Refrigerator that runs
software form different vendors. Each of them may independently install new
version of software modules.
Seite 7
OSGI – what, why and who
OSGi and Java
OSGi has a focus on Java
Bundles usually contain class-files
Bundles may contain JNI code e.g. SWT-bundles in Eclipse
Communication with non-Java devises is possible
Script language support may be provided
Java execution environmentRequirements on a JVM to support OSGi framworksfulfilled by several JVMs (SE und ME)
related JSRs:JSR 232: Mobile operational ManagementJSR 291: Dynamic component support for Java SE
Seite 8
OSGI – what, why and who
OSGi and Eclipse
Eclipse is a main adopter of OSGi
Eclipse and OSGi in 2003 OSGi: a consortium of vendors in the area of embedded systems with the aim to
provide a platform for inter-vendor compatible components called bundles.
Eclipse: a consortium of vendors in the area of software tools with the aim to provide a platform for inter-vendor compatible components called plugins.
2003: Eclipse Project Equinox initiated Aim: Resolve problems of Eclipse's runtime behavior
Leverage of (then) current work on management and provisioning Available technologies considered
JMX Java Management Extensions Avalon Component framework : Apache project, 1999 – 2004, still active
follower projects eg. Excalibur
OSGi Decision to use OSGi
A number of changes and extension of the OSGi specification where developed Based on IBMs OSGi-Impl. SMF (Service Management Framework),
Equinox runtime was developed and replaced Eclipse runtime
Seite 9
OSGI – what, why and who
OSGi and Eclipse
Eclipse and OSGi together changed the (software) world
Eclipse ~> OSGi OSGi: from niche to mainstream:
a mature good technology became the marketing it deserved OSGi got a complete new market: all mayor Java application server are (or are in
the process of being) ported to OSGi
OSGi ~> Eclipse gain of a mature component model Eclipse/Equinox adoption outside Eclipse (embedded systems)
OSGi + Eclipse Proof for everyone: Working runtime component systems can exist
OSGi is not the first component system but it is the first with wide range of followers
OSGi's original target market - “home gateways” - never where of any relevance but the strict constraints of them forced the development of a technology of widespread usage
Seite 10
OSGI – what, why and who
OSGi Survey
Service platform: Container, Bundles, Services
OSGi Service Platform: Component technology consisting of
Bundle ~ ComponentSet of classes and resources that
have defined interfaces (provided / used services)may be installed (deployed) / de-installed at runtime
Service ~ Component interfaceServices are provided by bundles that register them with the container
Services are used by bundles that request them from the container
Some Services are standard-services provided by the container
Container ~ OSGi FrameworkRuntime environment for bundles
Life-cycle management of bundles
Service-management
Provider of standard services
Seite 11
OSGI – what, why and who
OSGi Survey
OSGi application
A set of bundles each bundle may contribute in any way:provide libraries, start threads, open sockets, open DBs, ····
no “main”-bundle: all bundles are peers
no hierarchy: no bundle within a bundle
Bundle A
Bundle DBundle C
Bundle B
OSGi-Application
Seite 12
OSGI – what, why and who
OSGi Survey
OSGi application vs Java application
OSGi-Application: A set of bundles with mutual dependencies declared and resolved through defined interfaces
Java application: Dependencies are between (more granule) classes. They are declared using class-names and resolved using names, the position of a package / jar within the classpath, the loader that was used to load the using class, the loader that was used to load the used class, ···
Bundle A
Bundle DBundle C
Bundle B
OSGi-Application Java-Application
Jar
package
class
Seite 13
OSGI – what, why and who
OSGi Survey
Logical Layers according to the OSGi Specification
Module LayerDefines bundles: the basic components
Life-cycle Management LayerLife-cycle of bundles: states, actions, state transitions
Service LayerService definition, how to provide or use services
Security LayerSecurity related definitions
Execution Environment
Module Layer
Lifecycle Mngmt
Service Layer
Securty
ServicesOSGiFramework
Seite 14
OSGI – what, why and who
OSGi adoption
OSGi is a technology for enterprise servers
Enterprise servers based on OSGi➢ IBM WebSphere Application Server ➢ Sun Glassfish V3➢ Oracle WebLogic Server ➢ Redhat JBoss➢ SAP Netweaver Application Server (announced) ➢ ···
Seite 15
OSGI – what, why and who
OSGi adoption
OSGi is a technology for automotive electronics
➢ BMW➢ Bombardier➢ Siemens VDO ➢ Volvo➢ Windriver ➢ ···
Seite 16
OSGI – what, why and who
What do you need:
an OSGi container (open source examples):➢ Equinox
OSGi-container implementation developed and used by Eclipse
➢ Apache FelixOSGi-container implementation by the Apache Foundation
➢ KnopflerfishOSGi-container implementation developed by Makewave
➢ ...
http://eclipse.org/equinox/
http://felix.apache.org/
http://www.knopflerfish.org/
Seite 17
OSGI – what, why and who
OSGi with Equinox / The console
see Equinox QuickStart Guide http://eclipse.org/equinox/documents/quickstart.php
Equinox is part of Eclipse and can be activated without further downloads– Start the Equinox osgi-console:
java -jar /path/to/eclipse/plugins/org.eclipse.osgi_3.5.2.jar -console
osgi>
– This starts the equinox implementation of the OSGi container and opens a console
– The console may also be used with eclipse itself:
/path/to/eclipse/eclipse -console
Seite 18
OSGI – what, why and who
Th Letschert
OSGi with Equinox / The console
Commands (Examples)
– help List all available commands.
– ss List of all bundles together with their state and id.
– ss <string> List all bundles with names containing that string.
– start <id> Start up the bundle with a given id.
– stop <id> Stop the bundle with the given id.
– install <url> Install the bundle that the URL refers to.
– uninstall <id> Uninstall the bundle with the given id.
– diag <id> Show resolution problems for bundle with given id.
– exit Exit
For more information use the help command
Seite 19
OSGI – what, why and who
Th Letschert
OSGi with Equinox / The console
Usage Example: install http-server as eclipse bundles
> java -jar org.eclipse.osgi_3.5.2.jar -consoleosgi> install file:/path/to/eclipse/plugins/org.eclipse.osgi.services_3.2.0.v20090520-1800.jarBundle id is 1 osgi> install file:/path/to/eclipse/plugins/org.eclipse.equinox.ds_1.1.1.R35x_v20090806.jar
Bundle id is 2 osgi> install file:/path/to/eclipse/plugins/javax.servlet_2.5.0.v200806031605.jarBundle id is 3 osgi> install file:/path/to/eclipse/plugins/org.eclipse.equinox.util_1.0.100.v20090520-1800.jarBundle id is 4osgi> install \ file:/path/to/eclipse/plugins/org.eclipse.equinox.http.servlet_1.0.200.v20090520-1800.jarBundle id is 5osgi> install file:/path/to/eclipse/plugins/org.mortbay.jetty.util_6.1.15.v200905182336.jarBundle id is 6osgi> install file:/path/to/eclipse/plugins/org.mortbay.jetty.server_6.1.15.v200905151201.jar
Bundle id is 7osgi> setprop org.osgi.service.http.port=8888Setting Properties: org.osgi.service.http.port = 8888
Seite 20
OSGI – what, why and who
Th Letschert
Usage Example: install eclipse bundles (cont)
osgi> start 1 osgi> start 2osgi> start 3osgi> start 4osgi> start 5osgi> start 6osgi> start 7osgi> ssFramework is launched.id State Bundle0 ACTIVE org.eclipse.osgi_3.5.2.R35x_v201001261 ACTIVE org.eclipse.osgi.services_3.2.0.v20090520-18002 ACTIVE org.eclipse.equinox.ds_1.1.1.R35x_v200908063 ACTIVE javax.servlet_2.5.0.v2008060316054 ACTIVE org.eclipse.equinox.util_1.0.100.v20090520-18005 ACTIVE org.eclipse.equinox.http.servlet_1.0.200.v20090520-18006 ACTIVE org.mortbay.jetty.util_6.1.15.v2009051823367 ACTIVE org.mortbay.jetty.server_6.1.15.v200905151201osgi>
now a http server is up and running(of course it has no files to serve)
Seite 21
OSGI – what, why and who
Th Letschert
OSGi adoption :
OSGi survey report 2009 / Java developers on OSGi
➢ Are you familiar with the OSGi Service Platform?
92% have heard of OSGi
➢ Are you currently developing systems to be deployed to an OSGi runtime?
70.9% were using OSGi
➢ Do you have plans to develop systems that are to be deployed to an OSGi runtime within the next 6 – 12 months?
82.7% are planning to use it in the next 6 - 12 months
➢ Are you familiar with the available OSGi products and services
83.5% were familar with OSGi products and services
➢ Which OSGi implementations are you currently using or evaluating?
Equinox, Felix are the leaders
http://osgi.dzone.com/articles/osgi-survey-results
Seite 22
OSGI – what, why and who
Th Letschert
OSGi adoption : OSGi survey report 2009 / Java developers on OSGi
Which of the following types of systems are you planning to deploy within an OSGi runtime?
64.8% web apps17.2% embedded development15.6% mobile development50.4% for rich clients13.6% aren't using OSGi at all.
What are the benefits you hope to achieve using OSGi?
83.9% greater modularity56.6% hot deployment51.4% manageable runtime environment68.6% better dependency management57.3% bundle versioning63.5% plugin architecture10.2% nothing
http://osgi.dzone.com/articles/osgi-survey-results
Seite 23
OSGI – what, why and who
Th Letschert
OSGi adoption : OSGi survey report 2009 / Java developers on OSGi (cont.)
Which of the following types of systems are you planning to deploy within an OSGi runtime?
64.8% web apps17.2% embedded development15.6% mobile development50.4% for rich clients13.6% aren't using OSGi at all.
What are the benefits you hope to achieve using OSGi?
83.9% greater modularity56.6% hot deployment51.4% manageable runtime environment68.6% better dependency management57.3% bundle versioning63.5% plugin architecture10.2% nothing
http://osgi.dzone.com/articles/osgi-survey-results
Seite 24
OSGI – Bundle
Th Letschert
Bundle Bundles are runtime components, i.e. plugins Eclipse plugins are (special) bundles Incarnation : Jar-file containing:
➢ Content: classes, resources ➢ Meta-information: Bundle-specific meta-information
Content➢ mainly packages identified by name and version➢ hidden from other bundles➢ unless explicitly exported and explicitly imported by other bundles
Meta-information Manifest file (mandatory)
➢ as Jar manifest file META-INF/MANIFEST.MF➢ file-content structured following the jar-specification➢ with specific OSGi headers
Optional meta-information in optional directories e.g.:➢ OSGi-INF: XML-files describing (declarative services)➢ OSGi-OPT: security / i18n related specifications
Seite 25
OSGI – Bundle
Th Letschert
Example: Bundle org.eclipse.core.runtime-v20090525.jar and its manifest file
Manifest-Version: 1.0Bundle-Localization: pluginBundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0,J2SE-1.3
Bundle-SymbolicName: org.eclipse.core.runtime; singleton:=trueRequire-Bundle: org.eclipse.osgi;bundle-version="[3.5.0,4.0.0)";visibi lity:=reexport,org.eclipse.equinox.common;bundle-version="[3.5.0,4.0. 0)";visibility:=reexport,org.eclipse.core.jobs;bundle-version="[3.2.0 ,4.0.0)";visibility:=reexport,org.eclipse.equinox.registry;bundle-ver sion="[3.4.0,4.0.0)";visibility:=reexport,org.eclipse.equinox.prefere nces;bundle-version="[3.2.0,4.0.0)";visibility:=reexport,org.eclipse. core.contenttype;bundle-version="[3.3.0,4.0.0)";visibility:=reexport, org.eclipse.core.runtime.compatibility.auth;bundle-version="[3.2.0,4. 0.0)";resolution:=optional,org.eclipse.equinox.app;bundle-version="[1 .0.0,2.0.0)";visibility:=reexportBundle-Activator: org.eclipse.core.internal.runtime.PlatformActivatorExport-Package: org.eclipse.core.internal.preferences.legacy;x-interna l:=true,org.eclipse.core.internal.runtime;x-friends:="org.eclipse.cor e.runtime.compatibility",org.eclipse.core.runtime;version="3.4.0"Bundle-Version: 3.5.0.v20090525Bundle-ActivationPolicy: lazyBundle-Vendor: %providerNameBundle-Name: %pluginName
· · ·
Seite 26
OSGI – Bundle
Th Letschert
Manifest file contains information about the bundle in headers:
Identification: bundles identify themselvesheader: Bundle-SymbolicName
header: Bundle-Version
Export: Bundles may export packages Exported packages form the bundle's API Packages not exported are private Packages are exported with their name and a optional version number
(packages are versioned independently)header: Export-Package
Example:
Export-Package: org.eclipse.core.internal.preferences.legacy;x-interna l:=true,org.eclipse.core.internal.runtime;x-friends:="org.eclipse.cor e.runtime.compatibility",org.eclipse.core.runtime;version="3.4.0"
package org.eclipse.core.runtime is exported with version number 3.4.0
Seite 27
OSGI – Bundle
Th Letschert
Manifest file contains information about the bundle in headers:
Import
Bundles may use packages exported packages only if they explicitly import them using the package name
Version: Each import may be qualified with a version or a version range :lower and upper bound of versions for the imported packageVersion range spec. mathematically “[a,b)” “(“ ~ exclusive “[“ ~ inclusive
header: Import-Package
Example (from org.eclipse.equinox.http.servlet_1.0.200.v20090520-1800.jar)
Import-Package: javax.servlet;version="2.3",javax.servlet.http;version="2.3",org.osgi.framework;version="1.3.0",org.osgi.service.http;version="1.2.0"
all imports are labeled with exact versions
Seite 28
OSGI – Bundle
Th Letschert
Manifest file contains information about the bundle in headers:
Requirement Bundles may specify a dependency on entire bundles Simplifies imports May be used to express dependency on on-Java resources Widely used in Eclipse because it maps to the import statements of eclipse's
original plugin concept Version: Requirements may be qualified with a version or a version range header: Required-Bundle
Example (from org.eclipse.core.runtime-v20090525.jar)
Require-Bundle: org.eclipse.osgi;bundle-version="[3.5.0,4.0.0)";visibi lity:=reexport,org.eclipse.equinox.common;bundle-version="[3.5.0,4.0. 0)";visibility:=reexport,org.eclipse.core.jobs;bundle-version="[3.2.0
,4.0.0)";visibility:=reexport,org.eclipse.equinox.registry;bundle-ver sion="[3.4.0,4.0.0)";visibility:=reexport,org.eclipse.equinox.prefere nces;bundle-version="[3.2.0,4.0.0)";visibility:=reexport,org.eclipse. core.contenttype;bundle-version="[3.3.0,4.0.0)";visibility:=reexport, org.eclipse.core.runtime.compatibility.auth;bundle-version="[3.2.0,4. 0.0)";resolution:=optional,org.eclipse.equinox.app;bundle-version="[1 .0.0,2.0.0)";visibility:=reexport
Seite 29
OSGI – Bundle
Th Letschert
Resolving dependencies between bundles
Dependencies are resolved using language rules and classloaders
Dependencies between bundles are resolved at runtime Visibility follows usual Java language rules (public, protected, ···) Mechanism: Each bundle is equipped with it's own class loader when being
installed
class name
bundle class loaderclass
class+
Seite 30
OSGI – Bundle
Th Letschert
Lifecycle
Instances of a bundle are created by installing them in a container / framework.
Installed bundles have a lifecycle manged by the framework.
The difference between a bundle and its installment is usually not made explicit. The noun “bundle” may refer to a bundle or to an installed bundle (a bundle instance). OSGi Spec differentiates between Bundle - deployed instance - and bundle - jar file.
For each Bundle (an installed bundle) there is a Bundle-object that is managed by the framework
Each Bundle goes through a lifecycle controlled by the framework A Bundle has to listen and react on lifecycle events
deploy / install,activate, stop
update, uninstall
OSGi framework
bundleBundleBundle
lifecycleevents
Seite 31
OSGI – Bundle
Th Letschert
BundleBundle
Diagr: OSGi Service Platform Spec. 4.2
OSGi framework
bundle
deploy / install,activate, stop
update, uninstall
Bundle lifecycle
Seite 32
OSGI – Bundle
Th Letschert
Lifecycle installed: initial state of an (installed) bundle
resolved: all dependencies are resolved, all classes are available, bundle is ready to be started
starting: the bundle is in the process of starting,method BundleActivator.start is called but did not return
active: bundle is active and running, method BundleActivator.start was called and did return
stopping: the bundle is in the process of being stopped, method BundleActivator.stop was called but did not yet return
uninstalled: the bundle has been uninstalled, it is no longer available for use of the framework
Seite 33
OSGI – Bundle
Th Letschert
Bundle Context Upon activation a bundle gets a bundle context
The bundle context represents the framework as seen by the bundle
The bundle context is used by the bundle to:
get information about the framework install other bundles information about other bundles access persistent storage access the service registry access the event subscription
Framework
BundleBundle
Bundle Context(proxy to the framework)
Bundle
Seite 34
OSGI – Bundle
Th Letschert
Events Types of events
Bundle events: report state changes of a bundle Service events: report service registration, un-registration, modification Framework events: report changes in the framework (starting, stopping)
Bundle listener registered by the bundle at the bundle context called when the bundles stage changes
Framework listener registered by the bundle at the bundle context called when a framework event occurs
Framework
BundleBundle
Bundle Context
Listener
Event
Seite 35
OSGI – Service
Th Letschert
Services Types of bundle interaction
Via direct references to classes provided by other bundles Via Services: Access mediated by a service registry Via Extension points (only Equinox)
Service Service name: name of an interface Service definition: a public interface defined in an exported package of a
bundle
Service implementation: Object of a class that implements the interface (within the same or a different bundle) The service class usually is not exported.
Service registration: Service implementer registers the object under the name of the interface
Service usage: A service consumer imports the package containing the interface
looks up – using the name – the service registry for a matching object
uses the service object
Seite 36
Bundle / Equinox – Extensions
Th Letschert
Extension and Extension Point
Extension Point: a complementary bundle collaboration mechanism. Bundle-local registration mechanism.
Defined and implemented in Equinox
Inheritance of Eclipse's pre-OSGi time
Bundles declare extension points
Other bundles provide extensions to an extension point
Extensions and extension points are declared in XML (file plugin.xml)
BundleBundle
BundleBundle
Seite 37
OSGi – Framework
Th Letschert
Framework
framework = runtime = container = platform
Specified in “OSGi Service Platform Core Specification” as part of an OSGi-compliant device responsible for managing bundles, services and their dependencies
Structured into “layers”: Execution Environment (EE) Module Lifecycle Service Security
Framework layers, their interaction and responsibilities(OSGi Service Platform Spec. 4.2 )
Seite 38
OSGi – Framework
Th Letschert
Life cycle state diagram
Diagr.: OSGi Service Platform Spec. 4.2
Seite 39
OSGi – Framework
Th Letschert
Life cycle of a framework
Outside of the specification: Classes that implement a framework must be made available through the class path or a special class loader.
Launcher: a launcher (outside the specification) launches the framework by using the factory and a framework object:
Factory: A framework implementation must provide a factory class which can create a framework object
Framework life cycle refers to a framework object installed: the framework has been created starting: the framework has been initialized, none of its bundles are active active: services and event handling is active, framework object has a
bundle context object, framework services are available, all bundles are started
stopping: shutdown is initiated
Top Related