W-JAX 09 - ScalaModules

1,641 views

Published on

ScalaModules - OSGi ganz einfach mit einer Scala DSL

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

  • Be the first to like this

No Downloads
Views
Total views
1,641
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
31
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

W-JAX 09 - ScalaModules

  1. 1. SCALAMODULES OSGi ganz einfach mit einer Scala DSL Heiko Seeberger Copyright WeigleWilczek 2009
  2. 2. HOUSTON, WIR HABEN EIN PROBLEM! ServiceReference ref = ctx.getServiceReference(Greeting.class.getName()); if (ref != null) { try { Object service = ctx.getService(ref); Greeting greeting = (Greeting) service; Low-level API if (greeting != null) { Häßliche System.out.println(greeting.welcome()); } else { Details } System.out.println("No Greeting service available!"); } finally { ctx.ungetService(ref); } } else { System.out.println("No Greeting service available!"); } 2
  3. 3. WIE KÖNNTE SCALA HELFEN? Ausdrucksstarke high-level DSL 3
  4. 4. SO ETWAS IN DER ART ... OSGi giveMe Greeting and call welcome 4
  5. 5. WIE BAUE ICH EINE DSL? Implicit Higher-order Conversions Functions Fluent API 5
  6. 6. SCALAMODULES Scala DSL to ease OSGi development 6
  7. 7. SERVICES REGISTRIEREN val hello = new Greeting { ... } automatisch ctx register hello ... unter allen Interfaces 7
  8. 8. SERVICES REGISTRIEREN II val hello = new Greeting { ... } ctx register (hello as classOf[Greeting]) typsicher ... unter einem bestimmten Interface 8
  9. 9. SERVICES REGISTRIEREN III val hello = new Greeting { ... } ctx register (hello withProps ("Scala" -> "Modules")) ... mit Properties 9
  10. 10. LIVE DEMO 10
  11. 11. SERVICES KONSUMIEREN I Funktional ctx getOne classOf[Greeting] andApply { _.welcome } match { case None => // Handle service not available ... case Some(welcome) => println(welcome) } ... nur einen einzelnen 11
  12. 12. SERVICES KONSUMIEREN II ctx getOne classOf[Greeting] andApply { (greeting, properties) => ... } ... nur einen einzelnen mit Properties 12
  13. 13. SERVICES KONSUMIEREN III ctx getMany classOf[Greeting] andApply { _.welcome } match { case Nil => // Handle service not available ... case welcomes => welcomes foreach { println } } ... alle 13
  14. 14. SERVICES KONSUMIEREN IV ctx getMany classOf[Greeting] withFilter isTrue("polite") andApply { _.welcome } match { case Nil => // Handle service not available ... case welcomes => welcomes foreach { println } } ... alle mit Filter 14
  15. 15. LIVE DEMO 15
  16. 16. SERVICES TRACKEN ctx track classOf[Greeting] on { case Adding(grt, _) => println("Adding polite Greeting: " + grt.welcome) case Removed(grt, _) => println("Removed polite Greeting: " + grt.goodbye) } ... mit oder ohne Properties 16
  17. 17. SERVICE-ABHÄNGIGKEITEN ctx register { (grt: Greeting) => new GreetingReverser(grt) } ... wie DS Mandatory Dependencies 17
  18. 18. FRAGEN / DISKUSSION 18
  19. 19. DANKE Kontakt: seeberger@weiglewilczek.com 19

×