scalarookie scalarookie - 1 year ago 91
Scala Question

Is it safe to override `receive` in an Akka FSM?

I created an FSM with Akka. However, my FSM doesn't only get messages passed that are relevant for its FSM state. Its children may also pass

s up to it, which my FSM should then pass further up to its parent. Since FSMs in Akka are (naturally) also actors, I would like to override
to catch those
. However, doing that broke the FSM functionality of the actor. What's the proper way to handle a situation like this?

Answer Source

Messages that are nor relevant for any FSM states can be handled in whenUnhandled:

whenUnhandled {
  case Event(someActorRef: ActorRef, _) =>
    context.parent someActorRef

Though, overriding receive should, afaik, work, too.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download