OSGi on Scala: ScalaModules 1.0 released

Surely you are in love with OSGi. But don't you think that coding in Java sometimes is too verbose? And dont't you find service handling or dealing with APIs returning null references sometimes too involved?

Then try out OSGi on Scala with ScalaModules which was just released as 1.0. ScalaModules offers a DSL to ease OSGi development. Look at the following examples:

To register a Greeting service with some properties just type
context registerAs classOf[Greeting] withProperties 
  Map("name" -> "welcome") theService new Greeting { ... }

This is type checked at compile time and providing properties via a Scala Map is an easy task.

To consume a Greeting service just type
context getOne classOf[Greeting] andApply { 
  _.welcome 
} match { 
  case None          => // Not available ... 
  case Some(welcome) => println(welcome)
}

As you can see there is no need to get a service reference, check for null, get a service and finally unget the reference again. You just say what is to be done with the service via a function that takes the service as a parameter. Your result will be a Scala Option (not null): None, if there is no service available, or Some with the result of the service invocation.

ScalaModules also offers service dependencies: Your service will only be created and registered if some other service is available:
context registerAs classOf[Command] dependOn 
  classOf[Greeting] theService { 
    greeting => new Command { ...  } 
  }

There are a more features and more details, yet there are still a lot of things to be included in the future. To learn more about ScalaModules take a look at the Reference Guide which is also part of the release.

Please let me know what you think, report bugs and tell me  your wishes for enhancements.
Enjoy OSGi on Scala!

Leave a Reply