SlideShare a Scribd company logo
Practical OSGi
   Sten Roger Sandvik
       Enonic AS

    srs@enonic.com
What is OSGi?
• A module system for Java
  The Dynamic Module System for Java™.


• Dynamic modules (bundles)
  Installing, starting, stopping, updating and uninstalling modules at runtime.


• Service oriented
  Services can be registered and consumed at runtime.


• A worldwide standard
  OSGi Alliance. Release R1 in 2000. Currenty at release R4.1.
Key Benefits
• No more “JAR” hell
  Can have multiple versions of same library.


• Reuse packaged modules
  Allows 3rd party prepackaged modules to be installed.


• Less server restarts
  Update modules at runtime.


• Simplifies multi-team projects
  Can partition the application into smaller modules.
Key Benefits (2)
• Enables smaller systems
  By breaking it into smaller pieces (some optional).


• Multiple runtime options
  Standalone, Client, Server, Embedded.


• Multiple implementations
  Eclipse Equinox, Apache Felix, Knopflerfish.


• Very high adaption rate
  Apache, Sun, Oracle, IBM, BMW and Enonic are all using it.
Theory
Framework Layers
• L3 - Service                                               L3
  Publish/find/bind service model to decouple bundles.
                                                             L2
• L2 - Lifecycle                                             L1
  Independent lifecycle of bundles without JVM restarts.


• L1 - Module                                                L0
  A module (or bundle) uses classes from other
  bundles in a controlled way.


• L0 - Execution environment
  Well defined profiles (JavaSE, CDC) that define the JVM environment.
Module Layer
• Unit of deployment                         L3
  A module is called a bundle in OSGi.
                                             L2
• Standard JAR file with metadata             L1
  Metadata in META-INF/MANIFEST.MF


• Seperate classloader per bundle            L0
  Class sharing at the Java package level.


• Share only “interface” packages
  Share only API between bundles.
Module Layer (2)
• Multi-version support                           L3
  Different bundles can see different versions.
                                                  L2
• Manifest example                                L1
   Bundle-Name: Example
   Bundle-SymbolicName: net.foo.common
   Bundle-Version: 1.0.0
                                                  L0
   Import-Package:
     org.osgi.framework;version=”1.3”,
     net.foo.api;version=”1.0.0”
   Export-Package:
     net.foo.common;version=”1.0.0”
   Private-Package:
     net.foo.common.internal,
     net.foo.common.internal.codec
   Bundle-ManifestVersion: 2
Lifecycle Layer
• Managed lifecycle                                   L3
  Managed states for each bundle.
                                                      L2
• Update existing bundles                             L1
  Dynamically install, start, update and uninstall.

                                                      L0
Service Layer
• Service registry                                          L3
  Publish/find/bind services at runtime.
                                                            L2
• Bind interfaces                                           L1
  Bind interfaces - not implementations.

                                                            L0
                                     Registry

                       publish                   find


                      Provider                  Requester
                                     interact
Practice
Password Encoder
• Password encoder application
  Simple JVM client that uses password encoders.


• Encoders are pluggable
  Multiple implementations. Can be stopped/started at runtime.
Project Structure
• API Bundle                                                    API
  Holds all public avaliable APIs.
                                                           Encoder
• Encoder Bundle                                           Client
  Provides a password encoder implementation.
                                                       Parent
• Client Bundle
  Client bundle that uses one or more password encoders.
API Bundle
• Provides the API                                  API
  Simple PasswordEncoder interface.
                                                  Encoder
• Exports package                                 Client
  Export the API (net.foo.api) package so other
  bundles can see it.
Password Encoder
package net.foo.api;
                                                               API
/**
  * Simple interface that defines the password
                                                          Encoder
  * encoder.
  */
public interface PasswordEncoder
                                                              Client
{
   /**
     * Returns the name of this encoder.
     */
   public String getName();

    /**
     * Encode the password and return the encoded password.
     */
    public String encode(String password);
}
Manifest
• Exports the package                                   API
  Exports package (net.foo.api) with right version.
                                                      Encoder
     ...
     Bundle-Name: Example - API

                                                      Client
     Bundle-SymbolicName: net.foo.api
     Export-Package:
       net.foo.api;version=”1.0.0”
     ...
Encoder Bundle
• Uses the API                                                 API
  Imports proper API package (net.foo.api).
                                                           Encoder
• Registers a provider                                       Client
  Registers a PasswordEncoder provider implementation
  as a service.


• Hides the implementation
  Hides implementation from other bundles by using Private-Package.
