concept actor system in category reactive

appears as: n actor system, actor system, The actor system, Actor systems, ctor system, actor systems, ctor systems
Reactive Application Development

This is an excerpt from Manning's book Reactive Application Development.

Reactive systems are message-driven, so it comes as no surprise that messages play a key role. Actors and messages are the building blocks of an actor system. An actor receives a message and does something in response to it. That something might include performing a computation, updating internal state, sending more messages, or perhaps initiating some I/O.

Listing 2.6. The Main driver application
import java.util.Locale import akka.actor.{ActorRef, ActorSystem, Props} #1 import Tourist.Start #2 object Main extends App { val system: ActorSystem = ActorSystem("GuideSystem") #3 val guideProps: Props = Props[Guidebook] #4 val guidebook: ActorRef = system.actorOf(guideProps, "guidebook") #5 val tourProps: Props = Props(classOf[TouristActor], guidebook) #6 val tourist: ActorRef = system.actorOf(tourProps) #5 tourist ! messages.Start(Locale.getISOCountries) #7 } #1 Akka library #2 Start message shown previously #3 Creates the actor system that will contain the actors #4 Props define a recipe for creating instances of the Guidebook actor. #5 Creates an actor based on the Props, returning a reference to the actor #6 The Props for a Tourist include a reference to the Guidebook actor. #7 Sends an initial message to the tourist actor !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":2,\"ch\":59},{\"line\":2,\"ch\":61}],[{\"line\":22,\"ch\":0},{\"line\":22,\"ch\":2}],[{\"line\":4,\"ch\":59},{\"line\":4,\"ch\":61}],[{\"line\":23,\"ch\":0},{\"line\":23,\"ch\":2}],[{\"line\":7,\"ch\":59},{\"line\":7,\"ch\":61}],[{\"line\":24,\"ch\":0},{\"line\":24,\"ch\":2}],[{\"line\":9,\"ch\":59},{\"line\":9,\"ch\":61}],[{\"line\":25,\"ch\":0},{\"line\":25,\"ch\":2}],[{\"line\":12,\"ch\":57},{\"line\":12,\"ch\":59}],[{\"line\":17,\"ch\":59},{\"line\":17,\"ch\":61}],[{\"line\":26,\"ch\":0},{\"line\":26,\"ch\":2}],[{\"line\":15,\"ch\":57},{\"line\":15,\"ch\":59}],[{\"line\":27,\"ch\":0},{\"line\":27,\"ch\":2}],[{\"line\":12,\"ch\":57},{\"line\":12,\"ch\":59}],[{\"line\":17,\"ch\":59},{\"line\":17,\"ch\":61}],[{\"line\":26,\"ch\":0},{\"line\":26,\"ch\":2}],[{\"line\":19,\"ch\":59},{\"line\":19,\"ch\":61}],[{\"line\":28,\"ch\":0},{\"line\":28,\"ch\":2}]]"} !@%STYLE%@!

2.3. Starting the actor system

Akka doesn’t require much to get started. You create the actor system and add some actors; the Akka library does the rest. Sometimes, as shown in figure 2.5, it’s useful to get things moving by sending a first message to the system. In chapters 3 and 4, you learn a bit more about what Akka is doing behind the scenes. To learn even more about the internals, see Akka in Action, by Raymond Roestenburg, Rob Bakker, and Rob Williams (Manning, 2016).

Figure 2.5. Both the Tourist and Guidebook actors are deployed into the same actor system. The start message is sent from outside the actor system.