Pet
                                     er K
                                            rien
                                                s, a
                                                       Qu
                                                         te
                  grav   e, IBM
        B   J Har




                           OSGi Puzzlers
Tuesday, March 22, 2011
1. Attachment

   H1                                                  H2
         Bundle-SymbolicName: foo.host                      Bundle-SymbolicName: foo.host
         Bundle-Version: 1.0                                Bundle-Version: 2.0


                          F
                              Bundle-SymbolicName: foo.fragment
                              Fragment-Host: foo.host; version=”[1.0,2.0)”




Tuesday, March 22, 2011
To what host(s) does fragment F attach when
    resolved?

   H1                                                  H2
         Bundle-SymbolicName: foo.host                      Bundle-SymbolicName: foo.host
         Bundle-Version: 1.0                                Bundle-Version: 2.0


                          F
                              Bundle-SymbolicName: foo.fragment
                              Fragment-Host: foo.host; version=”[1.0,2.0)”




        (a) F attaches to only H1
        (b) F attaches to only H2
        (c) F attaches to both H1 and H2
        (d) F does not attach to either H1 or H2


Tuesday, March 22, 2011
To what host(s) does fragment F attach when
    resolved?

       (a) F attaches to only H1
       (b) F attaches to only H2
       (c) F attaches to both H1 and H2
       (d) F does not attach to either H1 or H2

       bundle-version is the proper attribute! Note: in
       4.3 attribute matching is now supported, so the
       answer will be (d)!




Tuesday, March 22, 2011
Solution

   H1                                                  H2
         Bundle-SymbolicName: foo.host                      Bundle-SymbolicName: foo.host
         Bundle-Version: 1.0                                Bundle-Version: 2.0


                          F
                              Bundle-SymbolicName: foo.fragment
                              Fragment-Host: foo.host; bundle-version=”[1.0,2.0)”




Tuesday, March 22, 2011
2. Waiting For Service

     Thread 1
    // a service in which the tracker is interested is registered

    ...

    Waiter waiter;
    public T addingService(ServiceReference<S> reference) {
        synchronized (waiter) {
            waiter.notify(); // tell waiter about the service
        }
        return super.addingService(reference);
    }



     Thread 2
    // waiter object
    ServiceTracker tracker;
    void waitingForService {
        synchronized (this) {
            wait(); // waiting here for a service
        }
        T service = tracker.getService();
        System.out.println(service);
    }



Tuesday, March 22, 2011
What is printed by Thread 2?

     Thread 1
    // a service in which the tracker is interested is registered

    ...

    Waiter waiter;
                                                                    (a) nothing; thread
    public T addingService(ServiceReference<S> reference) {
        synchronized (waiter) {                                     2 does not reach
            waiter.notify(); // tell waiter about the service
        }
        return super.addingService(reference);
                                                                    println
    }
                                                                    (b) the service
     Thread 2                                                       object
    // waiter object
    ServiceTracker tracker;                                         (c) null
                                                                    (d) none of the
    void waitingForService {
        synchronized (this) {
            wait(); // waiting here for a service
        }
        T service = tracker.getService();
                                                                    above
        System.out.println(service);
    }



Tuesday, March 22, 2011
What is printed by Thread 2?




    (a) nothing; thread 2 does not reach println
    (b) the service object
    (c) null
    (d) none of the above: race condition

    The answer can be (b) or (c) depending on how the
    race works out.


Tuesday, March 22, 2011
Another Look

     Thread 1
    Waiter waiter;
    public T addingService(ServiceReference<S> reference) {
        synchronized (waiter) {
            waiter.notify(); // tell waiter about the service
        }
        return super.addingService(reference);
        // until this method returns, the tracker is not actually tracking the service!
    }



     Thread 2
    // waiter object
    ServiceTracker tracker;
    void waitingForService {
        synchronized (this) {
            wait(); // waiting here for a service
        }
        T service = tracker.getService();
        System.out.println(service);
    }




Tuesday, March 22, 2011
3. Activator

     Component Description
    <component name="example.activator">
      <implementation class="com.acme.Activator"/>
    </component>




    Component Implementation
    public class Activator {
        private String data = null;
        public Activator() {
            data = “initialized”;
        }
        private void activate(ComponentContext context) {
            System.out.println(data);
        }
    }