Register a Service
• Use a BundleActivator                                          API
  Implement bundle activator that handle lifecycle.
                                                            Encoder
• Register on start                                             Client
  Register service on when bundle is started.


• Unregister at stop
  Unregister the service when bundle is stopped.


• Add proper metadata
  Do not forget to add Bundle-Activator metadata in manifest.
Bundle Activator
package net.foo.encoder;
                                                 API
import net.foo.api.*;
import org.osgi.framework.*;

                                               Encoder
public class Activator
  implements BundleActivator

                                               Client
{
  private ServiceRegistration reg;

    public void start(BundleContext context)
    {
      this.reg = context.registerService(
        PasswordEncoder.class.getName(),
        new ReversePasswordEncoder(), null);
    }

    public void stop(BundleContext context)
    {
      this.reg.unregister();
    }
}
Manifest
• Declare BundleActivator                                   API
  Set the bundle activator classname in manifest.
                                                          Encoder
• Import used packages                                    Client
  Import net.foo.api and org.osgi.framework
  packages with right version.


• Hide implementation package
  Declare net.foo.encoder package as a private package.
Manifest (2)
...

                                         API
Bundle-Name: Example - Encoder
Bundle-SymbolicName: net.foo.encoder
Bundle-Activator:

                                       Encoder
  net.foo.encoder.Activator
Import-Package:
  net.foo.api;version=”1.0.0”,
  org.osgi.framework;version=”1.3”
                                       Client
Private-Package:
  net.foo.encoder
...
Client Bundle
• Uses the API                    API
  Does not see the encoder implementation.
                                Encoder
• Track PasswordEncoder’s        Client
  Track available password encoder providers.


• Encodes password based on encoder
  Finds right encoder and encodes the password.
Locating Services
• Services are dynamic                                         API
  All services can be added and removed runtime.
                                                            Encoder
• Not always available on init                               Client
  Do not assume that you can always obtain a service
  during initialization.


• Use ServiceTracker
  Use ServiceTracker to track available services. Remember to open()
  and close() the tracker.
Using ServiceTracker
public class Activator
  implements BundleActivator
                                                                   API
{
  private ServiceTracker tracker;


                                                                 Encoder
  public void start(BundleContext context)
  {
    tracker = new ServiceTracker(

                                                                 Client
      context, PasswordEncoder.class.getName(), null);
    tracker.open();
  }

  public void stop(BundleContext context)
  {
    tracker.close();
  }                         public class MyConsumer
}                           {
                               private ServiceTracker tracker;

                               ...

                               public void consumeServices()
                               {
                                 Object[] services = tracker.getServices();
                               }
                           }
Client Implementation
public class Client
                                                                       API
{
  private ServiceTracker tracker;

                                                                 Encoder
    ...

    public String encode(String method, String password)
                                                                      Client
    {
       for (Object service : tracker.getServices()) {
         PasswordEncoder enc = (PasswordEncoder)service;

            if (enc.getName().equals(method)) {
              return enc.encode(password);
            }
        }

          throw new IllegalArgumentException(“Provider not found”);
    }
}
Manifest
...
                                          API
Bundle-Name: Example - Client
Bundle-SymbolicName: net.foo.client
Bundle-Activator:
                                        Encoder
  net.foo.client.Activator
Import-Package:
  net.foo.api;version=”1.0.0”,

                                        Client
  org.osgi.framework;version=”1.3”,
  org.osgi.util.tracker;version=”1.3”
Private-Package:
  net.foo.client
...
Improvements
• Use a declarative service model
  Hides OSGi details. Makes service tracking easy. Spring DM is one
  implementation.


• Use automatic manifest creation
  Use Maven Bundle Plugin (Apache Felix Project) to create and validate
  manifest entries at build time.
Demo
Tools Used
• Maven 2
  Build the project using Maven 2 using standard layout.


• Maven Bundle Plugin
  Creates and validates the MANIFEST.MF. Based on BND.


• Maven Pax Plugin
  Running the OSGi application using Pax Runner.


• Felix OSGi Container
  Implementation of R4.1 specification.
3rd Party Bundles
• Pax Web
  Web container based on Jetty. Implementation of HttpService.


• Pax Logging
  Logging abstraction and LogService implementation. Possible to use SLF4J,
  Commons Logging and Log4J in bundles.


• Felix WebConsole
  Web Console to visualize bundles and services.
Q?


srs@enonic.com

More Related Content

What's hot

Modular Java
Modular JavaModular Java
Modular Java
Martin Toshev
 
Desiging for Modularity with Java 9
Desiging for Modularity with Java 9Desiging for Modularity with Java 9
Desiging for Modularity with Java 9
Sander Mak (@Sander_Mak)
 
