Good question. My assumption would be that the terminate shut down the part of the system that would have raised the timeout exception well before it got there. Putting a sleep right before the terminate of two seconds would cause the timeout exception if my guess is correct.
Here is the playlist: ua-cam.com/play/PLLMXbkbDbVt98z_6KWt3fU3W5jTOja9zY.html. I wish that UA-cam would automatically show the playlists that the creator of a video put that video in.
All the knowledge about Scala principle you are able to explore here: www.programmingusingscala.net/home/object-orientation-abstract-and-data-structures-using-scala---2nd-edition I think Mark who is a really low-key scholar :)
implicit val timeout = Timeout(1.seconds) val answer = actor ? AskName This call is very confusing def ?(message: Any)(implicit timeout: Timeout, implicit sender: ActorRef): Future[Any] Im finding difficulty in identifying if this a curried function or partial function. Can you clarify how or what parameters are passed to the method at runtime. Is AskName passed to Any and timeout to Timeout and actor to ActorRef? Appreciate your hardwork in simplifying such complex concepts and creating videos to help online learners.
The ? method is curried with the second argument list being implicit. That means that in most cases, you won't provide the second argument list, and values will be passed implicitly for you. For this particular call in my code, I'm not doing much with the result. The line that has "val answer = actor ? AskName" is actually expanded out to the following: val answer = actor.?(AskName)(timeout, self) This is using three aspects of the Scala syntax/semantics for translation. First, the ? is being used with infix (operator) notation because it is a method that has one argument. It is also curried. The other arguments, after the message, are provided in a second argument list. In addition, that second argument list is implicit, so Scala looks for appropriately typed implicit values to use in it. Note that the answer is a Future[Any]. As such, you will have to use methods like map, filter, foreach, ... in order to do things with the results when it comes back. If dealing with the response involved the value "sender", take special care to make a local copy of it. You might want to val val s = sender before you do the ask and then use "s" instead of "sender" in code that handles the Future.
That is odd. I can't reproduce that behavior. I just put that exact code into a project with Akka and it is perfectly happy. Even when I put in a sleep to slow down the counting, everything was happy.
All my fault under the case StartCount I had a sender ! CountDown which was throwing it found out as we were sending the start count msg from out side the actor class and that's why it tried to send it to the deadletter actor which was throwing that exception
That would do it. As you have figured out, the Start message is being sent from main, which isn't in an actor, so there isn't a valid sender to reply to.
I want to thank you for the time and effort that you take to create these videos. You have helped me a lot.
You are welcome. I am glad that you have found them useful.
Interesting although, why wasn't a Timeout exception raised as your thread sleep was longer than the timeout period that you provided?
Good question. My assumption would be that the terminate shut down the part of the system that would have raised the timeout exception well before it got there. Putting a sleep right before the terminate of two seconds would cause the timeout exception if my guess is correct.
Hi Mark, how to view this series in logical sequence as it is hard to follow otherwise..
Here is the playlist: ua-cam.com/play/PLLMXbkbDbVt98z_6KWt3fU3W5jTOja9zY.html. I wish that UA-cam would automatically show the playlists that the creator of a video put that video in.
All the knowledge about Scala principle you are able to explore here: www.programmingusingscala.net/home/object-orientation-abstract-and-data-structures-using-scala---2nd-edition
I think Mark who is a really low-key scholar :)
what is actor of()
The actorOf method is used to create actors. You pass it the information on how to create the actor, which is contained in the Props object.
implicit val timeout = Timeout(1.seconds)
val answer = actor ? AskName
This call is very confusing
def ?(message: Any)(implicit timeout: Timeout, implicit sender: ActorRef): Future[Any]
Im finding difficulty in identifying if this a curried function or partial function.
Can you clarify how or what parameters are passed to the method at runtime.
Is AskName passed to Any and timeout to Timeout and actor to ActorRef?
Appreciate your hardwork in simplifying such complex concepts and creating videos to help online learners.
The ? method is curried with the second argument list being implicit. That means that in most cases, you won't provide the second argument list, and values will be passed implicitly for you.
For this particular call in my code, I'm not doing much with the result. The line that has "val answer = actor ? AskName" is actually expanded out to the following:
val answer = actor.?(AskName)(timeout, self)
This is using three aspects of the Scala syntax/semantics for translation. First, the ? is being used with infix (operator) notation because it is a method that has one argument. It is also curried. The other arguments, after the message, are provided in a second argument list. In addition, that second argument list is implicit, so Scala looks for appropriately typed implicit values to use in it.
Note that the answer is a Future[Any]. As such, you will have to use methods like map, filter, foreach, ... in order to do things with the results when it comes back. If dealing with the response involved the value "sender", take special care to make a local copy of it. You might want to val val s = sender before you do the ask and then use "s" instead of "sender" in code that handles the Future.
Mark Lewis , your precise tutorials and quick replies are really helping me.
Glad to help. I was a bit late in that last reply, but things have been busy. I'm trying to catch up on some stuff this weekend.
what is props
propaganda ahahahah
object ActorCountDown extends App{
case class StartCount(n : Int, otherActor: ActorRef)
case class CountDown(n : Int)
class ContDownActor extends Actor{
override def receive: Receive = {
case StartCount(n, actorRef)=> {
println( context.toString +"is counting : " + n)
actorRef ! CountDown(n-1)
}
case CountDown(n) => {
println( context.toString +"is counting : " + n)
if(n > 0 )
sender ! CountDown(n-1)
else
context.system.terminate()
}
}
}
val systemActor = ActorSystem("FirstSystemActor")
val actor1 = systemActor.actorOf(Props[ContDownActor],"actor1")
val actor2 = systemActor.actorOf(Props[ContDownActor],"actor2")
actor1 ! StartCount(10,actor2)
}
Any reasons why this code throws deadletters
That is odd. I can't reproduce that behavior. I just put that exact code into a project with Akka and it is perfectly happy. Even when I put in a sleep to slow down the counting, everything was happy.
All my fault under the case StartCount I had a sender ! CountDown which was throwing it found out as we were sending the start count msg from out side the actor class and that's why it tried to send it to the deadletter actor which was throwing that exception
That would do it. As you have figured out, the Start message is being sent from main, which isn't in an actor, so there isn't a valid sender to reply to.