I have a master worker which has a superviser to supervise over its child 
worker. The child worker throws a IOException which is viewed by the parent 
who then calls the resume()/restart() method of SupervisorStartegy.

Till now when the IO exception is getting thrown, the exception is 
transferred to the parent, the parent is calling the resume/restart method 
but after that I am getting a timeout exception.

I want that the parent will try to resume/restart the child worker for n 
number of times before stopping gracefully with a message. But what i am 
getting in this code is an exception after a single try

On Tuesday, August 12, 2014 11:28:12 AM UTC+5:30, soumya sengupta wrote:
>
> I have a master worker
>
> public class EmailServiceActor extends UntypedActor{
> ActorRef actorRef ;
>  private static SupervisorStrategy strategy =  
>        new OneForOneStrategy(3, Duration.create("1 minute"),  
>            new Function<Throwable, Directive>() {  
>              @Override  
>              public Directive apply(Throwable t) {  
>                if (t instanceof IOException) {  
>                System.out.println("IO Exception occurred");
>                  return restart();  
>                } else if (t instanceof Exception) {  
>                  return stop();  
>                } else {  
>                  return escalate();  
>                }  
>              }  
>            });  
>
> @Override  
>    public void onReceive(Object message) {  
> System.out.println("Received .....");
> if(message instanceof MyLocalMessage){
> System.out.println("received instr from EmailServiceWorker by 
> EmailServiceActor");
> actorRef.tell(message, self());
> }else{
> actorRef = getSender();
> System.out.println("received instr by EmailServiceActor from Application");
> getContext().actorOf(Props.create(EmailServiceWorker.class),"EmailServiceWorker").tell(message,
>  
> self());
> }
>    }  
>    @Override  
>    public SupervisorStrategy supervisorStrategy() {  
>      return strategy;  
>    }  
>    
>    @Override
>    public void preStart() {
>      System.out.println("Pre Restart...");
>    }
>
> }
>
> I also have a child worker
>
> public class EmailServiceWorker extends UntypedActor{
>
>  @Override  
>    public void onReceive(Object message) throws IOException{  
>     
>      System.out.println("received instr by EmailServiceWorker");
>      System.out.println("Sending mail");
>      FileReader reader = new FileReader("someFile");
>      MyLocalMessage myLocalMessage = new MyLocalMessage("Hello");
>      getSender().tell( myLocalMessage, getSelf() );
>      getContext().stop(getSelf());
>       
>  }
>  
>  @Override
>    public void preStart() {
>      System.out.println("Pre Restart");
>    }
>
> }
>
> There is no such file as "someFile". I am deliberately trying to raise the 
> error.
>
> But when I run the application I get the error
>
> [info] play - Application started (Dev)
> Pre Restart...
> Received .....
> received instr by EmailServiceActor from Application
> Pre Restart
> received instr by EmailServiceWorker
> Sending mail
> IO Exception occurred
> Pre Restart
> [ERROR] [08/12/2014 10:53:13.844] [play-akka.actor.default-dispatcher-5] 
> [akka://play/user/EmailServiceActor/EmailServiceWorker] someFile (No such 
> file or directory)
> java.io.FileNotFoundException: someFile (No such file or directory)
> at java.io.FileInputStream.open(Native Method)
> at java.io.FileInputStream.<init>(FileInputStream.java:146)
> at java.io.FileInputStream.<init>(FileInputStream.java:101)
> at java.io.FileReader.<init>(FileReader.java:58)
> at actors.EmailServiceWorker.onReceive(EmailServiceWorker.java:18)
> at 
> akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:167)
> at akka.actor.Actor$class.aroundReceive(Actor.scala:465)
> at akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:97)
> at akka.actor.ActorCell.receiveMessage(ActorCell.scala:516)
> at akka.actor.ActorCell.invoke(ActorCell.scala:487)
> at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238)
> at akka.dispatch.Mailbox.run(Mailbox.scala:220)
> at 
> akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393)
> 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)
>
> [error] play - Cannot invoke the action, eventually got an error: 
> akka.pattern.AskTimeoutException: Ask timed out on 
> [ActorSelection[Anchor(akka://play/), Path(/user/EmailServiceActor)]] after 
> [190000 ms]
> [error] application - 
>
> ! @6j77j81fk - Internal server error, for (GET) [/sendmail] ->
>
>
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to