Osgi platform
Osgi platformOsgi platform
Osgi platform
Yuriy Shapovalov
 
Modules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module SystemModules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module System
Tim Ellison
 
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application DevelopmentOSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
Sanjeeb Sahoo
 
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH
 
Java Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily JiangJava Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily Jiang
JAX London
 
Beyond OSGi Software Architecture
Beyond OSGi Software ArchitectureBeyond OSGi Software Architecture
Beyond OSGi Software Architecture
Jeroen van Grondelle
 
OSGi Presentation
OSGi PresentationOSGi Presentation
OSGi Presentation
Michal Malohlava
 
Java 9 New Features
Java 9 New FeaturesJava 9 New Features
Java 9 New Features
Ali BAKAN
 
OSGi & Java EE in GlassFish - Best of both worlds
OSGi & Java EE in GlassFish - Best of both worldsOSGi & Java EE in GlassFish - Best of both worlds
OSGi & Java EE in GlassFish - Best of both worlds
Arun Gupta
 
Modules or microservices?
Modules or microservices?Modules or microservices?
Modules or microservices?
Sander Mak (@Sander_Mak)
 
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration IssuesJava 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
GlobalLogic Ukraine
 
Moved to https://slidr.io/azzazzel/leveraging-osgi-to-create-extensible-plugi...
Moved to https://slidr.io/azzazzel/leveraging-osgi-to-create-extensible-plugi...Moved to https://slidr.io/azzazzel/leveraging-osgi-to-create-extensible-plugi...
Moved to https://slidr.io/azzazzel/leveraging-osgi-to-create-extensible-plugi...
Milen Dyankov
 
JBI and PEtALS Presentation at SOA4ALL architecture meeting
JBI and PEtALS Presentation at SOA4ALL architecture meetingJBI and PEtALS Presentation at SOA4ALL architecture meeting
JBI and PEtALS Presentation at SOA4ALL architecture meeting
Christophe Hamerling
 
OSGi in 5 minutes
OSGi in 5 minutesOSGi in 5 minutes
OSGi in 5 minutes
Serge Huber
 
OSGi Blueprint Services
OSGi Blueprint ServicesOSGi Blueprint Services
OSGi Blueprint Services
Guillaume Nodet
 
Step by step guide to create theme for liferay dxp 7
Step by step guide to create theme for liferay dxp 7Step by step guide to create theme for liferay dxp 7
Step by step guide to create theme for liferay dxp 7
Azilen Technologies Pvt. Ltd.
 
Managing Change
Managing ChangeManaging Change
Managing Change
Mirko Jahn
 
OSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishOSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFish
Arun Gupta
 

What's hot (20)

Modular Java
Modular JavaModular Java
Modular Java
 
Desiging for Modularity with Java 9
Desiging for Modularity with Java 9Desiging for Modularity with Java 9
Desiging for Modularity with Java 9
 
Osgi platform
Osgi platformOsgi platform
Osgi platform
 
Modules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module SystemModules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module System
 
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application DevelopmentOSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
 
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
 
Java Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily JiangJava Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily Jiang
 
Beyond OSGi Software Architecture
Beyond OSGi Software ArchitectureBeyond OSGi Software Architecture
Beyond OSGi Software Architecture
 
OSGi Presentation
OSGi PresentationOSGi Presentation
OSGi Presentation
 
Java 9 New Features
Java 9 New FeaturesJava 9 New Features
Java 9 New Features
 
OSGi & Java EE in GlassFish - Best of both worlds
OSGi & Java EE in GlassFish - Best of both worldsOSGi & Java EE in GlassFish - Best of both worlds
OSGi & Java EE in GlassFish - Best of both worlds
 
Modules or microservices?
Modules or microservices?Modules or microservices?
Modules or microservices?
 
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration IssuesJava 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
 
Moved to https://slidr.io/azzazzel/leveraging-osgi-to-create-extensible-plugi...
Moved to https://slidr.io/azzazzel/leveraging-osgi-to-create-extensible-plugi...Moved to https://slidr.io/azzazzel/leveraging-osgi-to-create-extensible-plugi...
Moved to https://slidr.io/azzazzel/leveraging-osgi-to-create-extensible-plugi...
 
JBI and PEtALS Presentation at SOA4ALL architecture meeting
JBI and PEtALS Presentation at SOA4ALL architecture meetingJBI and PEtALS Presentation at SOA4ALL architecture meeting
JBI and PEtALS Presentation at SOA4ALL architecture meeting
 
