Uploaded on

ScalaModules is an elegant and intuitive domain specific language for OSGi development written in the Scala programming language. …

ScalaModules is an elegant and intuitive domain specific language for OSGi development written in the Scala programming language.

In this podcast, Neil Bartlett examines the differences between java and scala osgi implementations. He also shared his views on the advantages of scalamodules for osgi.

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
982
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
12
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. ScalaModules Scala and OSGi
  • 2. OSGi Services • The key to modularity • Arguably, the key to OOP itself?
  • 3. Dr Alan Kay
  • 4. Dr Alan Kay “Dude I invented friggin’ OOP. Have you heard of it?”
  • 5. Dr Alan Kay “OOP to me means only messaging, local retention and protection and hiding of state- process, and extreme late-binding of all things.”
  • 6. Late Binding with Services • Services answer the question:where do I get an implementation of this interface? • The registry decentralises the architecture.
  • 7. Consuming Services
  • 8. Harder than Expected!
  • 9. Why...?
  • 10. Slippery
  • 11. Dynamics • A service can come and go • At any time • On any thread • Yes... even while you’re using it
  • 12. Result • Service usage code can be very complex
  • 13. Service Consumption in Java
  • 14. Consuming a Service public void consumeService(BundleContext context) { ServiceReference ref = context.getServiceReference(Greeting.class.getName()); Greeting greeting = (Greeting) context.getService(ref); System.out.println(greeting.getMessage()); }
  • 15. Consuming a Service public void consumeService(BundleContext context) { ServiceReference ref = context.getServiceReference(Greeting.class.getName()); Greeting greeting = (Greeting) context.getService(ref); System.out.println(greeting.getMessage()); } WRONG
  • 16. Consuming a Service public void consumeService(BundleContext context) { ServiceReference ref = context.getServiceReference(Greeting.class.getName()); if(ref != null) { Greeting greeting = (Greeting) context.getService(ref); System.out.println(greeting.getMessage()); } }
  • 17. Consuming a Service public void consumeService(BundleContext context) { ServiceReference ref = context.getServiceReference(Greeting.class.getName()); if(ref != null) { Greeting greeting = (Greeting) context.getService(ref); System.out.println(greeting.getMessage()); } } WRONG
  • 18. Consuming a Service public void consumeService(BundleContext context) { ServiceReference ref = context.getServiceReference(Greeting.class.getName()); if(ref != null) { Greeting greeting = (Greeting) context.getService(ref); if(greeting != null) { System.out.println(greeting.getMessage()); } } }
  • 19. Consuming a Service public void consumeService(BundleContext context) { ServiceReference ref = context.getServiceReference(Greeting.class.getName()); if(ref != null) { Greeting greeting = (Greeting) context.getService(ref); if(greeting != null) { System.out.println(greeting.getMessage()); } } } WRONG
  • 20. Consuming a Service public void consumeService(BundleContext context) { ServiceReference ref = context.getServiceReference(Greeting.class.getName()); if(ref != null) { Greeting greeting = (Greeting) context.getService(ref); if(greeting != null) { System.out.println(greeting.getMessage()); } context.ungetService(ref); } }
  • 21. Consuming a Service public void consumeService(BundleContext context) { ServiceReference ref = context.getServiceReference(Greeting.class.getName()); if(ref != null) { Greeting greeting = (Greeting) context.getService(ref); if(greeting != null) { System.out.println(greeting.getMessage()); } context.ungetService(ref); } } WRONG
  • 22. Consuming a Service public void consumeService(BundleContext context) { ServiceReference ref = context.getServiceReference(Greeting.class.getName()); if(ref != null) { try { Greeting greeting = (Greeting) context.getService(ref); if(greeting != null) { System.out.println(greeting.getMessage()); } } finally { context.ungetService(ref); } } }
  • 23. Consuming a Service public void consumeService(BundleContext context) { ServiceReference ref = context.getServiceReference(Greeting.class.getName()); if(ref != null) { try { Greeting greeting = (Greeting) context.getService(ref); if(greeting != null) { System.out.println(greeting.getMessage()); } } finally { context.ungetService(ref); } } } NOT TYPE SAFE
  • 24. Consuming a Service public void consumeService(BundleContext context) { ServiceReference ref = context.getServiceReference(Greeting.class.getName()); if(ref != null) { try { Greeting greeting = (Greeting) context.getService(ref); if(greeting != null) { System.out.println(greeting.getMessage()); } } finally { context.ungetService(ref); } } } NOT TYPE SAFE
  • 25. An Answer: Stop Writing Code!
  • 26. Declarative Services (DS) @Reference public void setGreeting(Greeting greeting) { this.greeting = greeting; } public void consumeService() { System.out.println(greeting.getMessage()); }
  • 27. Blueprint public void setGreeting(Greeting greeting) { this.greeting = greeting; } public void consumeService() { System.out.println(greeting.getMessage()); } <blueprint> <reference id="greeting" interface="org.example.Greeting"/> <bean id="foo" class="com.foo.Foo"/> <property name="greeting" ref="greeting"/> </bean> </blueprint>
  • 28. Problem • These frameworks provide abstractions • Abstraction hide detail • Sometimes we need the detail
  • 29. Example: Cardinality? Service Service Component Service Service
  • 30. Single Service Service Component Service Service
  • 31. Multiple Service Service Component Service Service
  • 32. ??? Component Service Component Service Component Service Component Service Not supported by DS
  • 33. Declarative I Services (and Blueprint)
  • 34. Declarative I Services (and Blueprint)
  • 35. The “80%” Solution “Normal” Users
  • 36. The “80%” Solution “Normal” Users DS support
  • 37. The “80%” Solution “Normal” Users DS support
  • 38. The “80%” Solution “Normal” Users DS support “Power” Users
  • 39. The “80%” Solution “Normal” Users DS support “Power” Users
  • 40. The “80%” Solution “Normal” Users DS support “Power” Users Easy in Java
  • 41. The “80%” Solution “Normal” Users DS support “Power” Users Easy in Java
  • 42. The “80%” Solution “Normal” Users DS support “Power” Users Easy in Java Easy in Scala
  • 43. The “80%” Solution “Normal” Users DS support “Power” Users Easy in Java Easy in Scala
  • 44. Java ServiceTracker tracker = new ServiceTracker(context, Greeting.class.getName(), new ServiceTrackerCustomizer() { public Object addingService(ServiceReference reference) { Greeting greeting = (Greeting) context.getService(reference); ServiceRegistration reg = context.registerService(IFoo.class.getName(), new Foo(greeting), null); return reg; } public void modifiedService(ServiceReference reference, Object service) { } public void removedService(ServiceReference reference, Object service) { ServiceRegistration reg = (ServiceRegistration) service; reg.unregister(); } });
  • 45. Java ServiceTracker tracker = new ServiceTracker(context, Greeting.class.getName(), new ServiceTrackerCustomizer() { public Object addingService(ServiceReference reference) { Greeting greeting = (Greeting) context.getService(reference); ServiceRegistration reg = context.registerService(IFoo.class.getName(), new Foo(greeting), null); return reg; } public void modifiedService(ServiceReference reference, Object service) { } public void removedService(ServiceReference reference, Object service) { ServiceRegistration reg = (ServiceRegistration) service; reg.unregister(); } }); Type Safety???
  • 46. What is ScalaModules?
  • 47. NOT Another Module System (phew!)
  • 48. “A Scala internal DSL to ease OSGi development”
  • 49. • Now: • Services • Future: • Extender Pattern? • Resources?
  • 50. An Eclipse Project!
  • 51. Examples
  • 52. Java ServiceTracker tracker = new ServiceTracker(context, Greeting.class.getName(), new ServiceTrackerCustomizer() { public Object addingService(ServiceReference reference) { Greeting greeting = (Greeting) context.getService(reference); ServiceRegistration reg = context.registerService(IFoo.class.getName(), new Foo(greeting), null); return reg; } public void modifiedService(ServiceReference reference, Object service) { } public void removedService(ServiceReference reference, Object service) { ServiceRegistration reg = (ServiceRegistration) service; reg.unregister(); } });
  • 53. ScalaModules val greetingTrack = context track classOf[Greeting] on { case Adding(greeting) => context createService (classOf[IFoo], new Foo(greeting)) case Removed(_, reg) => reg unregister }
  • 54. Plan • Started moving the code & docs to Eclipse • 19 March: M1 • 7 May: M2 • 28 May: RC1 • 11 June: RC2 • 23 June: ScalaModules 2.0 Release & Graduation
  • 55. Get Involved http://www.eclipse.org/forums/ eclipse.scalamodules