0

In src/main/resources/application.conf

actor {
  # The guardian "/user" will use this class to obtain its supervisorStrategy.
  # It needs to be a subclass of akka.actor.SupervisorStrategyConfigurator.
  # In addition to the default there is akka.actor.StoppingSupervisorStrategy.
  guardian-supervisor-strategy = "config.ResilientSupervisorStrategy"
}

which refers to the following:

package config

import akka.actor._
import akka.actor.SupervisorStrategy._

final class ResilientSupervisorStrategy extends SupervisorStrategyConfigurator {
  override def create(): SupervisorStrategy = {
    OneForOneStrategy(){
      case _: ActorInitializationException ⇒ Stop
      case _: ActorKilledException         ⇒ Stop
      case _: DeathPactException           ⇒ Stop
      case _: Exception                    ⇒ Resume}
    }
  }
}

My Actor is instantiated like so

object Singleton {
  val actorSystem = ActorSystem("main")
  val logger: ActorRef = actorSystem.actorOf(Props(new Logger()))
}

and

val miner: ActorRef = 
    Singleton.actorSystem.actorOf(Props(new Miner()))

However, when miner hits an Exception, it still restarts (it is still using the default supervisor strategy)


As a side note, my actors have very simple internal state. All failures are due to external resources (ie. Futures not returned because the server sent a bad response) so the default strategy of restarting the actor is not necessary.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
kliew
  • 3,073
  • 1
  • 14
  • 25

1 Answers1

1

I think it should be

akka.actor {
  # The guardian "/user" will use this class to obtain its supervisorStrategy.
  # It needs to be a subclass of akka.actor.SupervisorStrategyConfigurator.
  # In addition to the default there is akka.actor.StoppingSupervisorStrategy.
  guardian-supervisor-strategy = "config.ResilientSupervisorStrategy"
}
mattinbits
  • 10,370
  • 1
  • 26
  • 35
  • Thanks! I was looking for mistakes in the class rather than the config. – kliew Feb 12 '16 at 10:11
  • It still crashes. I tried `akka { actor { ... } }` too. I think I need to look into the location of the application.conf file. Maybe related to the classpath – kliew Feb 13 '16 at 04:06
  • The other problem was an IntelliJ config problem. I had to mark the folder as a Resources folder, which also meant that it had to be moved outside of the src/main folder – kliew Feb 13 '16 at 08:15
  • 1
    Thanks for coming back with the complete solution. Did you create it as an sbt project? Intellij usually sets all that stuff up correctly – mattinbits Feb 13 '16 at 08:23
  • It is a sbt project, but every time I restart IntelliJ, I have to manually mark the src and resources folder. Is there a folder naming convention that I have to follow for IntelliJ to detect these things? – kliew Feb 13 '16 at 08:26