OSGi in 5 minutes
OSGi in 5 minutesOSGi in 5 minutes
OSGi in 5 minutes
 
OSGi Blueprint Services
OSGi Blueprint ServicesOSGi Blueprint Services
OSGi Blueprint Services
 
Step by step guide to create theme for liferay dxp 7
Step by step guide to create theme for liferay dxp 7Step by step guide to create theme for liferay dxp 7
Step by step guide to create theme for liferay dxp 7
 
Managing Change
Managing ChangeManaging Change
Managing Change
 
OSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishOSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFish
 

Viewers also liked

A Sangue Frio
A Sangue FrioA Sangue Frio
A Sangue Frio
Ricardo Rodrigues
 
Ddp médico ocupacional v1
Ddp médico ocupacional v1Ddp médico ocupacional v1
Ddp médico ocupacional v1
Roberto Fernando Kano Velarde
 
Kemampanan bandar tempat tinggal saya
Kemampanan bandar tempat tinggal sayaKemampanan bandar tempat tinggal saya
Kemampanan bandar tempat tinggal saya
zaira zue
 
Faktor biofisiologis
Faktor biofisiologisFaktor biofisiologis
Faktor biofisiologis
Afifah Zulianuriauwani
 
Cостояние и перспективы машинного интеллекта
Cостояние и перспективы машинного интеллектаCостояние и перспективы машинного интеллекта
Cостояние и перспективы машинного интеллекта
Skolkovo Robotics Center
 
Test Automation Without the Headache: Agile Tour Vienna 2015
Test Automation Without the Headache: Agile Tour Vienna 2015 Test Automation Without the Headache: Agile Tour Vienna 2015
Test Automation Without the Headache: Agile Tour Vienna 2015
gojkoadzic
 
BRAKE DAY2
BRAKE DAY2BRAKE DAY2
BRAKE DAY2
kishan rajbhar
 
How to build an effective IoT demo with OSGi - Derek Baum & Walt Bowers
How to build an effective IoT demo with OSGi - Derek Baum & Walt BowersHow to build an effective IoT demo with OSGi - Derek Baum & Walt Bowers
How to build an effective IoT demo with OSGi - Derek Baum & Walt Bowers
mfrancis
 
Force Measurement - Best load cell calibration practices
Force Measurement - Best load cell calibration practices Force Measurement - Best load cell calibration practices
Force Measurement - Best load cell calibration practices
Henry Zumbrun
 
441 presentation 5
441 presentation 5441 presentation 5
441 presentation 5
Ashwin Fujii
 
Alfred preso 1
Alfred preso 1Alfred preso 1
Alfred preso 1
Davis Vorva
 
Electromagnetic braking
Electromagnetic brakingElectromagnetic braking
Electromagnetic braking
Surya Prakash
 
Etude de gestion BAC STMG 2017 – épreuve anticipée STMG en Sciences de gestio...
Etude de gestion BAC STMG 2017 – épreuve anticipée STMG en Sciences de gestio...Etude de gestion BAC STMG 2017 – épreuve anticipée STMG en Sciences de gestio...
Etude de gestion BAC STMG 2017 – épreuve anticipée STMG en Sciences de gestio...
Super Professeur
 
Ppt on project_ELECTOMAGNETIC_BRAKING_SYSTEM
Ppt on project_ELECTOMAGNETIC_BRAKING_SYSTEMPpt on project_ELECTOMAGNETIC_BRAKING_SYSTEM
Ppt on project_ELECTOMAGNETIC_BRAKING_SYSTEM
ANUPAM SINGH
 
Django から各種チャットツールに通知するライブラリを作った話
Django から各種チャットツールに通知するライブラリを作った話Django から各種チャットツールに通知するライブラリを作った話
Django から各種チャットツールに通知するライブラリを作った話
Yusuke Miyazaki
 
APIドキュメントの話 #sphinxjp
APIドキュメントの話 #sphinxjpAPIドキュメントの話 #sphinxjp
APIドキュメントの話 #sphinxjp
Takeshi Komiya
 
Infinity OSD Overview
Infinity OSD OverviewInfinity OSD Overview
Infinity OSD Overview
caleb7777
 
「Python言語」はじめの一歩 / First step of Python
「Python言語」はじめの一歩 / First step of Python「Python言語」はじめの一歩 / First step of Python
「Python言語」はじめの一歩 / First step of Python
Takanori Suzuki
 
Automobile Chassis
Automobile Chassis  Automobile Chassis
Automobile Chassis
PEC University Chandigarh
 