Tuesday, March 22, 2011
What is printed by the activate method?

     Component Description
    <component name="example.activator">

                                                            (a) null
      <implementation class="com.acme.Activator"/>
    </component>


                                                            (b) initialized
    Component Implementation                                (c) throws
    public class Activator {                                exception
        private String data = null;
        public Activator() {
            data = “initialized”;
                                                            (d) none of the
        }
        private void activate(ComponentContext context) {
                                                            above
            System.out.println(data);
        }
    }




Tuesday, March 22, 2011
What is printed by the activate method?

     (a) null
     (b) initialized
     (c) throws exception
     (d) none of the above: activate method is not
     called

     The component description does not specify a
     namespace and thus is the DS 1.0 namespace. DS
     1.0 required the activate method to be at least
     protected!

Tuesday, March 22, 2011
One Solution: Change accessibility

     Component Description
    <component name="example.activator">
      <implementation class="com.acme.Activator"/>
    </component>




    Component Implementation
    public class Activator {
        private String data = null;
        public Activator() {
            data = “initialized”;
        }
        protected void activate(ComponentContext context) {
            System.out.println(data);
        }
    }




Tuesday, March 22, 2011
Better Solution: Specify the DS 1.1 namespace

     Component Description
    <scr:component name="example.activator"
        xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
      <implementation class="com.acme.Activator"/>
    </scr:component>




    Component Implementation
    public class Activator {
        private String data = null;
        public Activator() {
            data = “initialized”;
        }
        private void activate(ComponentContext context) {
            System.out.println(data);
        }
    }




Tuesday, March 22, 2011
Tuesday, March 22, 2011

More Related Content

PDF
Chat Room System using Java Swing
PDF
Concurrecy techdrop
PDF
IKH331-07-java-rmi
PDF
Kamaelia Protocol Walkthrough
PDF
Lecture11 b
PDF
Java Concurrency Idioms
PPT
Java concurrency begining
PPT
Baocao Web Tech Java Mail
Chat Room System using Java Swing
Concurrecy techdrop
IKH331-07-java-rmi
Kamaelia Protocol Walkthrough
Lecture11 b
Java Concurrency Idioms
Java concurrency begining
Baocao Web Tech Java Mail

What's hot (20)

PPT
C# Application program UNIT III
PPTX
Servlets
PDF
Advanced Java Practical File
PPTX
PDF
Java Concurrency Gotchas
PDF
Akka cluster overview at 010dev
DOCX
PDF
Overview of Android Infrastructure
PDF
JAVA NIO
PDF
The Ring programming language version 1.7 book - Part 52 of 196
PDF
Python concurrency: libraries overview
PPT
Python Evolution
ODP
Concurrent Programming in Java
KEY
DOC
Ad java prac sol set
PPT
NIO.2, the I/O API for the future
PDF
The Ring programming language version 1.3 book - Part 7 of 88
PDF
Active Software Documentation using Soul and IntensiVE
PDF
Java9 Beyond Modularity - Java 9 más allá de la modularidad
PDF
02 - Basics of Qt
C# Application program UNIT III
Servlets
Advanced Java Practical File
Java Concurrency Gotchas
Akka cluster overview at 010dev
Overview of Android Infrastructure
JAVA NIO
The Ring programming language version 1.7 book - Part 52 of 196
Python concurrency: libraries overview
Python Evolution
Concurrent Programming in Java
Ad java prac sol set
NIO.2, the I/O API for the future
The Ring programming language version 1.3 book - Part 7 of 88
Active Software Documentation using Soul and IntensiVE
Java9 Beyond Modularity - Java 9 más allá de la modularidad
02 - Basics of Qt
Ad

Viewers also liked (18)

