scala - How to Create a Timer Actor that receives -
i want create timer actor tracks progress of entire program (and estimate remaining execution time). since timer actor have hold mutable variable aka "current progress", think should constructed under highest supervisor instead of being spawned lower actors. created this:
object entry extends app { val system: actorsystem = actorsystem("twitter") val sup = system.actorof(props[supervisor]) sup ! sentence(.....) } class supervisor extends actor { def receive = { case sen: sentence => val timer = context.actorof(props[timer]) val pcfg = context.actorof(props[pcfgparser]) pcfg ! sen.copy() } }
then have lower actor actions:
class pcfgparser extends actor{ def receive = { case sen: sentence => //....business logic val ps = context.actorof(props[patternsearch]) //create actor ps ! sen.copy(tree = some(tree)) context.actorselection("../timer") ! pcfgaddone } }
so @ point, think should send messages timer actor. how!? tried actorselection, got "dead letter" errors. message not delivered. , seems pcfgparser actor failed send messages both child actor , timer actor:
[info] [06/03/2014 01:35:25.290] [twitter-akka.actor.default-dispatcher-4] [akka://twitter/user/$a/$h/$a] message [twitterproject.pcfgparsermsg$sentence] actor[akka://twitter/user/$a/$h#11 90256968] actor[akka://twitter/user/$a/$h/$a#-1918790382] not delivered. [6] dead letters encountered.
[info] [06/03/2014 01:35:25.291] [twitter-akka.actor.default-dispatcher-17] [akka://twitter/user/$a/$d/../timer] message [twitterproject.timermsg$pcfgaddone$] actor[akka://twitter/user/$a/ $d#-1685001108] actor[akka://twitter/user/$a/$d/../timer] not delivered. [7] dead letters encountered.
first, admit there error that's inside business logic of actor caused error (or really?? dead actor triggers message not delivered error?) second, what's right way pcfgparser actor send message distant actor?
thank you!
if want access timer actor via relative path like
context.actorselection("../timer")
you first need name timer actor instance "timer"
val timer = context.actorof(props[timer], name = "timer")
another point, if use context.actorof
within receive
block, create new actor instances every messages processed. don't think want here.
for examples if instances unique per supervisor actor, should write.
class supervisor extends actor { val timer = context.actorof(props[timer]) val pcfg = context.actorof(props[pcfgparser]) def receive = { case sen: sentence => pcfg ! sen.copy() } }
Comments
Post a Comment