Atomic hyrogen arc welding
Atomic hyrogen arc weldingAtomic hyrogen arc welding
Atomic hyrogen arc welding
Ilyas Hussain
 

Viewers also liked (20)

A Sangue Frio
A Sangue FrioA Sangue Frio
A Sangue Frio
 
Ddp médico ocupacional v1
Ddp médico ocupacional v1Ddp médico ocupacional v1
Ddp médico ocupacional v1
 
Kemampanan bandar tempat tinggal saya
Kemampanan bandar tempat tinggal sayaKemampanan bandar tempat tinggal saya
Kemampanan bandar tempat tinggal saya
 
Faktor biofisiologis
Faktor biofisiologisFaktor biofisiologis
Faktor biofisiologis
 
Cостояние и перспективы машинного интеллекта
Cостояние и перспективы машинного интеллектаCостояние и перспективы машинного интеллекта
Cостояние и перспективы машинного интеллекта
 
Test Automation Without the Headache: Agile Tour Vienna 2015
Test Automation Without the Headache: Agile Tour Vienna 2015 Test Automation Without the Headache: Agile Tour Vienna 2015
Test Automation Without the Headache: Agile Tour Vienna 2015
 
BRAKE DAY2
BRAKE DAY2BRAKE DAY2
BRAKE DAY2
 
How to build an effective IoT demo with OSGi - Derek Baum & Walt Bowers
How to build an effective IoT demo with OSGi - Derek Baum & Walt BowersHow to build an effective IoT demo with OSGi - Derek Baum & Walt Bowers
How to build an effective IoT demo with OSGi - Derek Baum & Walt Bowers
 
Force Measurement - Best load cell calibration practices
Force Measurement - Best load cell calibration practices Force Measurement - Best load cell calibration practices
Force Measurement - Best load cell calibration practices
 
441 presentation 5
441 presentation 5441 presentation 5
441 presentation 5
 
Alfred preso 1
Alfred preso 1Alfred preso 1
Alfred preso 1
 
Electromagnetic braking
Electromagnetic brakingElectromagnetic braking
Electromagnetic braking
 
Etude de gestion BAC STMG 2017 – épreuve anticipée STMG en Sciences de gestio...
Etude de gestion BAC STMG 2017 – épreuve anticipée STMG en Sciences de gestio...Etude de gestion BAC STMG 2017 – épreuve anticipée STMG en Sciences de gestio...
Etude de gestion BAC STMG 2017 – épreuve anticipée STMG en Sciences de gestio...
 
Ppt on project_ELECTOMAGNETIC_BRAKING_SYSTEM
Ppt on project_ELECTOMAGNETIC_BRAKING_SYSTEMPpt on project_ELECTOMAGNETIC_BRAKING_SYSTEM
Ppt on project_ELECTOMAGNETIC_BRAKING_SYSTEM
 
Django から各種チャットツールに通知するライブラリを作った話
Django から各種チャットツールに通知するライブラリを作った話Django から各種チャットツールに通知するライブラリを作った話
Django から各種チャットツールに通知するライブラリを作った話
 
APIドキュメントの話 #sphinxjp
APIドキュメントの話 #sphinxjpAPIドキュメントの話 #sphinxjp
APIドキュメントの話 #sphinxjp
 
Infinity OSD Overview
Infinity OSD OverviewInfinity OSD Overview
Infinity OSD Overview
 
「Python言語」はじめの一歩 / First step of Python
「Python言語」はじめの一歩 / First step of Python「Python言語」はじめの一歩 / First step of Python
「Python言語」はじめの一歩 / First step of Python
 
Automobile Chassis
Automobile Chassis  Automobile Chassis
Automobile Chassis
 
Atomic hyrogen arc welding
Atomic hyrogen arc weldingAtomic hyrogen arc welding
Atomic hyrogen arc welding
 

Similar to Practical OSGi

[apidays LIVE HONK KONG] - OAS to Managed API in Seconds
[apidays LIVE HONK KONG] - OAS to Managed API in Seconds[apidays LIVE HONK KONG] - OAS to Managed API in Seconds
[apidays LIVE HONK KONG] - OAS to Managed API in Seconds
WSO2
 
Skype testing overview
Skype testing overviewSkype testing overview
Skype testing overview
QA Club Kiev
 
Skype testing overview
Skype testing overviewSkype testing overview
Skype testing overview
QA Club Kiev
 
Puppet Camp Phoenix 2015: Continuous Integration Using Puppet (Intermediate)
Puppet Camp Phoenix 2015:  Continuous Integration Using Puppet (Intermediate)Puppet Camp Phoenix 2015:  Continuous Integration Using Puppet (Intermediate)
Puppet Camp Phoenix 2015: Continuous Integration Using Puppet (Intermediate)
Puppet
 
