1

我需要在我的 spark 流应用程序中创建状态机实现。在阅读了一些帖子后,发现 AKKA 带有开箱即用的 FSM。我创建了一个简单的 AKKA FSM,并且能够在本地运行它。我不确定如何将此代码集成到火花结构化流(mapGroupsWithState)中。我想使用这个 FSM 并插入 mapGroupsWithState,这样即使我的应用程序出现故障,我也可以存储最后一个状态。

object BuilderFSM {

//States
sealed trait MachineState
case object tuned extends MachineState
case object trick extends MachineState
case object nonTuned extends MachineState

case class TuningEvent(macId: String, acctNumber: String, eventType: String)

}

object InputEvent {
sealed trait tuneEvents
sealed trait trickEvents

case object PLAY extends tuneEvents
case object REPLAY extends trickEvents
case object PLAY1 extends trickEvents
}

class BuilderFSM extends FSM[MachineState, TuningEvent] {
startWith(nonTuned, TuningEvent("DEVICE", "ACCOUNT", "NOTHING"))

when(nonTuned) {
case Event(PLAY, _) => {
  println("I am in NON-TUNE -> Going to Tuned")
  goto(tuned)
}
case Event(REPLAY, _) => {
  println("I am in NON-TUNED -> Going to Tuned")
  goto(tuned)
}} initialize()
}
4

0 回答 0