Introduction to OSGi using Apache Karaf Ioannis Canellos JHUG / 16 April 2011
Introduction to OSGi using
Apache Karaf Ioannis Canellos
JHUG / 16 April 2011
Presenting today…
OSGiOpen Services Gateway initiative, since 1999Initially targeted embedded devicesOSGi containers: Felix, Equinox, Knoperfish, ConciergeMost known use is Eclipse IDE
Apache KarafApache OSGi runtime runs on any OSGi containerBorn inside Service Mix, now is Top level projectStandard runtime for Geronimo, Service Mix, SlingEcosystem for deploying OSGi/EE applications
Part IIntroduction to OSGi
Introduction to OSGi
Problem
Solution
Architecture
Tools
OSGi in the Enterprise
Questions & Answers
The problemaspects
Dependency managementVersion HellConflicting dependenciesClass loading issues
Dynamic behaviorDifficulties to control component lifecycle
Lack of a pure modularity solution
The problemsDependency
managementLarge number of transitive dependencies
Conflicts among among dependencies
Class loading issuesBoot class loader
System class
loader
war war
JTA
JTA
The problemsDynamic Behavior
Components & Services need come and go
Components need to get updated / replaced
Components need to started / stoppedReal life examples
Eclipse IDE
Adding/Removing “plugins”
Ebay
Multiple version of the same component
The problemsModularity
The JVM does not address need for modularity
The class path paradoxThe jar is a “black box”
No dependencies & No versionThe pastitsio example
The “WORA” promise was repeatedly failedJavaBeansEJBs
Has the quest for modularity failed ?
OSGi is already hereProject Jigsaw will be shipped with JDK 8
The OSGi SolutionOverview
A Layer …
A deployment infrastructureBundles = class + metadata (import/exports)Bundles have a lifecycleBundles have their own Class loaderClass loading delegation between dependant bundles
A service platformDefines a Service RegistryBundles provide or request servicesThe service can “come and go”
Architecture
Architecture Execution
EnvironmentThe Runtime where the bundles live
A bundle can bound to an Execution Environment
JOSGi/
Minimum-1.0
JRE-1.3
JRE-1.5
Architecture Module Layer
Bundles import, export or have private packages
Each package can be assigned version range
A bundle (fragment) can be attached to a bundle (host)
Export Package
javax.transaction 1.01B
Export Package
javax.transaction 1.1
Import Package
javax.transaction [1.0,1.1)
Bundle Name: JMS APIImport Package: javax.transactionExport Package: javax.jmsBundle-RequiredExecutionEnvironment: J2SE-1.5
Architecture Module Layer
a MANIFEST.MF exampleManifest-Version: 1.0
Import-Package:
javax.transaction;version="1.1”, javax.transaction.xa;version="1.1”
Export-Package:
javax.jms;version="1.1”
Bundle-SymbolicName: org.apache.geronimo.specs.geronimo-jms_1.1_spec
Tool: Bnd-0.0.227
Stopped
Started
Starting
Uninstalled
Architecture Lifecycle Layer
resolve
update
refresh
uninstall uninstall
start
stop
Installed
Resolved
Architecture Service Layer
Each bundle can register or lookup a Service
Each service corresponds to one or more interfaces
Each service can be assigned and queried using propertiesService
Registryregister lookup
Service Provider
Service Consum
er
OSGi Toolsworking with
servicesManaging Services programmatically
Using the OSGi blueprintSpring Dynamic ModulesApache Aries
Felix i-Pojo
OSGi Toolscreating bundles
Manually providing the MANIFEST.MF
Bnd command line tool
Maven Bundle Plug-in
Spring’s BundlorMaven plug-in flavorCommand line flavor
OSGi ToolsOSGi Bundle
RepositorySimplifies the provisioning of bundles
The “apt-get install” for the OSGi
Integrates with public repositoriesEclipse OrbitSpring’s Enterprise Bundle Repository
OSGi End of Part I
Questions & Answers
Part IIGetting started with Apache
Karaf
Apache Karafagenda
Overview
Shell Console
Deployer
Features Concept
Security
Logging Service
Demo
Questions and Answers
Apache KarafOverview
Born as Service Mix Kernel project
Grown inside Apache Felix project
Become a Top Level Apache project last year
Apache KarafShell ConsoleExtensible
Auto complete & coloring support
Rich command set, covers most OSGi concepts/services
Special commands for the development phase
Apache KarafDeployer
Configuration Bundles Transforma
tion
File Scanner
Configuration
AdminURL
Handler
War Transforme
rSpringTransforme
rBlueprintTransforme
r
OBR Handler
HTTP Handler
Maven Handler
Hot deployment
Large number of supported artifacts
Large number of installation mediums
Apache KarafFeatures ConceptA Karaf feature is a descriptor which defines…
A set of bundlesA set of configurationsA set of other features
Allows provisioning of applications
Maven integration
OBR integration
Apache KarafFeatures Example
<feature name="http" version=”2.2.0” resolver=“(obr)”>
<config name="org.ops4j.pax.web”>
org.osgi.service.http.port=8181
</config>
<feature version="[7.0,8.0)">jetty</feature>
<bundle dependency=“true”>mvn:javax.servlet/servlet-api</bundle>
<bundle>mvn:org.ops4j.pax.web/pax-web-api</bundle>
</feature>
Apache KarafSecurity
JAAS based security
Multiple login module implementationsProperty Login ModuleJDBC Login ModuleLDAP Login Module
Command line supportProvisioning of any JASS realm Add users roles etc
Apache KarafLogging Service
Centralized Logging configuration
Supports most logging APIsLog4JSlf4j Commons Logging
Command line supportclear, display, tail change threshold etc.
OSGi integrationper bundle appender, osgi specific attributes
Apache KarafEnd of Part II
Questions & Answers
Thank you