Akka in OSGi
Loading

Akka in OSGi

Configuring the OSGi Framework

To use Akka in an OSGi environment, the org.osgi.framework.bootdelegation property must be set to always delegate the sun.misc package to the boot classloader instead of resolving it through the normal OSGi class space.

Activator

To bootstrap Akka inside an OSGi environment, you can use the akka.osgi.AkkaSystemActivator class to conveniently set up the ActorSystem.

  1. import akka.actor.{ Props, ActorSystem }
  2. import org.osgi.framework.BundleContext
  3. import akka.osgi.ActorSystemActivator
  4.  
  5. class Activator extends ActorSystemActivator {
  6.  
  7. def configure(context: BundleContext, system: ActorSystem) {
  8. // optionally register the ActorSystem in the OSGi Service Registry
  9. registerService(context, system)
  10.  
  11. val someActor = system.actorOf(Props[SomeActor], name = "someName")
  12. someActor ! SomeMessage
  13. }
  14.  
  15. }

Blueprint

For the Apache Aries Blueprint implementation, there's also a namespace handler available. The namespace URI is https://akka.io/xmlns/blueprint/v1.0.0 and it can be used to set up an ActorSystem.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  3. xmlns:akka="https://akka.io/xmlns/blueprint/v1.0.0">
  4.  
  5. <akka:actor-system name="BlueprintSystem" />
  6.  
  7. <akka:actor-system name="BlueprintSystemWithConfig">
  8. <akka:config>
  9. some.config {
  10. key=value
  11. }
  12. </akka:config>
  13. </akka:actor-system>
  14. </blueprint>