Scala modules
Upcoming SlideShare
Loading in...5
×
 

Scala modules

on

  • 1,486 views

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.

Statistics

Views

Total Views
1,486
Views on SlideShare
1,225
Embed Views
261

Actions

Likes
0
Downloads
12
Comments
0

3 Embeds 261

http://skillsmatter.com 227
http://smash 33
http://85.92.73.37 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Scala modules Scala modules Presentation Transcript

  • 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 late-binding of all things.”
  • Late Binding with Services • Services answer the question:where do I get an implementation of this interface? • The registry decentralises the architecture.
  • 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.getServiceReference(Greeting.class.getName()); Greeting greeting = (Greeting) context.getService(ref); System.out.println(greeting.getMessage()); }
  • 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
  • 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()); } }
  • 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
  • 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()); } } }
  • 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
  • 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); } }
  • 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
  • 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); } } }
  • 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
  • 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
  • An Answer: Stop Writing Code!
  • Declarative Services (DS) @Reference public void setGreeting(Greeting greeting) { this.greeting = greeting; } public void consumeService() { System.out.println(greeting.getMessage()); }
  • 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>
  • Problem • These frameworks provide abstractions • Abstraction hide detail • Sometimes we need the detail
  • Example: Cardinality? Service Service Component Service Service
  • Single Service Service Component Service Service
  • Multiple Service Service Component Service Service
  • ??? Component Service Component Service Component Service Component Service Not supported by DS
  • 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 Java
  • The “80%” Solution “Normal” Users DS support “Power” Users Easy in Java
  • The “80%” Solution “Normal” Users DS support “Power” Users Easy in Java Easy in Scala
  • The “80%” Solution “Normal” Users DS support “Power” Users Easy in Java Easy in Scala
  • 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(); } });
  • 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???
  • 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(), 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(); } });
  • ScalaModules val greetingTrack = context track classOf[Greeting] on { case Adding(greeting) => context createService (classOf[IFoo], new Foo(greeting)) case Removed(_, reg) => reg unregister }
  • 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
  • Get Involved http://www.eclipse.org/forums/ eclipse.scalamodules