Continuous Integration with Puppet
Continuous Integration with PuppetContinuous Integration with Puppet
Continuous Integration with Puppet
Miguel Zuniga
 
Five Steps to Add AppUp .NET SDK to Microsoft Visual Studio
Five Steps to Add AppUp .NET SDK to Microsoft Visual StudioFive Steps to Add AppUp .NET SDK to Microsoft Visual Studio
Five Steps to Add AppUp .NET SDK to Microsoft Visual Studio
readwritehack
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
Ramesh Prasad
 
Eclipse Kura Shoot a-pi
Eclipse Kura Shoot a-piEclipse Kura Shoot a-pi
Eclipse Kura Shoot a-pi
Eclipse Kura
 
Automatically Managing Service Dependencies in an OSGi Environment - Marcel O...
Automatically Managing Service Dependencies in an OSGi Environment - Marcel O...Automatically Managing Service Dependencies in an OSGi Environment - Marcel O...
Automatically Managing Service Dependencies in an OSGi Environment - Marcel O...
mfrancis
 
OpenAPI Generator The Babel Fish of The API World - apidays Live Australia
OpenAPI Generator The Babel Fish of The API World - apidays Live AustraliaOpenAPI Generator The Babel Fish of The API World - apidays Live Australia
OpenAPI Generator The Babel Fish of The API World - apidays Live Australia
Cliffano Subagio
 
MINA2 (Apache Netty)
MINA2 (Apache Netty)MINA2 (Apache Netty)
MINA2 (Apache Netty)
ducquoc_vn
 
Warum OSGi?
Warum OSGi?Warum OSGi?
OpenAPI Generator The Babel Fish of The API World - apidays Live Paris
OpenAPI Generator The Babel Fish of The API World - apidays Live ParisOpenAPI Generator The Babel Fish of The API World - apidays Live Paris
OpenAPI Generator The Babel Fish of The API World - apidays Live Paris
Cliffano Subagio
 
Review: Apitrace and Vogl
Review: Apitrace and VoglReview: Apitrace and Vogl
Review: Apitrace and Vogl
Gao Yunzhong
 
Intro to OSGi and Eclipse Virgo
Intro to OSGi and Eclipse VirgoIntro to OSGi and Eclipse Virgo
Intro to OSGi and Eclipse Virgo
Gordon Dickens
 
How to Dockerize Your .NET Core API
How to Dockerize Your .NET Core APIHow to Dockerize Your .NET Core API
How to Dockerize Your .NET Core API
Lakshman S
 
How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks
Weaveworks
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDK
Kirill Kounik
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Tim Burks
 
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
BeMyApp
 

Similar to Practical OSGi (20)

[apidays LIVE HONK KONG] - OAS to Managed API in Seconds
[apidays LIVE HONK KONG] - OAS to Managed API in Seconds[apidays LIVE HONK KONG] - OAS to Managed API in Seconds
[apidays LIVE HONK KONG] - OAS to Managed API in Seconds
 
Skype testing overview
Skype testing overviewSkype testing overview
Skype testing overview
 
Skype testing overview
Skype testing overviewSkype testing overview
Skype testing overview
 
Puppet Camp Phoenix 2015: Continuous Integration Using Puppet (Intermediate)
Puppet Camp Phoenix 2015:  Continuous Integration Using Puppet (Intermediate)Puppet Camp Phoenix 2015:  Continuous Integration Using Puppet (Intermediate)
Puppet Camp Phoenix 2015: Continuous Integration Using Puppet (Intermediate)
 
Continuous Integration with Puppet
Continuous Integration with PuppetContinuous Integration with Puppet
Continuous Integration with Puppet
 
Five Steps to Add AppUp .NET SDK to Microsoft Visual Studio
Five Steps to Add AppUp .NET SDK to Microsoft Visual StudioFive Steps to Add AppUp .NET SDK to Microsoft Visual Studio
Five Steps to Add AppUp .NET SDK to Microsoft Visual Studio
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
Eclipse Kura Shoot a-pi
Eclipse Kura Shoot a-piEclipse Kura Shoot a-pi
Eclipse Kura Shoot a-pi
 
Automatically Managing Service Dependencies in an OSGi Environment - Marcel O...
Automatically Managing Service Dependencies in an OSGi Environment - Marcel O...Automatically Managing Service Dependencies in an OSGi Environment - Marcel O...
Automatically Managing Service Dependencies in an OSGi Environment - Marcel O...
 
