Shutdown

60 views
Skip to first unread message

Maatary Okouya

unread,
Feb 11, 2015, 3:35:37 PM2/11/15
to akka...@googlegroups.com
Hi, 

I wonder what is happening behind the scene is spray .....

Why do we have to call actor shutdown for the application to actually terminate here. 

What i mean is that, usually in the main thread of my akka appliation. I will have an awaitTermination. If i don't have this there is no need to call a shutdown anyway, because the main will end and the program with it. 

I have tested and commented the shutdown method and indeed it does not terminate. 

Please could you explain ?


object Main extends App {
// we need an ActorSystem to host our application in
implicit val system = ActorSystem("simple-spray-client")
import system.dispatcher // execution context for futures below
val log = Logging(system, getClass)

log.info("Requesting the elevation of Mt. Everest from Googles Elevation API...")

import ElevationJsonProtocol._
import SprayJsonSupport._
val pipeline = sendReceive ~> unmarshal[GoogleApiResult[Elevation]]

val responseFuture = pipeline {
Get("http://maps.googleapis.com/maps/api/elevation/json?locations=27.988056,86.925278&sensor=false")
}
responseFuture onComplete {
case Success(GoogleApiResult(_, Elevation(_, elevation) :: _)) =>
log.info("The elevation of Mt. Everest is: {} m", elevation)
shutdown()

case Success(somethingUnexpected) =>
log.warning("The Google API call was successful but returned something unexpected: '{}'.", somethingUnexpected)
shutdown()

case Failure(error) =>
log.error(error, "Couldn't get elevation")
shutdown()
}

def shutdown(): Unit = {
IO(Http).ask(Http.CloseAll)(1.second).await
system.shutdown()
}
}

Patrik Nordwall

unread,
Feb 13, 2015, 7:16:08 AM2/13/15
to akka...@googlegroups.com
On Wed, Feb 11, 2015 at 9:35 PM, Maatary Okouya <maatar...@gmail.com> wrote:
Hi, 

I wonder what is happening behind the scene is spray .....

Why do we have to call actor shutdown for the application to actually terminate here. 

What i mean is that, usually in the main thread of my akka appliation. I will have an awaitTermination. If i don't have this there is no need to call a shutdown anyway, because the main will end and the program with it. 

Akka threads are by default not daemonic, which means that a started ActorSystem will keep the JVM alive until you shutdown the ActorSystem. You don't need to awaitTermination in a separate thread.

/Patrik
 

--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--

Patrik Nordwall
Typesafe Reactive apps on the JVM
Twitter: @patriknw

 Scala Days

Maatary Okouya

unread,
Feb 13, 2015, 11:50:26 AM2/13/15
to akka...@googlegroups.com
Got it thanks

You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/k7VmIFyYPMs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages