While doing some crazy things with SARAH, I realized that the best way to solve a particular problem was to use remote Akka actors. I haven’t had the opportunity to work with Akka much since finishing the Scala Cookbook, so I dug around trying to find a simple Akka remote “Hello, world” example. Unable to find a good one, I read some stuff, and created it myself.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a very short recipe, Recipe 13.7, “How to shut down the Akka Actor system.”
You want to shut down the Akka actor system, typically because your application is finished, and you want to shut it down gracefully.
shutdown method on your
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 13.6, “How to stop Akka Actors.”Back to top
You want to stop one or more running Akka actors.Back to top
There are several ways to stop Akka actors. The most common ways are to call
system.stop(actorRef) at the
ActorSystem level or
context.stop(actorRef) from inside an actor.
There are other ways to stop an actor:Back to top
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 13.1, “How to get started with a simple Scala/Akka Actor.”
You want to begin using actors to build concurrency into your applications.
Create an actor by extending the
akka.actor.Actor class and writing a
receive method in your class. The
receive method should be implemented with a
case statement that allows the actor to respond to the different messages it receives.
As a brief reminder to self, when using Akka, in general you only want one
ActorSystem per application.
Akka Futures FAQ: Can you share a simple example that shows how to use an Akka Future?
Sure. To fix a problem in my Sarah application I needed to be able to run some operations concurrently. After digging through the Akka Actors documentation I found that you can run simple operations as a Future, almost as easily as this: