Hi Allen,
3 jun 2014 kl. 07:48 skrev Allen Nie <[email protected]>:
> Hey,
>
> I want to create a Timer Actor that tracks the progress of the entire
> program (and also estimate remaining execution time). Since the timer actor
> will have to hold mutable variable aka "current progress", I think it should
> be constructed under the highest supervisor instead of being spawned by lower
> actors. So I created this:
>
> object Entry extends App {
> val system: ActorSystem = ActorSystem("Twitter")
> val sup = system.actorOf(Props[Supervisor])
This actor should have a name, let’s call it “app” (i.e. use
system.actorOf(Props[Supervisor], "app")).
> sup ! Sentence(.....)
> }
>
> class Supervisor extends Actor {
>
> def receive = {
> case sen: Sentence =>
> val timer = context.actorOf(Props[Timer])
This one should also have a name, e.g. “timer”.
> val pcfg = context.actorOf(Props[PCFGParser])
This one will need to be acquainted with the timer, so I’d recommend
val pcfg = context.actorOf(PCFGParser.props(timer), "parser")
which needs
object PCFGParser {
def props(timer: ActorRef): Props = Props(new PCFGParser(timer))
}
> pcfg ! sen.copy()
> }
> }
>
> Then I have this lower actor that does all the actions:
>
> class PCFGParser extends Actor{
Introduce the “timer” ActorRef here …
>
> def receive = {
> case sen: Sentence =>
> //....business logic
> val ps = context.actorOf(Props[PatternSearch]) //create another actor
> ps ! sen.copy(tree = Some(tree))
> context.actorSelection("../timer") ! PCFGAddOne
… then you can send to it here.
> }
> }
>
> So at this point, I think it should send messages back to that Timer Actor.
> BUT HOW!? I tried actorSelection, but all I got were "dead letter" errors.
> The message was not delivered. And it also seems like this PCFGParser actor
> failed to send messages to both its child actor and 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] from
> Actor[akka://Twitter/user/$a/$h#11
> 90256968] to Actor[akka://Twitter/user/$a/$h/$a#-1918790382] was 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$] from Actor[akka://Twitter/user/$a/
> $d#-1685001108] to Actor[akka://Twitter/user/$a/$d/../timer] was not
> delivered. [7] dead letters encountered.
>
> First, I admit there could be some error that's inside the business logic of
> this actor that caused this error (or really?? Could a dead actor triggers
> message not delivered error?) Second, what's the right way for this
> PCFGParser actor to send message to a distant actor?
Hope this helps! And remember to always give names to your actors, they are
precious little helpers of yours :-)
Regards,
Roland
>
> Thank you!
>
> --
> >>>>>>>>>> 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.
Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Reactive apps on the JVM.
twitter: @rolandkuhn
--
>>>>>>>>>> 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.