ScalaModules
   Scala and OSGi
OSGi Services


• The key to modularity
• Arguably, the key to OOP itself?
Dr Alan Kay
Dr Alan Kay

“Dude I
invented
friggin’ OOP.
Have you
heard of it?”
Dr Alan Kay

“OOP to me means only
messaging, local
retention and protection
and hiding of state-
process, and extreme
lat...
Late Binding with
         Services

• Services answer the question:where do I
  get an implementation of this interface?
...
Consuming Services
Harder than Expected!
Why...?
Slippery
Dynamics

• A service can come and go
• At any time
• On any thread
• Yes... even while you’re using it
Result


• Service usage code can be
 very complex
Service Consumption
        in Java
Consuming a Service

public void consumeService(BundleContext context) {
   ServiceReference ref = context.getServiceRefer...
Consuming a Service

public void consumeService(BundleContext context) {
   ServiceReference ref = context.getServiceRefer...
Consuming a Service

public void consumeService(BundleContext context) {
   ServiceReference ref = context.getServiceRefer...
Consuming a Service

public void consumeService(BundleContext context) {
   ServiceReference ref = context.getServiceRefer...
Consuming a Service

    public void consumeService(BundleContext context) {
       ServiceReference ref = context.getServ...
Consuming a Service

    public void consumeService(BundleContext context) {
       ServiceReference ref = context.getServ...
Consuming a Service
public void consumeService(BundleContext context) {
   ServiceReference ref = context.getServiceRefere...
Consuming a Service
public void consumeService(BundleContext context) {
   ServiceReference ref = context.getServiceRefere...
Consuming a Service
public void consumeService(BundleContext context) {
   ServiceReference ref = context.getServiceRefere...
Consuming a Service
public void consumeService(BundleContext context) {
   ServiceReference ref = context.getServiceRefere...
Consuming a Service
public void consumeService(BundleContext context) {
   ServiceReference ref = context.getServiceRefere...
An Answer:
Stop Writing Code!
Declarative Services
              (DS)
@Reference
public void setGreeting(Greeting greeting) {
   this.greeting = greetin...
Blueprint
   public void setGreeting(Greeting greeting) {
      this.greeting = greeting;
   }

   public void consumeServ...
Problem

• These frameworks provide abstractions
• Abstraction hide detail
• Sometimes we need the detail
Example: Cardinality?
                  Service



                  Service

      Component

                  Service

...
Single
            Service



            Service

Component

            Service



            Service
Multiple
            Service



            Service

Component

            Service



            Service
???
  Component         Service



  Component         Service



  Component         Service



  Component         Servi...
Declarative
I    Services
       (and Blueprint)
Declarative
I    Services
       (and Blueprint)
The “80%” Solution
              “Normal” Users
The “80%” Solution
              “Normal” Users
              DS support
The “80%” Solution
              “Normal” Users
              DS support
The “80%” Solution
              “Normal” Users
              DS support
              “Power” Users
The “80%” Solution
              “Normal” Users
              DS support
              “Power” Users
The “80%” Solution
              “Normal” Users
              DS support
              “Power” Users
              Easy in...
The “80%” Solution
              “Normal” Users
              DS support
              “Power” Users
              Easy in...
The “80%” Solution
              “Normal” Users
              DS support
              “Power” Users
              Easy in...
The “80%” Solution
              “Normal” Users
              DS support
              “Power” Users
              Easy in...
Java
ServiceTracker tracker = new ServiceTracker(context, Greeting.class.getName(),
                                      ...
Java
ServiceTracker tracker = new ServiceTracker(context, Greeting.class.getName(),
                                      ...
What is ScalaModules?
NOT Another Module
  System (phew!)
“A Scala internal DSL to ease
    OSGi development”
• Now:
 • Services
• Future:
 • Extender Pattern?
 • Resources?
An Eclipse Project!
Examples
Java
ServiceTracker tracker = new ServiceTracker(context, Greeting.class.getName(),
                                      ...
ScalaModules


val greetingTrack = context track classOf[Greeting] on {
   case Adding(greeting) => context createService ...
Plan
• Started moving the code & docs to Eclipse
• 19 March: M1
• 7 May: M2
• 28 May: RC1
• 11 June: RC2
• 23 June: ScalaM...
Get Involved

http://www.eclipse.org/forums/
      eclipse.scalamodules
Scala modules
Scala modules
Scala modules
Upcoming SlideShare
Loading in...5
×

Scala modules

1,010

Published on

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.

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

  • Be the first to like this

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

No notes for slide

Transcript of "Scala modules"

  1. 1. ScalaModules Scala and OSGi
  2. 2. OSGi Services • The key to modularity • Arguably, the key to OOP itself?
  3. 3. Dr Alan Kay
  4. 4. Dr Alan Kay “Dude I invented friggin’ OOP. Have you heard of it?”
  5. 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. 6. Late Binding with Services • Services answer the question:where do I get an implementation of this interface? • The registry decentralises the architecture.
  7. 7. Consuming Services
  8. 8. Harder than Expected!
  9. 9. Why...?
  10. 10. Slippery
  11. 11. Dynamics • A service can come and go • At any time • On any thread • Yes... even while you’re using it
  12. 12. Result • Service usage code can be very complex
  13. 13. Service Consumption in Java
  14. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 25. An Answer: Stop Writing Code!
  26. 26. Declarative Services (DS) @Reference public void setGreeting(Greeting greeting) { this.greeting = greeting; } public void consumeService() { System.out.println(greeting.getMessage()); }
  27. 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. 28. Problem • These frameworks provide abstractions • Abstraction hide detail • Sometimes we need the detail
  29. 29. Example: Cardinality? Service Service Component Service Service
  30. 30. Single Service Service Component Service Service
  31. 31. Multiple Service Service Component Service Service
  32. 32. ??? Component Service Component Service Component Service Component Service Not supported by DS
  33. 33. Declarative I Services (and Blueprint)
  34. 34. Declarative I Services (and Blueprint)
  35. 35. The “80%” Solution “Normal” Users
  36. 36. The “80%” Solution “Normal” Users DS support
  37. 37. The “80%” Solution “Normal” Users DS support
  38. 38. The “80%” Solution “Normal” Users DS support “Power” Users
  39. 39. The “80%” Solution “Normal” Users DS support “Power” Users
  40. 40. The “80%” Solution “Normal” Users DS support “Power” Users Easy in Java
  41. 41. The “80%” Solution “Normal” Users DS support “Power” Users Easy in Java
  42. 42. The “80%” Solution “Normal” Users DS support “Power” Users Easy in Java Easy in Scala
  43. 43. The “80%” Solution “Normal” Users DS support “Power” Users Easy in Java Easy in Scala
  44. 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. 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. 46. What is ScalaModules?
  47. 47. NOT Another Module System (phew!)
  48. 48. “A Scala internal DSL to ease OSGi development”
  49. 49. • Now: • Services • Future: • Extender Pattern? • Resources?
  50. 50. An Eclipse Project!
  51. 51. Examples
  52. 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. 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. 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. 55. Get Involved http://www.eclipse.org/forums/ eclipse.scalamodules
  1. A particular slide catching your eye?

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

×