This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.{ActorSystem, Props, Actor} | |
import akka.actor.OneForOneStrategy | |
import akka.actor.SupervisorStrategy._ | |
import scala.concurrent.duration._ | |
class Supervisor extends Actor { | |
override val supervisorStrategy = | |
OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) { | |
case _: ArithmeticException => Resume | |
case _: NullPointerException => Restart | |
case _: IllegalArgumentException => Stop | |
case _: Exception => Escalate | |
} | |
def receive = { | |
case p: Props => { | |
val child = context.actorOf(p) | |
println("Supervisor created " + child.path + p) | |
} | |
} | |
} | |
class Child extends Actor { | |
throw new Exception("Intentional Exception within Child Actor's constructor") | |
println("Child actor initiated") | |
def receive = { | |
case x: Any => println( "" + x.toString ) | |
} | |
} | |
object Main { | |
def main(args: Array[String]): Unit = { | |
val system = ActorSystem("main") | |
val supervisor = system.actorOf(Props[Supervisor]) | |
println("main() started") | |
supervisor ! Props[Child] | |
Thread.sleep(2000) | |
system.terminate() | |
println("main() ended") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ERROR] [03/19/2016 22:26:07.167] [main-akka.actor.default-dispatcher-3] [akka://main/user/$a] Intentional Exception within Child Actor's constructor | |
akka.actor.ActorInitializationException: exception during creation | |
at akka.actor.ActorInitializationException$.apply(Actor.scala:172) | |
at akka.actor.ActorCell.create(ActorCell.scala:606) | |
at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:461) | |
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:483) | |
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:282) | |
at akka.dispatch.Mailbox.run(Mailbox.scala:223) | |
at akka.dispatch.Mailbox.exec(Mailbox.scala:234) | |
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) | |
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) | |
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) | |
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) | |
Caused by: java.lang.Exception: Intentional Exception within Child Actor's constructor | |
at Child.<init>(SuperVisory.scala:26) | |
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) | |
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) | |
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) | |
at java.lang.reflect.Constructor.newInstance(Constructor.java:422) | |
at java.lang.Class.newInstance(Class.java:442) | |
at akka.util.Reflect$.instantiate(Reflect.scala:44) | |
at akka.actor.NoArgsReflectConstructor.produce(IndirectActorProducer.scala:105) | |
at akka.actor.Props.newActor(Props.scala:214) | |
at akka.actor.ActorCell.newActor(ActorCell.scala:562) | |
at akka.actor.ActorCell.create(ActorCell.scala:588) | |
... 9 more |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment