java-akka : sending back message to grandparent -


i have created 3 levels of actors. level 1 supervisor actor. supervisor actor trigger message level2 actor , take action based on responses child actors (level1 , level2) based on type of message received. below code of supervisor

if (message instanceof outbounddataexportdto) {     // trigger query processor      outbounddataexportdto data = outbounddataexportdto.class.cast(message);     logger.info("received:  " + data.tostring());     actorref ruleinstexportactor = actorsystem         .actorof(props.create(outboundsqueryactor.class, applicationcontext)         .withrouter(new roundrobinpool(5)));     ruleinstexportactor.tell(data, getself());  } else if (message instanceof taskcompletemsg) {     taskcompletemsg taskcompletemsg= taskcompletemsg.class.cast(message);     taskservice.update(taskcompletemsg); } 

in level 2 actor, work delegated processor. processor spawn actor (level3 actor). now, need return response of taskcomplete level3 actor level1 actor (supervisor actor) take action based on response.

below sample code of level2 actor:

if (message instanceof level1actormessage) {      outboundqueryprocessor queryprocessor =  queryprocessorfactory          .getqueryprocessor(queryname);      response = queryprocessor.executequery(templateid, querydata, task);  } else if (message instanceof level3actortaskcompletemsg) { // response level 3 actor, once has completed      actorref parent = getcontext().parent(); // gives me   parent(level2)     // how send parent     // parent.tell(returnresponse, parent); } 

how can send response 3rd level actor (child) grandparent (1st level).

in code snippet level2 actor:

if (message instanceof level1actormessage) {     outboundqueryprocessor queryprocessor = queryprocessorfactory.getqueryprocessor(queryname);     response = queryprocessor.executequery(templateid, querydata, task);  } else if(message instanceof level3actortaskcompletemsg){// response level 3 actor, once has completed      actorref parent = getcontext().parent();// gives me   parent(level2)     //how send parent     //   parent.tell(returnresponse, parent); } 

you have line actorref parent = getcontext().parent();// gives me parent(level2) gives actorref level2's parent i.e. level1, grandparent of level3.

so if want tell level1 level3 has completed in level2 actor can either use:

parent.tell(message, getself()); 

which pass level3actortaskcompletemsg on level1 , sender level2 or use:

parent.forward(message, getcontext()); 

which forward level3actortaskcompletemsg level1 , sender when level1 level3 i.e. it's grandchild.

either way have achieved goal of sending level3actortaskcompletemsg level3 it's grandparent @ level1.

see http://doc.akka.io/docs/akka/snapshot/java/untyped-actors.html#forward_message


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -