2012-05-29 12:41:09 +02:00
|
|
|
package akka.osgi
|
|
|
|
|
|
|
|
|
|
import com.typesafe.config.{ Config, ConfigFactory }
|
|
|
|
|
import akka.actor.ActorSystem
|
|
|
|
|
import org.osgi.framework.{ BundleContext, BundleActivator }
|
|
|
|
|
import java.util.Properties
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Abstract {@link BundleActivator} implementation to bootstrap and configure an {@link ActorSystem} in an
|
|
|
|
|
* OSGi environment.
|
|
|
|
|
*/
|
2012-06-12 16:57:25 +02:00
|
|
|
abstract class ActorSystemActivator(nameFor: (BundleContext) ⇒ Option[String]) extends BundleActivator {
|
2012-05-31 22:53:15 +02:00
|
|
|
|
2012-06-12 16:57:25 +02:00
|
|
|
def this() = this({ context: BundleContext ⇒ None })
|
|
|
|
|
def this(name: String) = this({ context: BundleContext ⇒ Some(name) })
|
2012-05-29 12:41:09 +02:00
|
|
|
|
|
|
|
|
var system: ActorSystem = null
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implement this method to add your own actors to the ActorSystem
|
|
|
|
|
*
|
|
|
|
|
* @param system the ActorSystem that was created by the activator
|
|
|
|
|
*/
|
|
|
|
|
def configure(system: ActorSystem)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets up a new ActorSystem and registers it in the OSGi Service Registry
|
|
|
|
|
*
|
|
|
|
|
* @param context the BundleContext
|
|
|
|
|
*/
|
|
|
|
|
def start(context: BundleContext) {
|
2012-05-31 22:53:15 +02:00
|
|
|
system = OsgiActorSystemFactory(context).createActorSystem(nameFor(context))
|
2012-05-29 12:41:09 +02:00
|
|
|
configure(system)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shuts down the ActorSystem when the bundle is stopped.
|
|
|
|
|
*
|
|
|
|
|
* @param context the BundleContext
|
|
|
|
|
*/
|
|
|
|
|
def stop(context: BundleContext) {
|
|
|
|
|
if (system != null) {
|
|
|
|
|
system.shutdown()
|
|
|
|
|
system = null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|