本文整理汇总了Scala中org.apache.spark.launcher.SparkAppHandle类的典型用法代码示例。如果您正苦于以下问题:Scala SparkAppHandle类的具体用法?Scala SparkAppHandle怎么用?Scala SparkAppHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SparkAppHandle类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SparkJobActor
//设置package包名称以及导入依赖的类
package com.example
import akka.actor.{Actor, ActorLogging, ActorRef}
import org.apache.spark.launcher.{SparkAppHandle, SparkLauncher}
class SparkJobActor extends Actor with ActorLogging {
import SparkJobActor._
def receive: Receive = {
case Launch(appResource, mainClass, master, conf) => {
val launcher = new SparkLauncher()
.setAppResource(appResource)
.setMainClass(mainClass)
.setMaster(master)
for ((key, value) <- conf.toList) {
launcher.setConf(key, value)
}
val listener = new SparkAppHandle.Listener {
override def infoChanged(handle: SparkAppHandle): Unit = {}
override def stateChanged(handle: SparkAppHandle): Unit = self ! StateChanged
}
val handle = launcher.startApplication(listener)
context become launched(handle, sender)
}
}
def launched(handle: SparkAppHandle, origSender: ActorRef): Receive = {
case StateChanged => {
if (handle.getState.isFinal) {
origSender ! Finished(handle.getState)
context stop self
}
}
}
}
object SparkJobActor {
case class Launch(appResource: String, mainClass: String, master: String, conf: Map[String, String])
case object StateChanged
case class Finished(state: SparkAppHandle.State)
}