【发布时间】:2014-10-11 20:31:49
【问题描述】:
我的意图是使用 Akka 创建一个应用程序。当我意识到我需要创建一些 Web 服务时,我决定使用 Spray。
这个 App 需要一个分类器,所以我在 Spark 上使用 MLlib 构建了一个原型。现在我需要了解如何将 Spark 与 Spray 集成。具体来说,我需要得到
1. 这是创建 Spark 上下文的最佳方法
2. 如何让 Spark 上下文对 Actor 可见
我假设我必须在引导应用程序时创建 Spark 上下文,所以我根据 GitHub 上的示例修改了这段代码,该示例用于没有 Spark 集成的 Spray 应用程序。结果在实例化 Actor 时出现错误
14/10/11 22:12:32 ERROR actor.OneForOneStrategy: exception during creation
akka.actor.ActorInitializationException: exception during creation
我对原始代码的更改是标记为//$$$ $$$的那些
trait Core {
protected implicit def system: ActorSystem
// $$$ SparkContext in the trait $$$
protected implicit def sc: SparkContext
}
/**
* This trait implements ``Core`` by starting the required
* ``ActorSystem`` and registering the
* termination handler to stop the system when the JVM exits.
*/
trait BootedCore extends Core with Api {
def system: ActorSystem = ActorSystem("activator-akka-spray")
def actorRefFactory: ActorRefFactory = system
// $$$ Initializing SparkContext $$$
def sc = new SparkContext("local[2]", "naivebayes")
val rootService = system.actorOf(Props(new RoutedHttpService(routes)))
IO(Http)(system) ! Http.Bind(rootService, "0.0.0.0", port = 9010)
/**
* Construct the ActorSystem we will use in our application
*/
//protected implicit val system : ActorSystem
/**
* Ensure that the constructed ActorSystem is shut
* down when the JVM shuts down
*/
sys.addShutdownHook(system.shutdown())
}
/**
* This trait contains the actors that make up our application;
* it can be mixed in with
* ``BootedCore`` for running code or ``TestKit``
* for unit and integration tests.
*/
trait CoreActors {
this: Core =>
//$$$ passing the context to the actor $$$
val classifier = system.actorOf(Props(classOf[ClassifierActor], sc))
}
【问题讨论】:
标签: apache-spark spray