Setting up Parent-Child Actor in Play Framework


I just started working on Play Framework + Akka. I have one Parent Actor and one child Actor(in future it can exceed). I am making an Api call from a controller and expecting a response from child actor.


@Singleton public class NotificationController extends Controller{ final ActorRef commActor; @Inject public NotificationController(ActorSystem system) { commActor = system.actorOf(CommActor.props, "comm-actor"); } public CompletionStage<Result> communicate(int isDirect, int mode, int messageId){ return FutureConverters.toJava(ask(commActor, new CommActorProtocol.CA(isDirect, mode, messageId), 1000)) .thenApply(response -> ok((String) response).as("application/json")); } }

CommActor(Parent Actor)

public class CommActor extends UntypedActor { public static Props props = Props.create(CommActor.class); private ActorRef notificationActor; public CommActor(){ notificationActor = this.getContext().actorOf(NotificationActor.props, "notification-actor"); } @Override public void onReceive(Object message) throws Exception { notificationActor.tell(message, self()); }

NotificationActor (Child Actor):

public class NotificationActor extends UntypedActor{ public static Props props = Props.create(NotificationActor.class); @Override public void onReceive(Object message) throws Exception { sender().tell("Hi from notification", self()); } }

Parent Actor is responding correctly, but when I replace it with Notification tell. I get exception; I am not able to figure it out where the thing is going wrong.

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[Completio nException: akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://app lication/user/comm-actor#1301952259]] after [1000 ms]. Sender[null] sent message of type "protocols.CommActorProtocol$CA".]] at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException( HttpErrorHandler.scala:280) at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler. scala:206) at play.api.GlobalSettings$class.onError(GlobalSettings.scala:160) at play.api.DefaultGlobal$.onError(GlobalSettings.scala:188) at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorH andler.scala:98) at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1 .applyOrElse(PlayRequestHandler.scala:100) at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1 .applyOrElse(PlayRequestHandler.scala:99) at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:346 ) at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:345 ) at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) Caused by: java.util.concurrent.CompletionException: akka.pattern.AskTimeoutExce ption: Ask timed out on [Actor[akka://application/user/comm-actor#1301952259]] a fter [1000 ms]. Sender[null] sent message of type "protocols.CommActorProtocol$C A". at java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source ) at java.util.concurrent.CompletableFuture.completeThrowable(Unknown Sour ce) at java.util.concurrent.CompletableFuture.uniApply(Unknown Source) at java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Sourc e) at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConverter sImpl.scala:21) at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConverter sImpl.scala:18) at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) at scala.concurrent.BatchingExecutor$Batch$$anonfun$run$1.processBatch$1 (BatchingExecutor.scala:63) Caused by: akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://appl ication/user/comm-actor#1301952259]] after [1000 ms]. Sender[null] sent message of type "protocols.CommActorProtocol$CA". at akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala :604) at akka.actor.Scheduler$$anon$4.run(Scheduler.scala:126) at scala.concurrent.Future$InternalCallbackExecutor$.unbatchedExecute(Fu ture.scala:601) at scala.concurrent.BatchingExecutor$class.execute(BatchingExecutor.scal a:109) at scala.concurrent.Future$InternalCallbackExecutor$.execute(Future.scal a:599) at akka.actor.LightArrayRevolverScheduler$TaskHolder.executeTask(LightAr rayRevolverScheduler.scala:331) at akka.actor.LightArrayRevolverScheduler$$anon$4.executeBucket$1(LightA rrayRevolverScheduler.scala:282) at akka.actor.LightArrayRevolverScheduler$$anon$4.nextTick(LightArrayRev olverScheduler.scala:286) at akka.actor.LightArrayRevolverScheduler$$anon$4.run(LightArrayRevolver Scheduler.scala:238) at java.lang.Thread.run(Unknown Source)


I am able to solve the problem. In case any one stuck with same problem. It was basically going to an infinite loop from CommActor to NotificationActor.


if (message instanceof CA) { int mode = ((CA) message).mode; this.originator = getContext().sender(); switch(mode){ case 1: //SMS break; case 2: //Email break; case 3: //Notification notificationActor.tell(new NA((CA)message), getSelf()); break; } } else if (message instanceof Response) { originator.tell(((Response) message).getResponse(), getSelf()); } else{ unhandled(message); }

Where CA/NA are protocols for Notification/CommActor


@Override public void onReceive(Object message) throws Exception { if (message instanceof NA){ getSender().tell(new Response(response), getSelf());}}


  • Why error occurs when I send multiple queries into mysqli_query?
  • Android SimpleAdapter wrong data-item gets associated with a list row
  • HTML5 canvas drawImage not working on first click
  • Get byte[] from
  • How to Filter ListAdapter using getFilter() within a fragment
  • IndexSizeError on drawImage on IE and Edge
  • using a UILocalNotification to play a sound that's not in the app bundle
  • Title cutoff in tabbed page in Xamarin.Forms
  • Trouble downloading file from browser on Android
  • Reload UITableView from another tab
  • PushKit for VOIP iOS apps
  • Why cepheus don't send int without quotes to orion?
  • WPF Visiblity Binding to Boolean Expression with multiple Variables
  • revitapi ironpython ToRoom returns “indexer # object”
  • Access variable of ScriptContext using Nashorn JavaScript Engine (Java 8)
  • Connect .sks to skscene.h
  • Debug.DrawLine not showing in the GameView
  • GridView breaks while scrolling
  • Jackson Parser: ignore deserializing for type mismatch
  • How to Cache Real-time Data?
  • How to render a blob on a canvas element?
  • How to use RequestBodyAdvice
  • Q promise. Difference between .when and .then
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Opengl-es onTouchEvents problem or a draw problem? [closed]
  • output of program is not same as passed argument
  • Incrementing object id automatically JS constructor (static method and variable)
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Javascript + PHP Encryption with pidCrypt
  • When should I choose bucket sort over other sorting algorithms?
  • Hazelcast - OperationTimeoutException
  • To display the title for the current loaction in map in iphone
  • Akka Routing: Reply's send to router ends up as dead letters
  • AT Commands to Send SMS not working in Windows 8.1
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How do I configure my settings file to work with unit tests?
  • Getting Messege Twice Using IMvxMessenger
  • Is it possible to post an object from jquery to bottle.py?
  • How can i traverse a binary tree from right to left in java?
  • How can I use threading to 'tick' a timer to be accessed by other threads?