PDF
Services-First Migration to OSGi
KEY
OSGi 4.3 Technical Update: What's New?
PDF
OSGi for Enterprises
PDF
What's new in the OSGi Enterprise Release 5.0
PDF
Field injection, type safe configuration, and more new goodies in Declarative...
PDF
Avoid the chaos - Handling 100+ OSGi Components - Balázs Zsoldos
PDF
Why OSGi?
PDF
Hands on with lightweight m2m and Eclipse Leshan
PPTX
How to RSS Feed in Search Engine Optimization and their Benefits.
PDF
Millennials in the Workplace copy
DOC
Holistic Approach To Saving Energy Dr Shriiwas Kashalikar
PPT
Texas S Ta R Chart, Pp, Lamar
PDF
A Look at Structural Claims
PPTX
vitamin c
PDF
1. Why is the Gospel Important?
PDF
PSE Insights: Manufacturing
PDF
Project communication plan v1c cmmaao pmi pmp
PPTX
Be the Professional Realtor
Services-First Migration to OSGi
OSGi 4.3 Technical Update: What's New?
OSGi for Enterprises
What's new in the OSGi Enterprise Release 5.0
Field injection, type safe configuration, and more new goodies in Declarative...
Avoid the chaos - Handling 100+ OSGi Components - Balázs Zsoldos
Why OSGi?
Hands on with lightweight m2m and Eclipse Leshan
How to RSS Feed in Search Engine Optimization and their Benefits.
Millennials in the Workplace copy
Holistic Approach To Saving Energy Dr Shriiwas Kashalikar
Texas S Ta R Chart, Pp, Lamar
A Look at Structural Claims
vitamin c
1. Why is the Gospel Important?
PSE Insights: Manufacturing
Project communication plan v1c cmmaao pmi pmp
Be the Professional Realtor
Ad

Similar to OSGi Puzzlers (20)

PDF
The Ring programming language version 1.6 book - Part 184 of 189
ODP
PDF
Multithreading in Java
PDF
Migrating from Ext GWT 2.x to 3.0
PDF
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
PPTX
Async Best Practices
PDF
C++aptitude questions and answers
PPT
Mobicents JSLEE progress and roadmap - Mobicents Summit 2011
PPT
Deuce STM - CMP'09
PPTX
The Taverna 2 Platform
PDF
Demoiselle 2.0 no JavaOne Brasil 2010
PPT
Generalized Functors - Realizing Command Design Pattern in C++
PDF
C++ aptitude
PDF
The Ring programming language version 1.8 book - Part 95 of 202
PPTX
Object Oriented Programming using C++: Ch08 Operator Overloading.pptx
PPTX
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
PPTX
C++ Functions
PDF
Netty from the trenches
PDF
mininet-intro.pdf
PDF
Reactive programming with tracker
The Ring programming language version 1.6 book - Part 184 of 189
Multithreading in Java
Migrating from Ext GWT 2.x to 3.0
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Async Best Practices
C++aptitude questions and answers
Mobicents JSLEE progress and roadmap - Mobicents Summit 2011
Deuce STM - CMP'09
The Taverna 2 Platform
Demoiselle 2.0 no JavaOne Brasil 2010
Generalized Functors - Realizing Command Design Pattern in C++
C++ aptitude
The Ring programming language version 1.8 book - Part 95 of 202
Object Oriented Programming using C++: Ch08 Operator Overloading.pptx
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
C++ Functions
Netty from the trenches
mininet-intro.pdf
Reactive programming with tracker

Recently uploaded (20)

PDF
Five Habits of High-Impact Board Members
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
The various Industrial Revolutions .pptx
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPT
What is a Computer? Input Devices /output devices
DOCX
search engine optimization ppt fir known well about this
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PPTX
observCloud-Native Containerability and monitoring.pptx
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
STKI Israel Market Study 2025 version august
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
Modernising the Digital Integration Hub
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPT
Geologic Time for studying geology for geologist
PDF
Unlock new opportunities with location data.pdf
Five Habits of High-Impact Board Members
DP Operators-handbook-extract for the Mautical Institute
The various Industrial Revolutions .pptx
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
What is a Computer? Input Devices /output devices
search engine optimization ppt fir known well about this
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
observCloud-Native Containerability and monitoring.pptx
Chapter 5: Probability Theory and Statistics
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
STKI Israel Market Study 2025 version august
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Hybrid model detection and classification of lung cancer
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Modernising the Digital Integration Hub
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
A contest of sentiment analysis: k-nearest neighbor versus neural network
Geologic Time for studying geology for geologist
Unlock new opportunities with location data.pdf

