OSGi Puzzlers
Neil Bartlett and Peter Kriens
Overlapping Concerns...
What Does it Print?
MyService
P1

P2

Example
Component

NOW STOP BUNDLE P1...

MyService
CKFU!
(OBVIOUSLY)
WTF?

OSGi Compendium, section 112.5.10 Dynamic Service
Replacement
“SCR must first bind a replacement target service and t...
Beware this Pattern
@Component
public class ExampleComponent {


 private MyService svc;


 @Reference(dynamic = true)

 p...
Better...
@Component
public class ExampleComponent {


 private MyService svc;


 @Reference(dynamic = true)

 public sync...
Even Better...
@Component
public class ExampleComponent {


 private final AtomicReference<MyService> svcRef

 
 = new Atom...
Stooopid Hoooman...
What Does It Print?

A. 0,1,2,3,4,5,6,7,8,9,...
B. 1,
C. 1,2,3,4,5,6,7,8,9,....
D. NullPointerException
What Does It Print?

A. 0,1,2,3,4,5,6,7,8,9,...
B. 1,
C. 1,2,3,4,5,6,7,8,9,....
D. NullPointerException
WTF?
Blacklisting
EventHandlers have to return quickly
If they don’t... BLACKLIST! No more events for you.
Humans are slow and ...
You Gotta Start Me Up...
What Does It Print?

A. “Constructed...Started.”
B. “Constructed...”
C. Nothing
D. IllegalAccessException
E. “Started.”
What Does It Print?

A. “Constructed...Started.”
B. “Constructed...”
C. Nothing
D. IllegalAccessException
E. “Started.”
WTF?

DS Services are Lazy
Not an error... just waiting for a consumer!
REMEMBER:

OSGi is Your Friend!
Upcoming SlideShare
Loading in...5
×

OSGi Puzzlers - Neil Bartlett & Peter Kriens

1,281

Published on

OSGi Community Event 2013 (http://www.osgi.org/CommunityEvent2013/Schedule)

Lightning Talk

ABSTRACT
A fun look at some of the traps and pitfalls that people come across when working with OSGi, along with suggestions on how you should deal with these cases in point.

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,281
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
30
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

OSGi Puzzlers - Neil Bartlett & Peter Kriens

  1. 1. OSGi Puzzlers Neil Bartlett and Peter Kriens
  2. 2. Overlapping Concerns...
  3. 3. What Does it Print? MyService P1 P2 Example Component NOW STOP BUNDLE P1... MyService
  4. 4. CKFU! (OBVIOUSLY)
  5. 5. WTF? OSGi Compendium, section 112.5.10 Dynamic Service Replacement “SCR must first bind a replacement target service and then unbind the outgoing service” (emphasis added)
  6. 6. Beware this Pattern @Component public class ExampleComponent { private MyService svc; @Reference(dynamic = true) public void setMyService(MyService svc) { this.svc = svc; } public void unsetMyService(MyService svc) { this.svc = null; // OOOPS! } }
  7. 7. Better... @Component public class ExampleComponent { private MyService svc; @Reference(dynamic = true) public synchronized void setMyService(MyService svc) { this.svc = svc; } public synchronized void unsetMyService(MyService svc) { if (this.svc == svc) this.svc = null; } }
  8. 8. Even Better... @Component public class ExampleComponent { private final AtomicReference<MyService> svcRef = new AtomicReference<>(); @Reference(dynamic = true) public void setMyService(MyService svc) { svcRef.set(svc); } public void unsetMyService(MyService svc) { svcRef.compareAndSet(svc, null); } }
  9. 9. Stooopid Hoooman...
  10. 10. What Does It Print? A. 0,1,2,3,4,5,6,7,8,9,... B. 1, C. 1,2,3,4,5,6,7,8,9,.... D. NullPointerException
  11. 11. What Does It Print? A. 0,1,2,3,4,5,6,7,8,9,... B. 1, C. 1,2,3,4,5,6,7,8,9,.... D. NullPointerException
  12. 12. WTF?
  13. 13. Blacklisting EventHandlers have to return quickly If they don’t... BLACKLIST! No more events for you. Humans are slow and stooopid. Turn off blacklisting, OR use printf-style debugging
  14. 14. You Gotta Start Me Up...
  15. 15. What Does It Print? A. “Constructed...Started.” B. “Constructed...” C. Nothing D. IllegalAccessException E. “Started.”
  16. 16. What Does It Print? A. “Constructed...Started.” B. “Constructed...” C. Nothing D. IllegalAccessException E. “Started.”
  17. 17. WTF? DS Services are Lazy Not an error... just waiting for a consumer!
  18. 18. REMEMBER: OSGi is Your Friend!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×