OSGi Puzzlers - Neil Bartlett & Peter Kriens

1,691 views
1,515 views

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,691
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
32
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!

×