OSGi Puzzlers

  • 1. Pet er K rien s, a Qu te grav e, IBM B J Har OSGi Puzzlers Tuesday, March 22, 2011
  • 2. 1. Attachment H1 H2 Bundle-SymbolicName: foo.host Bundle-SymbolicName: foo.host Bundle-Version: 1.0 Bundle-Version: 2.0 F Bundle-SymbolicName: foo.fragment Fragment-Host: foo.host; version=”[1.0,2.0)” Tuesday, March 22, 2011
  • 3. To what host(s) does fragment F attach when resolved? H1 H2 Bundle-SymbolicName: foo.host Bundle-SymbolicName: foo.host Bundle-Version: 1.0 Bundle-Version: 2.0 F Bundle-SymbolicName: foo.fragment Fragment-Host: foo.host; version=”[1.0,2.0)” (a) F attaches to only H1 (b) F attaches to only H2 (c) F attaches to both H1 and H2 (d) F does not attach to either H1 or H2 Tuesday, March 22, 2011
  • 4. To what host(s) does fragment F attach when resolved? (a) F attaches to only H1 (b) F attaches to only H2 (c) F attaches to both H1 and H2 (d) F does not attach to either H1 or H2 bundle-version is the proper attribute! Note: in 4.3 attribute matching is now supported, so the answer will be (d)! Tuesday, March 22, 2011
  • 5. Solution H1 H2 Bundle-SymbolicName: foo.host Bundle-SymbolicName: foo.host Bundle-Version: 1.0 Bundle-Version: 2.0 F Bundle-SymbolicName: foo.fragment Fragment-Host: foo.host; bundle-version=”[1.0,2.0)” Tuesday, March 22, 2011
  • 6. 2. Waiting For Service Thread 1 // a service in which the tracker is interested is registered ... Waiter waiter; public T addingService(ServiceReference<S> reference) { synchronized (waiter) { waiter.notify(); // tell waiter about the service } return super.addingService(reference); } Thread 2 // waiter object ServiceTracker tracker; void waitingForService { synchronized (this) { wait(); // waiting here for a service } T service = tracker.getService(); System.out.println(service); } Tuesday, March 22, 2011
  • 7. What is printed by Thread 2? Thread 1 // a service in which the tracker is interested is registered ... Waiter waiter; (a) nothing; thread public T addingService(ServiceReference<S> reference) { synchronized (waiter) { 2 does not reach waiter.notify(); // tell waiter about the service } return super.addingService(reference); println } (b) the service Thread 2 object // waiter object ServiceTracker tracker; (c) null (d) none of the void waitingForService { synchronized (this) { wait(); // waiting here for a service } T service = tracker.getService(); above System.out.println(service); } Tuesday, March 22, 2011
  • 8. What is printed by Thread 2? (a) nothing; thread 2 does not reach println (b) the service object (c) null (d) none of the above: race condition The answer can be (b) or (c) depending on how the race works out. Tuesday, March 22, 2011
  • 9. Another Look Thread 1 Waiter waiter; public T addingService(ServiceReference<S> reference) { synchronized (waiter) { waiter.notify(); // tell waiter about the service } return super.addingService(reference); // until this method returns, the tracker is not actually tracking the service! } Thread 2 // waiter object ServiceTracker tracker; void waitingForService { synchronized (this) { wait(); // waiting here for a service } T service = tracker.getService(); System.out.println(service); } Tuesday, March 22, 2011
  • 10. 3. Activator Component Description <component name="example.activator"> <implementation class="com.acme.Activator"/> </component> Component Implementation public class Activator { private String data = null; public Activator() { data = “initialized”; } private void activate(ComponentContext context) { System.out.println(data); } } Tuesday, March 22, 2011
  • 11. What is printed by the activate method? Component Description <component name="example.activator"> (a) null <implementation class="com.acme.Activator"/> </component> (b) initialized Component Implementation (c) throws public class Activator { exception private String data = null; public Activator() { data = “initialized”; (d) none of the } private void activate(ComponentContext context) { above System.out.println(data); } } Tuesday, March 22, 2011
  • 12. What is printed by the activate method? (a) null (b) initialized (c) throws exception (d) none of the above: activate method is not called The component description does not specify a namespace and thus is the DS 1.0 namespace. DS 1.0 required the activate method to be at least protected! Tuesday, March 22, 2011
  • 13. One Solution: Change accessibility Component Description <component name="example.activator"> <implementation class="com.acme.Activator"/> </component> Component Implementation public class Activator { private String data = null; public Activator() { data = “initialized”; } protected void activate(ComponentContext context) { System.out.println(data); } } Tuesday, March 22, 2011
  • 14. Better Solution: Specify the DS 1.1 namespace Component Description <scr:component name="example.activator" xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"> <implementation class="com.acme.Activator"/> </scr:component> Component Implementation public class Activator { private String data = null; public Activator() { data = “initialized”; } private void activate(ComponentContext context) { System.out.println(data); } } Tuesday, March 22, 2011