Hi, I am trying to understand how to get the sender of the failed message in a supervisor. In this sample, there is a service that changes a string to upper case. I would like to return a "FailureToUpResponse" when the worker throws an exception. The service itself is being called from an ask from a play controller. Instead of getting the above class, I get a timeout. The line that I know is wrong is: context().sender().tell(new FailureToUpResponse(), self()); <- which returns the worker class and not the controller, but I cannot figure out the correct syntax. Here is the full class:
public class ServiceActor extends AbstractActor { private int count = 0; public ServiceActor() { receive( ReceiveBuilder.match(ServiceActor.ToUpperRequest.class, request -> { Logger.debug("About service: " + self().toString() + " Thread: " + Thread.currentThread().getName()); count++; final ActorRef worker = context().actorOf(Props.create(Worker.class, count)); worker.forward(request, context()); }).build() ); } private SupervisorStrategy strategy = new OneForOneStrategy(10, Duration.create("1 minute"), DeciderBuilder. match(IllegalArgumentException.class, e -> { Logger.debug("E: " + e); context().sender().tell(new FailureToUpResponse(), self()); return stop(); }). matchAny(o -> escalate()).build()); @Override public SupervisorStrategy supervisorStrategy() { return strategy; } public static class Worker extends AbstractActor { public Worker(int count) { receive( ReceiveBuilder.match(ServiceActor.ToUpperRequest.class, request -> { Logger.debug("About me: " + self().toString() + " Thread: " + Thread.currentThread().getName()); if(request.input.equals("error")) throw new IllegalArgumentException("Cannot handle the word error!"); Thread.sleep(5000); Logger.debug("Did the work: " + request.input.toUpperCase() + "-" + count); final ToUpperResponse response = new ToUpperResponse(request.input, request.input.toUpperCase() + "-" + count); sender().tell(response, self()); context().stop(self()); }).build() ); } } public static class ToUpperRequest { public final String input; public ToUpperRequest(String input) { this.input = input; } } public static class ToUpperResponse { public final String input; public final String output; public ToUpperResponse(String input, String output) { this.input = input; this.output = output; } } public static class FailureToUpResponse { } } -- >>>>>>>>>> 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 akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.