SlideShare a Scribd company logo
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

What's hot

Baocao Web Tech Java Mail
Baocao Web Tech Java MailBaocao Web Tech Java Mail
Baocao Web Tech Java Mail
xicot
 
C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT III
Minu Rajasekaran
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
Soumya Behera
 
Akka cluster overview at 010dev
Akka cluster overview at 010devAkka cluster overview at 010dev
Akka cluster overview at 010dev
Roland Kuhn
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 
Python concurrency: libraries overview
Python concurrency: libraries overviewPython concurrency: libraries overview
Python concurrency: libraries overview
Andrii Mishkovskyi
 
Active Software Documentation using Soul and IntensiVE
Active Software Documentation using Soul and IntensiVEActive Software Documentation using Soul and IntensiVE
Active Software Documentation using Soul and IntensiVE
kim.mens
 

What's hot (20)

Baocao Web Tech Java Mail
Baocao Web Tech Java MailBaocao Web Tech Java Mail
Baocao Web Tech Java Mail
 
C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT III
 
Servlets
ServletsServlets
Servlets
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
 
NIO and NIO2
NIO and NIO2NIO and NIO2
NIO and NIO2
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
Akka cluster overview at 010dev
Akka cluster overview at 010devAkka cluster overview at 010dev
Akka cluster overview at 010dev
 
srgoc
srgocsrgoc
srgoc
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
JAVA NIO
JAVA NIOJAVA NIO
JAVA NIO
 
The Ring programming language version 1.7 book - Part 52 of 196
The Ring programming language version 1.7 book - Part 52 of 196The Ring programming language version 1.7 book - Part 52 of 196
The Ring programming language version 1.7 book - Part 52 of 196
 
Python concurrency: libraries overview
Python concurrency: libraries overviewPython concurrency: libraries overview
Python concurrency: libraries overview
 
Python Evolution
Python EvolutionPython Evolution
Python Evolution
 
Concurrent Programming in Java
Concurrent Programming in JavaConcurrent Programming in Java
Concurrent Programming in Java
 
Clojure: a LISP for the JVM
Clojure: a LISP for the JVMClojure: a LISP for the JVM
Clojure: a LISP for the JVM
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
NIO.2, the I/O API for the future
NIO.2, the I/O API for the futureNIO.2, the I/O API for the future
NIO.2, the I/O API for the future
 
The Ring programming language version 1.3 book - Part 7 of 88
The Ring programming language version 1.3 book - Part 7 of 88The Ring programming language version 1.3 book - Part 7 of 88
The Ring programming language version 1.3 book - Part 7 of 88
 
Active Software Documentation using Soul and IntensiVE
Active Software Documentation using Soul and IntensiVEActive Software Documentation using Soul and IntensiVE
Active Software Documentation using Soul and IntensiVE
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidad
 

Viewers also liked

Millennials in the Workplace copy
Millennials in the Workplace copyMillennials in the Workplace copy
Millennials in the Workplace copy
D'Shai Hendricks
 
Holistic Approach To Saving Energy Dr Shriiwas Kashalikar
Holistic Approach To Saving Energy Dr Shriiwas KashalikarHolistic Approach To Saving Energy Dr Shriiwas Kashalikar
Holistic Approach To Saving Energy Dr Shriiwas Kashalikar
drrima
 
Texas S Ta R Chart, Pp, Lamar
Texas S Ta R Chart, Pp, LamarTexas S Ta R Chart, Pp, Lamar
Texas S Ta R Chart, Pp, Lamar
randymarshall
 
Project communication plan v1c cmmaao pmi pmp
Project communication plan v1c cmmaao pmi pmpProject communication plan v1c cmmaao pmi pmp
Project communication plan v1c cmmaao pmi pmp
vishvasyadav45
 

Viewers also liked (18)

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

Similar to OSGi Puzzlers

Mobicents JSLEE progress and roadmap - Mobicents Summit 2011
Mobicents JSLEE progress and roadmap - Mobicents Summit 2011Mobicents JSLEE progress and roadmap - Mobicents Summit 2011
Mobicents JSLEE progress and roadmap - Mobicents Summit 2011
telestax
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Mario Fusco
 

Similar to OSGi Puzzlers (20)

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

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 

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