OpenAPI Generator The Babel Fish of The API World - apidays Live Australia
OpenAPI Generator The Babel Fish of The API World - apidays Live AustraliaOpenAPI Generator The Babel Fish of The API World - apidays Live Australia
OpenAPI Generator The Babel Fish of The API World - apidays Live Australia
 
MINA2 (Apache Netty)
MINA2 (Apache Netty)MINA2 (Apache Netty)
MINA2 (Apache Netty)
 
Warum OSGi?
Warum OSGi?Warum OSGi?
Warum OSGi?
 
OpenAPI Generator The Babel Fish of The API World - apidays Live Paris
OpenAPI Generator The Babel Fish of The API World - apidays Live ParisOpenAPI Generator The Babel Fish of The API World - apidays Live Paris
OpenAPI Generator The Babel Fish of The API World - apidays Live Paris
 
Review: Apitrace and Vogl
Review: Apitrace and VoglReview: Apitrace and Vogl
Review: Apitrace and Vogl
 
Intro to OSGi and Eclipse Virgo
Intro to OSGi and Eclipse VirgoIntro to OSGi and Eclipse Virgo
Intro to OSGi and Eclipse Virgo
 
How to Dockerize Your .NET Core API
How to Dockerize Your .NET Core APIHow to Dockerize Your .NET Core API
How to Dockerize Your .NET Core API
 
How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDK
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
 
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
 

Recently uploaded

Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 

Recently uploaded (20)

Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 

