Quantcast
Channel: Akka Libraries - Discussion Forum for Akka technologies
Viewing all articles
Browse latest Browse all 1369

Receive signals for SpawnProtocol behavior?

$
0
0

In Akka 2.6 SpawnProtocol.appy() returns the result of a Behaviors.receive call.

But you can’t call receiveSignal on this as the return type of SpawnProtocol.apply is Behavior (unlike the underlying Behaviors.receive call which returns a Receive instance).

I can do the following nasty cast like so and then call receiveSignal:

val behavior: Behavior[SpawnProtocol.Command] = SpawnProtocol()
val receive = behavior.asInstanceOf[Receive[SpawnProtocol.Command]]

receive.receiveSignal {
  case (_, Terminated(ref)) =>
    log.warn(s"$ref terminated")
    same
  case (_, ChildFailed(ref, cause)) =>
    log.error(s"$ref failed: ${cause.getMessage}", cause)
    same
}

But is there a better way to do this? Can I avoid having to know about the underlying implementation? Can I (e.g. using one of the Behaviors.receiveX functions) somehow rewrap a Behavior (which in this case is actually already a Receive) such that I get essentially the same Receive object but with the right type?

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 1369

Latest Images

Trending Articles



Latest Images