Menu
Home
Log in / Register
 
Home arrow Computer Science arrow Building Applications with Scala
Source

Message exchange and mailboxes

Actors talk with each other via messaging. There are two patterns: one is called ask and the other is called fire and forget. Both methods are asynchronous and non-blocking IO. When an Actor sends a message to another Actor, it does not send the message directly to the other Actor; it actually sends it to the Actor's mailbox.

Messages are enqueued in the Actor mailbox in a time-ordered fashion. There are different mailboxes implementations in Akka. The default is First In First Out (FIFO) based. This is a good default; however, you might need a different algorithm, which is fine as you can change the mailbox if you need to. More details can be found in the official documentation

(http://doc.akka.io/docs/akka/2.4.9/ scala/mailboxes.html#mailboxes-scala).

Actors live in an Actor system. You can have multiple Actor systems in a cluster:

Akka encapsulates the actor state in mailbox and decouples it from the Actor behavior. The Actor behavior is the code you will have inside your Actor. You will need to see Actors and Akka as a protocol. So, basically, you will need to define how many Actors you will have and what each Actor will do in the sense of code, responsibility, and behavior.

The Actor system has Actors and supervisors. Supervisors are one of the Akka mechanisms to deliver fault tolerance and resiliency. Supervisors take care of the Actor instances, and they can restart, kill, or create more Actors as needed.

The Actor model is great for concurrency and scalability; however, like every single thing in computer science, there are tradeoffs and cons. For instance, Actors require a new mindset and a different way of thinking. There is no silver bullet. Once you have your protocol, it might be hard to reuse your Actors outside your protocol. In general, Actors can be harder to compose, as compared to object- oriented classes or functions in Functional Programming, for instance.

 
Source
Found a mistake? Please highlight the word and press Shift + Enter  
< Prev   CONTENTS   Next >
 
Subjects
Accounting
Business & Finance
Communication
Computer Science
Economics
Education
Engineering
Environment
Geography
Health
History
Language & Literature
Law
Management
Marketing
Mathematics
Political science
Philosophy
Psychology
Religion
Sociology
Travel