Practical OSGi

  • 1. Practical OSGi Sten Roger Sandvik Enonic AS srs@enonic.com
  • 2. What is OSGi? • A module system for Java The Dynamic Module System for Java™. • Dynamic modules (bundles) Installing, starting, stopping, updating and uninstalling modules at runtime. • Service oriented Services can be registered and consumed at runtime. • A worldwide standard OSGi Alliance. Release R1 in 2000. Currenty at release R4.1.
  • 3. Key Benefits • No more “JAR” hell Can have multiple versions of same library. • Reuse packaged modules Allows 3rd party prepackaged modules to be installed. • Less server restarts Update modules at runtime. • Simplifies multi-team projects Can partition the application into smaller modules.
  • 4. Key Benefits (2) • Enables smaller systems By breaking it into smaller pieces (some optional). • Multiple runtime options Standalone, Client, Server, Embedded. • Multiple implementations Eclipse Equinox, Apache Felix, Knopflerfish. • Very high adaption rate Apache, Sun, Oracle, IBM, BMW and Enonic are all using it.
  • 6. Framework Layers • L3 - Service L3 Publish/find/bind service model to decouple bundles. L2 • L2 - Lifecycle L1 Independent lifecycle of bundles without JVM restarts. • L1 - Module L0 A module (or bundle) uses classes from other bundles in a controlled way. • L0 - Execution environment Well defined profiles (JavaSE, CDC) that define the JVM environment.
  • 7. Module Layer • Unit of deployment L3 A module is called a bundle in OSGi. L2 • Standard JAR file with metadata L1 Metadata in META-INF/MANIFEST.MF • Seperate classloader per bundle L0 Class sharing at the Java package level. • Share only “interface” packages Share only API between bundles.
  • 8. Module Layer (2) • Multi-version support L3 Different bundles can see different versions. L2 • Manifest example L1 Bundle-Name: Example Bundle-SymbolicName: net.foo.common Bundle-Version: 1.0.0 L0 Import-Package: org.osgi.framework;version=”1.3”, net.foo.api;version=”1.0.0” Export-Package: net.foo.common;version=”1.0.0” Private-Package: net.foo.common.internal, net.foo.common.internal.codec Bundle-ManifestVersion: 2
  • 9. Lifecycle Layer • Managed lifecycle L3 Managed states for each bundle. L2 • Update existing bundles L1 Dynamically install, start, update and uninstall. L0
  • 10. Service Layer • Service registry L3 Publish/find/bind services at runtime. L2 • Bind interfaces L1 Bind interfaces - not implementations. L0 Registry publish find Provider Requester interact
  • 12. Password Encoder • Password encoder application Simple JVM client that uses password encoders. • Encoders are pluggable Multiple implementations. Can be stopped/started at runtime.
  • 13. Project Structure • API Bundle API Holds all public avaliable APIs. Encoder • Encoder Bundle Client Provides a password encoder implementation. Parent • Client Bundle Client bundle that uses one or more password encoders.
  • 14. API Bundle • Provides the API API Simple PasswordEncoder interface. Encoder • Exports package Client Export the API (net.foo.api) package so other bundles can see it.
  • 15. Password Encoder package net.foo.api; API /** * Simple interface that defines the password Encoder * encoder. */ public interface PasswordEncoder Client { /** * Returns the name of this encoder. */ public String getName(); /** * Encode the password and return the encoded password. */ public String encode(String password); }
  • 16. Manifest • Exports the package API Exports package (net.foo.api) with right version. Encoder ... Bundle-Name: Example - API Client Bundle-SymbolicName: net.foo.api Export-Package: net.foo.api;version=”1.0.0” ...
  • 17. Encoder Bundle • Uses the API API Imports proper API package (net.foo.api). Encoder • Registers a provider Client Registers a PasswordEncoder provider implementation as a service. • Hides the implementation Hides implementation from other bundles by using Private-Package.
  • 18. Register a Service • Use a BundleActivator API Implement bundle activator that handle lifecycle. Encoder • Register on start Client Register service on when bundle is started. • Unregister at stop Unregister the service when bundle is stopped. • Add proper metadata Do not forget to add Bundle-Activator metadata in manifest.
  • 19. Bundle Activator package net.foo.encoder; API import net.foo.api.*; import org.osgi.framework.*; Encoder public class Activator implements BundleActivator Client { private ServiceRegistration reg; public void start(BundleContext context) { this.reg = context.registerService( PasswordEncoder.class.getName(), new ReversePasswordEncoder(), null); } public void stop(BundleContext context) { this.reg.unregister(); } }
  • 20. Manifest • Declare BundleActivator API Set the bundle activator classname in manifest. Encoder • Import used packages Client Import net.foo.api and org.osgi.framework packages with right version. • Hide implementation package Declare net.foo.encoder package as a private package.
  • 21. Manifest (2) ... API Bundle-Name: Example - Encoder Bundle-SymbolicName: net.foo.encoder Bundle-Activator: Encoder net.foo.encoder.Activator Import-Package: net.foo.api;version=”1.0.0”, org.osgi.framework;version=”1.3” Client Private-Package: net.foo.encoder ...
  • 22. Client Bundle • Uses the API API Does not see the encoder implementation. Encoder • Track PasswordEncoder’s Client Track available password encoder providers. • Encodes password based on encoder Finds right encoder and encodes the password.
  • 23. Locating Services • Services are dynamic API All services can be added and removed runtime. Encoder • Not always available on init Client Do not assume that you can always obtain a service during initialization. • Use ServiceTracker Use ServiceTracker to track available services. Remember to open() and close() the tracker.
  • 24. Using ServiceTracker public class Activator implements BundleActivator API { private ServiceTracker tracker; Encoder public void start(BundleContext context) { tracker = new ServiceTracker( Client context, PasswordEncoder.class.getName(), null); tracker.open(); } public void stop(BundleContext context) { tracker.close(); } public class MyConsumer } { private ServiceTracker tracker; ... public void consumeServices() { Object[] services = tracker.getServices(); } }
  • 25. Client Implementation public class Client API { private ServiceTracker tracker; Encoder ... public String encode(String method, String password) Client { for (Object service : tracker.getServices()) { PasswordEncoder enc = (PasswordEncoder)service; if (enc.getName().equals(method)) { return enc.encode(password); } } throw new IllegalArgumentException(“Provider not found”); } }
  • 26. Manifest ... API Bundle-Name: Example - Client Bundle-SymbolicName: net.foo.client Bundle-Activator: Encoder net.foo.client.Activator Import-Package: net.foo.api;version=”1.0.0”, Client org.osgi.framework;version=”1.3”, org.osgi.util.tracker;version=”1.3” Private-Package: net.foo.client ...
  • 27. Improvements • Use a declarative service model Hides OSGi details. Makes service tracking easy. Spring DM is one implementation. • Use automatic manifest creation Use Maven Bundle Plugin (Apache Felix Project) to create and validate manifest entries at build time.
  • 28. Demo
  • 29. Tools Used • Maven 2 Build the project using Maven 2 using standard layout. • Maven Bundle Plugin Creates and validates the MANIFEST.MF. Based on BND. • Maven Pax Plugin Running the OSGi application using Pax Runner. • Felix OSGi Container Implementation of R4.1 specification.
  • 30. 3rd Party Bundles • Pax Web Web container based on Jetty. Implementation of HttpService. • Pax Logging Logging abstraction and LogService implementation. Possible to use SLF4J, Commons Logging and Log4J in bundles. • Felix WebConsole Web Console to visualize bundles and services.

Editor's Notes